We will hold AtCoder Beginner Contest 335 (Sponsored by Mynavi).
- Contest URL: https://atcoder.jp/contests/abc335
- Start Time: http://www.timeanddate.com/worldclock/fixedtime.html?iso=20240106T2100&p1=248
- Duration: 100 minutes
- Writer: physics0523, kyopro_friends, evima, leaf1415, PCTprobability
- Tester: leaf1415, MMNMM
- Rated range: ~ 1999
- The point values: 100-150-300-350-525-525-600
We are looking forward to your participation!
I'm really curious, what is the purpose of running atcoder rounds right before codeforces ones? Warming up or anything else?
Atcoder always hosts its contests at the same time, it has nothing to do with codeforces rounds
I mean, they're are not only close by time, but often are in the same days
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.
Now it makes sense, thanks
HELP, why this- Code submission gets TLE for problem E, any help is appreciated.
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.
Besides atcoder and codechef, do other sites remind CodeForces users about their competitions?
Got it.
why no english editorial?
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.
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?
Similar case for my submission, could not figure out why it gives those 15 WA, appreciate any help, thanks.
Maybe you can have a look at this case 5 5 1 2 3 3 4 1 2 2 4 3 4 1 3 3 5 If your output is correct, maybe there is some other reason
I am getting a correct answer which is 4 but its still failing
https://atcoder.jp/contests/abc335/submissions/49224033
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.
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?
Well... The graph is not DAG in the first place, so topo sort won't work.
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
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!
If they are not adjacent in path, then it will break the condition and we won't count it.
I solve it with modified Dijkstra's 49115351 algorithm.
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 codeset<pair<int, int>> as {a[u], u}
-> Accepted (a[u] is the number written on node u) Accepted codeCan anyone explain it to me, please?
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.
To solve this as mentioned by Swishy123 we have to merge the same nodes, I have used DSU, you can check my Accepted code
Can you please explain the idea of your dsu solution.
You can check my video editorial
What's the idea behind G?
C and D are both problems with stories of dragons. 2024 is the year of dragon.
help why my code is giving WA on 15 testcases on E? code link
It gives WA on the following test case as already mentioned by pedastrian57
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
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?
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$$$.
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.
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.
Is usage of
__int128
intended in G?I am getting TLE on problem E.Can anyone pleass help? My code.
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.
Can someone explain idea behind F
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
My solution discussion stream
My screencast
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 ?
the time complexity for the above code is o(n*(logn)^2)
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).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?
What is difficulty rating of E,F on codeforces level
1700, 1900
okay
can anyone explain why my code for F is giving TLE ->https://atcoder.jp/contests/abc335/submissions/49152850
https://atcoder.jp/contests/abc335/submissions/49167270
My code fails for TC -41 for E can anyone tell error
https://codeforces.me/blog/entry/124352?#comment-1103880
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.
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.