atcoder_official's blog

By atcoder_official, history, 4 months ago, In English

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

We are looking forward to your participation!

  • Vote: I like it
  • +49
  • Vote: I do not like it

»
4 months ago, # |
  Vote: I like it +8 Vote: I do not like it

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

  • »
    »
    4 months ago, # ^ |
      Vote: I like it +51 Vote: I do not like it

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

    • »
      »
      »
      4 months ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

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

      • »
        »
        »
        »
        4 months ago, # ^ |
        Rev. 3   Vote: I like it +16 Vote: I do not like it

        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.

»
4 months ago, # |
  Vote: I like it +3 Vote: I do not like it

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

  • »
    »
    4 months ago, # ^ |
    Rev. 2   Vote: I like it +5 Vote: I do not like it

    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.

    • »
      »
      »
      4 months ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      Besides atcoder and codechef, do other sites remind CodeForces users about their competitions?

    • »
      »
      »
      4 months ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      Got it.

»
4 months ago, # |
  Vote: I like it 0 Vote: I do not like it

why no english editorial?

»
4 months ago, # |
  Vote: I like it +1 Vote: I do not like it

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.

»
4 months ago, # |
  Vote: I like it +10 Vote: I do not like it

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?

  • »
    »
    4 months ago, # ^ |
      Vote: I like it +3 Vote: I do not like it

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

  • »
    »
    4 months ago, # ^ |
      Vote: I like it +1 Vote: I do not like it

    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.

    • »
      »
      »
      4 months ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      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?

      • »
        »
        »
        »
        4 months ago, # ^ |
          Vote: I like it +1 Vote: I do not like it

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

        • »
          »
          »
          »
          »
          4 months ago, # ^ |
            Vote: I like it +6 Vote: I do not like it

          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

          • »
            »
            »
            »
            »
            »
            4 months ago, # ^ |
              Vote: I like it 0 Vote: I do not like it

            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 months ago, # ^ |
                Vote: I like it +1 Vote: I do not like it

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

  • »
    »
    4 months ago, # ^ |
    Rev. 9   Vote: I like it 0 Vote: I do not like it

    I solve it with modified Dijkstra's 49115351 algorithm.

    • »
      »
      »
      4 months ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      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?

  • »
    »
    4 months ago, # ^ |
      Vote: I like it +1 Vote: I do not like it

    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

»
4 months ago, # |
  Vote: I like it +5 Vote: I do not like it

What's the idea behind G?

»
4 months ago, # |
  Vote: I like it +10 Vote: I do not like it

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

»
4 months ago, # |
Rev. 2   Vote: I like it +3 Vote: I do not like it

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

code
  • »
    »
    4 months ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

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

    Testcase
»
4 months ago, # |
  Vote: I like it 0 Vote: I do not like it

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

»
4 months ago, # |
  Vote: I like it 0 Vote: I do not like it

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?

  • »
    »
    4 months ago, # ^ |
      Vote: I like it +18 Vote: I do not like it

    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 months ago, # ^ |
      Rev. 2   Vote: I like it +8 Vote: I do not like it

      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 months ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

        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.

»
4 months ago, # |
  Vote: I like it +8 Vote: I do not like it

Is usage of __int128 intended in G?

»
4 months ago, # |
Rev. 2   Vote: I like it 0 Vote: I do not like it

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

  • »
    »
    4 months ago, # ^ |
    Rev. 2   Vote: I like it +1 Vote: I do not like it

    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.

»
4 months ago, # |
  Vote: I like it 0 Vote: I do not like it

Can someone explain idea behind F

  • »
    »
    4 months ago, # ^ |
    Rev. 4   Vote: I like it +1 Vote: I do not like it

    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

»
4 months ago, # |
  Vote: I like it 0 Vote: I do not like it

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 ?

  • »
    »
    4 months ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

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

  • »
    »
    4 months ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    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).

»
4 months ago, # |
Rev. 2   Vote: I like it 0 Vote: I do not like it

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 months ago, # |
  Vote: I like it 0 Vote: I do not like it

What is difficulty rating of E,F on codeforces level

»
4 months ago, # |
  Vote: I like it 0 Vote: I do not like it

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

»
4 months ago, # |
  Vote: I like it 0 Vote: I do not like it

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

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

»
4 months ago, # |
  Vote: I like it +1 Vote: I do not like it

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 months ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    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.