Блог пользователя atcoder_official

Автор atcoder_official, история, 5 месяцев назад, По-английски

We will hold AtCoder Beginner Contest 335 (Sponsored by Mynavi).

We are looking forward to your participation!

  • Проголосовать: нравится
  • +49
  • Проголосовать: не нравится

»
5 месяцев назад, # |
  Проголосовать: нравится +8 Проголосовать: не нравится

I'm really curious, what is the purpose of running atcoder rounds right before codeforces ones? Warming up or anything else?

  • »
    »
    5 месяцев назад, # ^ |
      Проголосовать: нравится +51 Проголосовать: не нравится

    Atcoder always hosts its contests at the same time, it has nothing to do with codeforces rounds

    • »
      »
      »
      5 месяцев назад, # ^ |
        Проголосовать: нравится 0 Проголосовать: не нравится

      I mean, they're are not only close by time, but often are in the same days

      • »
        »
        »
        »
        5 месяцев назад, # ^ |
        Rev. 3   Проголосовать: нравится +16 Проголосовать: не нравится

        Atcoder (almost) always hosts its contests on saturdays and sundays, it has nothing to do with codeforces rounds. It just happens that codeforces also often hosts contests during the weekend.

»
5 месяцев назад, # |
  Проголосовать: нравится +3 Проголосовать: не нравится

HELP, why this- Code submission gets TLE for problem E, any help is appreciated.

  • »
    »
    5 месяцев назад, # ^ |
    Rev. 2   Проголосовать: нравится +5 Проголосовать: не нравится

    Consider this graph where wi=i and 1 is connected to 1e5 nodes and these 1e5 nodes are directly connected to a chain of 1e5 nodes each in increasing value then your solution will run all possible paths which will be 1e5*1e5. In short, you algo is not stopping for the path it has already traveled before.

»
5 месяцев назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

why no english editorial?

»
5 месяцев назад, # |
  Проголосовать: нравится +1 Проголосовать: не нравится

C was a nasty problem for its place. Much harder than D.

Also, how to solve problem E? I tried with bfs but got TLE in 15/95 test cases.

»
5 месяцев назад, # |
  Проголосовать: нравится +10 Проголосовать: не нравится

Why normal dfs with dp will not work for E if we only jump to node j from i if a[j]>=a[i]. My code for ref. Can anyone point out why is it failing?

  • »
    »
    5 месяцев назад, # ^ |
      Проголосовать: нравится +3 Проголосовать: не нравится

    Similar case for my submission, could not figure out why it gives those 15 WA, appreciate any help, thanks.

  • »
    »
    5 месяцев назад, # ^ |
      Проголосовать: нравится +1 Проголосовать: не нравится

    Since a[j] >= a[i], the graph you are trying to dp on is not a DAG. You need to merge on vertices such that they are all connected by edges and are equal, then it will become a DAG.

    • »
      »
      »
      5 месяцев назад, # ^ |
        Проголосовать: нравится 0 Проголосовать: не нравится

      But the value of dp[i] will not change if I move to the same color vertices. Am I missing something, can you point out one such case?

      • »
        »
        »
        »
        5 месяцев назад, # ^ |
          Проголосовать: нравится +1 Проголосовать: не нравится

        Well... The graph is not DAG in the first place, so topo sort won't work.

        • »
          »
          »
          »
          »
          5 месяцев назад, # ^ |
            Проголосовать: нравится +6 Проголосовать: не нравится

          If we are only traversing v[j]>v[i] then its kind of traversing a dag only, if we are traversing v[j]=v[i] the value of dp[i] wont change right? What could be the issue then

          • »
            »
            »
            »
            »
            »
            5 месяцев назад, # ^ |
              Проголосовать: нравится 0 Проголосовать: не нравится

            What if there are two nodes with same a[] values but are not adjacent in path traversed by your dfs? It will get counted twice!

            • »
              »
              »
              »
              »
              »
              »
              4 месяца назад, # ^ |
                Проголосовать: нравится +1 Проголосовать: не нравится

              If they are not adjacent in path, then it will break the condition and we won't count it.

  • »
    »
    5 месяцев назад, # ^ |
    Rev. 9   Проголосовать: нравится 0 Проголосовать: не нравится

    I solve it with modified Dijkstra's 49115351 algorithm.

    • »
      »
      »
      5 месяцев назад, # ^ |
        Проголосовать: нравится 0 Проголосовать: не нравится

      I don't understand why Dijkstra's algo works faster with a set that sorts by the integer written on each node rather than by the score that was calculated for each node.
      Doesn't Dijkstra's algo always prioritize choosing and processing the node with the shortest calculated distance first? Then why it doesn't work in this problem.
      Shortly, set<pair<int, int>> as {res[u], u} -> TLE. TLE code
      set<pair<int, int>> as {a[u], u} -> Accepted (a[u] is the number written on node u) Accepted code
      Can anyone explain it to me, please?

  • »
    »
    5 месяцев назад, # ^ |
      Проголосовать: нравится +1 Проголосовать: не нравится

    Hey all, found the issue. The issue happens when you have some connected components having the same value, and if the first node is connected to N, the later nodes will not have proper dp value. Now if some of the later nodes have longer paths we will not be counting them. Providing one test case related to that.

    Spoiler

    To solve this as mentioned by Swishy123 we have to merge the same nodes, I have used DSU, you can check my Accepted code

»
5 месяцев назад, # |
  Проголосовать: нравится +5 Проголосовать: не нравится

What's the idea behind G?

»
5 месяцев назад, # |
  Проголосовать: нравится +10 Проголосовать: не нравится

C and D are both problems with stories of dragons. 2024 is the year of dragon.

»
5 месяцев назад, # |
Rev. 2   Проголосовать: нравится +3 Проголосовать: не нравится

help why my code is giving WA on 15 testcases on E? code link

code
  • »
    »
    5 месяцев назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    It gives WA on the following test case as already mentioned by pedastrian57

    Testcase
»
5 месяцев назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

hey does anyone have any idea on how to approach E , i tried dp on dfs , but cannot get uniqueness in the constraint time , gave me tle , does anyone have approach . It will be helpful. Thank you

»
5 месяцев назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Can anyone analyze the time complexity of my submission for F — Hop Sugoroku?

$$$dp[i]$$$ denotes the number of valid subsets of first $$$i$$$ elements such that the $$$i^{th}$$$ element is necessarily covered black. $$$dp[i]$$$ would contribute to all $$$j$$$ such that $$$j = i + a[i]*x$$$. So instead of iterating over all such $$$j$$$, I offload the increment for further indices to $$$j$$$ if I ever encounter $$$a[i] = a[j]$$$.

If there are no duplicates, then it works in $$$O(n \ log(n))$$$, but how to prove that it is still bounded by $$$O(n log(n))$$$ if there are duplicates?

  • »
    »
    5 месяцев назад, # ^ |
      Проголосовать: нравится +18 Проголосовать: не нравится

    This solution is bounded by $$$O(N*sqrt(N))$$$ and mentioned in one of the editorial.

    On this case this soln prints 59528480 as no of operations. This is roughly $$$300*N$$$.

    • »
      »
      »
      4 месяца назад, # ^ |
      Rev. 2   Проголосовать: нравится +8 Проголосовать: не нравится

      That solution is brilliant. I'm still not understanding how the argument works for why it is definitely O(N * sqrt(N)) though. The proof is a bit mathematically concise in the editorial, wishing there was a more verbose proof with example.

      • »
        »
        »
        »
        4 месяца назад, # ^ |
          Проголосовать: нравится 0 Проголосовать: не нравится

        I read the example with 1,2,2,3,3,3,4,4,4,4... and I extended that pattern out to 200,000 elements, you get to something with ...,631. But what I observed is that each of those elements is visited 1,2,2,3,3,3,4,4,4,4... I believe. If you do this all the way out with 200,000 elements you get the ...,631. So for the worst case I get about 80 million iterations. And if you take N * sqrt(N) with N = 200,000 you get about 89 million. So I guess it is O(N * sqrt(N)) for that worst case. Still not to sure. This is just extending the worst case scenario introduced in the editorial. I don't have enough time to think about this for now though.

»
5 месяцев назад, # |
  Проголосовать: нравится +8 Проголосовать: не нравится

Is usage of __int128 intended in G?

»
5 месяцев назад, # |
Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

I am getting TLE on problem E.Can anyone pleass help? My code.

  • »
    »
    4 месяца назад, # ^ |
    Rev. 2   Проголосовать: нравится +1 Проголосовать: не нравится

    You should only apply DP on the leader nodes for each component. Here's a theoretical scenario that would TLE if not implemented properly.

    Consider a graph of $$$2 \cdot n$$$ vertices. Split all vertices into 2 equal groups.

    If you try to update the DP value of all nodes in the first group, you would have to take contribution from each of the $$$n$$$ nodes from the second group (since all of them are reachable). Hence, the time complexity is $$$O(n*n)$$$.

    The correct strategy is to populate the DP values of leader only. That is, instead of asking the best path from node $$$a$$$ in group 1 to node $$$b$$$ in group 2, ask about the best path from the leader of group 1 to the leader of group 2.

»
5 месяцев назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Can someone explain idea behind F

  • »
    »
    5 месяцев назад, # ^ |
    Rev. 4   Проголосовать: нравится +1 Проголосовать: не нравится

    Video Editorial for F : Hop Sugoroku

    Define $$$dp[i]$$$ to be the number of valid subsets of the first $$$i$$$ elements such that the $$$i^{th}$$$ element is necessarily painted black. The final answer is $$$\sum dp[i]$$$

    The transitions are trivial, just follow the rules mentioned in the problem, i.e, $$$dp[i]$$$ contributes to all $$$j = i + a[i] \cdot x$$$.

    Code

    What if the array was a permutation? Can you prove that the naive DP works in $$$O(n \cdot log(n))$$$?

    What if the array only consisted of $$$1s$$$? Do you see a way to optimize this DP? Note that each $$$i$$$ would update the suffix $$$[i + 1, \dots n]$$$. Hence, you can just use difference array to propagate the updates in $$$O(1)$$$. Hence, if you define $$$delta[i]$$$ to be the delta that needs to be pushed to the suffix, for each $$$i$$$, you can do $$$delta[i + 1] \mathrel{+}= dp[i]$$$. And you keep pushing that delta to the next element.

    What if the array only consisted of $$$2s$$$? You now have to update $$$[i + 2, i + 4, \dots n]$$$. The strategy from above still works. For each $$$i$$$, $$$delta[i + 2] \mathrel{+}= dp[i]$$$. But while pushing the delta, the delta from the $$$i^{th}$$$ element would be pushed to $$$i + 2^{th}$$$ element.

    What if the array only consisted of $$$3s$$$? What if the array had all elements equal to $$$z$$$? All of these individual cases can be solved in $$$O(n)$$$. So, if the array consisted of mixed integers, you can combine the same logic, now keeping a delta for each variable.

    Code

    Now, notice that the transitions are in $$$O(1)$$$. But the matrix size is huge. So, let's not maintain the delta values of $$$a[i] > \sqrt n$$$. Then, each time we encounter such $$$a[i]$$$, we can iterate over all its multiples and naively update the DP. Since $$$\sqrt n \cdot \sqrt n \geq n$$$, we would do no more than $$$O(\sqrt n)$$$ work for each such index. For the remaining $$$a[i]$$$, the delta value of variable $$$j$$$ would propagate from $$$i$$$ to $$$i + j$$$. Since $$$j \leq \sqrt n$$$, we can maintain a matrix of size $$$n \times \sqrt n$$$ to maintain these delta values.

    Code

»
5 месяцев назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

time complexity of F is a bit strict i guess. my solutions execution time is 2.82 seconds but allowed time is 2.5 seconds.

this is my solution : https://atcoder.jp/contests/abc335/submissions/49137183

is there any way i could optimize this ?

  • »
    »
    5 месяцев назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    the time complexity for the above code is o(n*(logn)^2)

  • »
    »
    5 месяцев назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    2.82 seconds doesn't mean that your code completed execution in 2.82 seconds. It means that Atcoder decided to terminate the execution after 2.82 seconds because the time limit was 2.5 seconds. For example, on this testcase shared by aryanc403, your code runs in 58 seconds on my machine (and this is when the array is generated on the fly, so factoring in I/O would increase the time as well).

»
5 месяцев назад, # |
Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

For task G, the editorial says "Now, an (i,j) pair as in the problem statement is satisfactory if $$$k_j$$$ divides $$$k_i$$$ (to prove this, think of cycles and Bézout’s identity)." How to prove it?

»
4 месяца назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

What is difficulty rating of E,F on codeforces level

»
4 месяца назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

can anyone explain why my code for F is giving TLE ->https://atcoder.jp/contests/abc335/submissions/49152850

»
4 месяца назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

https://atcoder.jp/contests/abc335/submissions/49167270

My code fails for TC -41 for E can anyone tell error

»
4 месяца назад, # |
  Проголосовать: нравится +1 Проголосовать: не нравится

Can anyone help me understand why my approach is giving WA in E?

https://atcoder.jp/contests/abc335/submissions/49224033

I just did plain dfs and maintained the max count.

Thanks in advance.

  • »
    »
    4 месяца назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    Try this test case, it returns 3 when it should return 4. 5 5 1 2 3 3 4 3 4 1 3 1 2 2 4 3 5 I wrote out this example, it creates adjacency list [[3, 2], [1, 4], [4, 1, 5], [3, 2], [3]] => dfs traversal order: [1, 3, 4, 5, 2 ] [2, 1, min, 0, min

    It traverses the 1, 3, 4. And it places the vis = int_min, which prevents it from finding the optimal path later that is 1-2-4-3-5, instead it just finds 1-3-5. But if it is converted into a DAG by creating supernode (3, 4), then it will work. Because you can do DP on a DAG.