### Bazoka13's blog

By Bazoka13, history, 2 months ago,

Hi Codeforces!

We are glad to invite you to our first Codeforces Round Codeforces Round #738 (Div. 2) which will be held on Aug/15/2021 17:35 (Moscow time). This round will be rated for participants with rating less than 2100. We will be glad to see participants from the first division to join out of competition as well!

In this round, as the best friend of Mocha's, you are going to help her to solve the problems she meets.

The problems are prepared by 2sozx, JJLeo, Serval, CalvinJin and me. We hope you will enjoy the round. :P

We would like to thank:

• 1-gon for awesome coordination of this round and helping us improve our problems.

• Toxel for excellent testing and discussion of this round.

• MikeMirzayanov for the amazing Codeforces and Polygon platforms.

You will be given 5 problems to solve in 2 hours.

Scoring distribution: 500—750—1000—(1500—1500)—3000.

We recommend you to read the statements of all problems. Good luck & Have fun! :D

UPD: Great thanks to KAN and isaf27 for helping with Russian language translation and clarifications.

UPD2: Sorry for the long queue and my mistake in estimating the difficulty of problem D2 and E.

UPD3: Editorial is available now.

UPD4: Thank you for your participation in this round! Congratulations to the winners!

Div. 2

Div. 1 + Div. 2

• +796

 » 2 months ago, # |   +595 Darn, my VIP tester streak ended.
•  » » 2 months ago, # ^ |   +213 As a tester, Monogon orz.If you don't upvote Monogon, you won't get positive delta. Good luck!
•  » » » 2 months ago, # ^ | ← Rev. 2 →   +16 But, unfortunately, the inverse is not true. :(
•  » » » 2 months ago, # ^ |   -43 PurpleCrayon using old cheap tricks to get upvotes for 1-gon!PurpleCrayon should understand that even without these cheap tricks everyone will upvote 1-gon for sure!
•  » » » » 2 months ago, # ^ |   +33 He's doing it to get upvotes for himself
•  » » » » 2 months ago, # ^ |   -23 Let's get him downvotes!
•  » » » » 2 months ago, # ^ |   +4 But You got Downvote Lol!!
•  » » » » » 2 months ago, # ^ |   -10 Oh my GOD!
•  » » 2 months ago, # ^ |   0 1-gon,just remember one thing ,with great power comes great responsibility. Orz 1-gon Orz
•  » » 2 months ago, # ^ |   +13 You can still be VIP coordinator...
•  » » 2 months ago, # ^ |   +7 Yet another blog where Monogon has more upvotes than the blog itself
 » 2 months ago, # |   -185 Announcement blog 3 days before round -> bad round
•  » » 2 months ago, # ^ |   +5 why
•  » » 2 months ago, # ^ |   +74 hii rotavirus
•  » » » 2 months ago, # ^ | ← Rev. 6 →   -89 1-gon is god
•  » » » » 2 months ago, # ^ | ← Rev. 3 →   -78 Tourist is god
•  » » » » 2 months ago, # ^ | ← Rev. 3 →   -86 Errichto is god
•  » » » » » 2 months ago, # ^ |   +15 Are you a polytheist?
•  » » » » » 2 months ago, # ^ |   -19 And you are a dog!
•  » » 2 months ago, # ^ |   -24 call it a bad round 3days before the round begins -> bad comment
 » 2 months ago, # |   +59 As a tester, have fun!
•  » » 2 months ago, # ^ |   +17 ah, a man of culture indeed
•  » » 2 months ago, # ^ |   0 exactly..
 » 2 months ago, # | ← Rev. 3 →   +60 As a tester. You must be careful with your code and try to solve $x$ ($1 \leq x \leq 5$) problems! Good luck!-QuangBuiYT
•  » » 2 months ago, # ^ |   +56 Thank you for confirming that our codes will FST :|
•  » » 2 months ago, # ^ |   -21 Can you provide a link to such problem?
 » 2 months ago, # |   +8 Hoping to regain specialist after this round!
 » 2 months ago, # |   +119 As a tester, oooops I find myself a problem setter! lol
 » 2 months ago, # |   +81 As a coauther & tester for the first time, I hope you enjoy this round!
 » 2 months ago, # |   +12 orz
 » 2 months ago, # |   +86 As a tester, hope you enjoy those excellent problems and wish you all high rating!
 » 2 months ago, # |   +3 Hope to become pupil again this time!
 » 2 months ago, # |   +1 The scoring distribution looks noice!!!
 » 2 months ago, # |   +22 hoping for nice round and thanks author for spending your time for us
 » 2 months ago, # |   +8 Hope for a great round,and thanks for the early score distribution!
 » 2 months ago, # |   +3 OrzOrz
 » 2 months ago, # |   +17 As a tester,I'm sure that it is a fabulous round!
 » 2 months ago, # |   +14 As a Participant, I Would like to remind my Fellow Participants, not to get wooed by the Easy Score Distribution, as the Problems are gonna be hell a lot Tricky & many of us will be getting... Can You Guess ?WA on Pretest 2 :D
 » 2 months ago, # | ← Rev. 2 →   0 Hope to become expert for the first time, that feeling when you get something you dreamt 1 year ago :)))
 » 2 months ago, # |   0 hope this time i can reach pupil.(●'◡'●)
•  » » 2 months ago, # ^ |   0 You will reach pupil in 7 contests.
 » 2 months ago, # |   +4 speedforces ABC?
•  » » 2 months ago, # ^ |   0 Maybe not speedforces, but balanced like 1300 A, 1500 B, 1700 C or something like that but harder than normal round ABCs.
 » 2 months ago, # |   +31 why he write 6problems as e is the hard version of d only
•  » » 2 months ago, # ^ |   +12 Thank you for your reminding, I have updated the announcement :)
 » 2 months ago, # |   0 Score Distribution looks great! :)
 » 2 months ago, # | ← Rev. 7 →   +5 Behold The Chinese Round! Orz
 » 2 months ago, # | ← Rev. 2 →   0 Good luck to everyone!
 » 2 months ago, # |   +2 Auto comment: topic has been updated by Bazoka13 (previous revision, new revision, compare).
•  » » 2 months ago, # ^ |   +2 If we are given 5 problems so why the scoring distribution is saying we're ganna have 6 problems ? Spoiler
•  » » » 2 months ago, # ^ |   +14 1500 appeared twice inside the bracket denotes easy version and hard version of the same problem, and the only difference between them is the data constraints.
 » 2 months ago, # |   +2 As a participant,Orz yourself
 » 2 months ago, # | ← Rev. 2 →   +3 I have a mock round for my ICPC regionals and it ends just 5 minutes before the start of this codeforces round. Challenge accepted.
 » 2 months ago, # | ← Rev. 2 →   -41 5 problems again -_- Another speedforces maybe! but this time ABC :/
 » 2 months ago, # |   -106 As a tester up vote me ,problems are very nice
•  » » 2 months ago, # ^ |   +19 The problem is that you are not in the tester's list...
•  » » » 2 months ago, # ^ |   -97 hi covid
•  » » » » 2 months ago, # ^ |   +15 Are you the main account of Aman2?
•  » » » » » 2 months ago, # ^ |   0 Funniest thing ever LOL!
•  » » » » » 2 months ago, # ^ |   +9 Another one hoping to speed to reach -100 contribution lmfao
•  » » » » » » 2 months ago, # ^ |   0 Sparky_Master_WCH1226 achieved it in quite a hilarious way though.
 » 2 months ago, # |   +18 As a tester, hope you enjoy those excellent problems and wish you all high rating!
 » 2 months ago, # |   0 Glad to see partial Scoring :)
 » 2 months ago, # |   -34 i hope i can get top 10 in this contest
•  » » 2 months ago, # ^ |   +2 Top 10 before-contest commenting rituals
 » 2 months ago, # |   0 Score distribution looks good:)
 » 2 months ago, # |   +8 Hope I can become Candidate Master again.
•  » » 2 months ago, # ^ |   +18 Wow, this round was prepared by students from Beihang, which my ideal university is!
 » 2 months ago, # |   0 good luck all :)
 » 2 months ago, # |   +11 Won't be able to attend this round for some personal reason. Wish all the participants good luck. Hopefully, you will have a great time brainstorming.
 » 2 months ago, # |   +3 i wanna be specialist again, wish me good luck qwq
•  » » 2 months ago, # ^ |   +2 Wish all the best to you. And I hope I'll be able to get the lost rating in my last contest.
•  » » » 2 months ago, # ^ | ← Rev. 2 →   +2 thx, and wish u good luck qwq
•  » » » 2 months ago, # ^ |   -7 Rating is temporary, class is permanent
 » 2 months ago, # |   +2 pls not bitwise again
•  » » 2 months ago, # ^ |   0 How to bitwise?
•  » » » 2 months ago, # ^ |   0 wdym
•  » » » » 2 months ago, # ^ |   0 Looks like they bitwised again
 » 2 months ago, # |   0 I always wanted such an amazing score distribution lol.
 » 2 months ago, # |   +1 I hope PUPIL this time Spoilercoz Hope is a good thing
•  » » 2 months ago, # ^ |   +2 Please don't start hopeforces
•  » » » 2 months ago, # ^ |   0 why u being so negative dude?
•  » » » » 2 months ago, # ^ | ← Rev. 2 →   0 I missed the part where that's your problem.See my contributions if you want an answer for that
•  » » » 2 months ago, # ^ |   +10
•  » » 2 months ago, # ^ |   0 but i know that i won't make it , coz i am un prepared
 » 2 months ago, # |   -28 Finally there is a CHINESE Round!!!
 » 2 months ago, # |   -6 Just enjoy the round and test your skills.
 » 2 months ago, # |   -38 i just wanted to ask author , are covid cases still coming up in china?
 » 2 months ago, # |   0 Have they forgot to send an email? I didn't receive any!
 » 2 months ago, # |   0 Hoping for Pupil :)
 » 2 months ago, # |   -9 I have searched the whole post for these few words "The statements will be short and clean." But unfortunately, I couldn't find it and get disappointed :[ :P .
 » 2 months ago, # |   0 Hi bros!!!!!!!!
•  » » 2 months ago, # ^ |   0 Need your contribution dude
•  » » » 2 months ago, # ^ |   0 Yeah!!!!!!
•  » » » » 2 months ago, # ^ |   0 Dont be mad , do code .
 » 2 months ago, # |   0 Ok. I'm ready to help my new friend Mocha, if can :D
 » 2 months ago, # |   0 speedforces!
 » 2 months ago, # |   0 hello guys
 » 2 months ago, # |   +4 The downside of giving an easy A is you get a long queue...
 » 2 months ago, # |   +17 queue not ending!
 » 2 months ago, # |   +9 queue forces
 » 2 months ago, # |   -33 The round should be unrated , such a long queue .
 » 2 months ago, # |   +2 Queue is taking too long,if we get a wrong ans it tells us after minutes,and because of that we can't focus on ongoing quuestion, and time is also lost
 » 2 months ago, # |   -20 queueforces ???
•  » » 2 months ago, # ^ |   +2 Ya too much long queue!
 » 2 months ago, # |   0 Speedforces + long queue = RIP ratings:(
 » 2 months ago, # | ← Rev. 2 →   0 I think so many cheaters around there , solution are leaked in telegram, youtube
•  » » 2 months ago, # ^ |   -18 Dude, Why are u searching that in contest time. xD
•  » » » 2 months ago, # ^ |   -19 Dude cheating doesn't make sense , I suspected submissios for B and CEspecially B , See how less submission difference for A and B
•  » » » » 2 months ago, # ^ |   -14 Oke. but u should use your brain more without wasting time in thinking about cheating at least in contest time. (:I also against cheating may be most of them ^_^
•  » » 2 months ago, # ^ |   0 Don't worry , they will never have their rating depicting their true skills. They may get increased ratings now for which they cheat, but they're for sure gonna fail in long run. Since 2 years , one can observe the increased amount of cheating in these contests. I can understand ,it really hurts when you work genuinely and you don't get what you deserve because of these mfs.
 » 2 months ago, # |   -46 I want to see that shittiest pretest 2 for B
•  » » 2 months ago, # ^ |   -13 ??
•  » » » 2 months ago, # ^ |   +1 found that
•  » » 2 months ago, # ^ |   +6 Actually I am the shit
 » 2 months ago, # |   0 Hope I can become Candidate Master.
•  » » 2 months ago, # ^ |   0 The same answer for how I can become you.
 » 2 months ago, # |   -33 Too long queue and Speeforces round , Unfair contest
 » 2 months ago, # |   +1 div2.5
•  » » 2 months ago, # ^ | ← Rev. 10 →   +3 first 4 problems were like 4 problems of div3.
 » 2 months ago, # | ← Rev. 15 →   -26 s
 » 2 months ago, # |   +20 one of the most standard rounds I have seen in my life
 » 2 months ago, # |   -11 Hope to becume ♂Dungeon master♂ after this round
•  » » 2 months ago, # ^ |   +6 Ah ♂ That's ♂ Good
 » 2 months ago, # |   -7 Easy contest!!
 » 2 months ago, # |   0 is the solution to D2 some form of optimization of D1 using bitset in C++?
•  » » 2 months ago, # ^ |   +5 I'm not sure what was intended, but I used a randomized approach until there existed a connected component of large size, then I just tried all edges that have an endpoint not in that large component.
 » 2 months ago, # | ← Rev. 4 →   +65 Nice problems!Here's an extended version of $C$ which is cool:You won't be given the array $a_i$ itself, instead you will be given $n$ and you can interact and ask for particular values of $a_i$. Ask at most $20$ queries and output the answer as required in the original problem. Assume $n < 10^5$. Okay here is a solution as some people are asking: SolutionBasically you want to find an $i$ such that $a_i = 1$ and $a_{i-1} = 0$. You can just assume $a_0 = 0$ and $a_{n+1} = 1$. Let's say $\text{solve}(l, r)$ finds such $i$ in $[l, r]$ given $a_{l-1} = 0$ and $a_r = 1$.For $\text{solve}(l, r)$: If $l = r$, we found the required index. Otherwise, check $m = (l+r)/2$, if $a_m = 1$, call $\text{solve(l, m)}$ otherwise call $\text{solve}(m+1, r)$. Now, answer is just $\text{solve}(1, n+1)$.
•  » » 2 months ago, # ^ |   0 How would this version be solved?I have thought of a way in which we can find if the first element is 1 (to check for chains like n+1,1,2,3,4,...n) and to ask if a[n]==0 to check for chains like 1,2,3,4,5,...n,n+1.However how to check for other cases where the answer is possible.
•  » » » 2 months ago, # ^ |   0 you have to find place i where a[i] == 0 and a[i + 1] == 1.you can do that using binary search.after you find it (or if it doesn't even exist) you can solve it
•  » » » » 2 months ago, # ^ |   0 How to find it using binary search?
•  » » » » » 2 months ago, # ^ | ← Rev. 4 →   0 tbh I'm not sure whether this works but I would do sth like that if a[beg] == 0 and a[end] == 1 { if a[mid] == 1 then search in a[beg]..a[mid] else if a[mid] == 0 then search in a[mid]..a[end] } I hope this works :D
•  » » » » 2 months ago, # ^ |   0 But the number of queries will be greater than 20 ( log(10^5)==18 and then in each step of binary search we have to ask two values so 2*18==36>20 )
•  » » » » » 2 months ago, # ^ |   0 why 2?
•  » » » » » » 2 months ago, # ^ |   0 Nvm saw your implementation above
•  » » 2 months ago, # ^ |   0 Yea, nice one.But I personally don't like it when problem consists of 10 easy subproblems, so I would make this as a standalone problem
•  » » 2 months ago, # ^ |   0 What type of queries we can ask from interactor?
•  » » » 2 months ago, # ^ |   0 Particular values of $a_i$
•  » » » » 2 months ago, # ^ |   0 Umm ok, we can do binary search. Really cool problem.
•  » » 2 months ago, # ^ | ← Rev. 2 →   0 It exists on cf https://codeforces.com/problemset/problem/1019/B . It is one of my fav problem.
 » 2 months ago, # |   +18 How to solve E?
•  » » 2 months ago, # ^ | ← Rev. 4 →   +3 E was just like you calculate total number of sequence or pairs with gcd == x, like go from end pseudo code be like for j = m to j = 1: ans[j] = calculate(j) for(int i = 2 * j ; i <= m; i+=j) ans[j] -= ans[i] calculate(j) is of complexity m / j * n, using dynamic programming in total its $\sum_{y=0}^{m} (n * (m / j)) = O(m n log m)$
•  » » » 2 months ago, # ^ |   0 Can u explain how to make calculate(j) with the constraints a1 + a2 + ... + an <= m
•  » » » » 2 months ago, # ^ |   0 https://codeforces.com/blog/entry/93788?mobile=false#comment-829127 I have explained here There is also knapsack dp method using prefix sum , instead of generating function, refer Neal submission
•  » » 2 months ago, # ^ |   +3 let f(i) = number of sequence of length n with gcd == i for each range [lj,rj] 1 <= j <= n , there will [ (lj+i-1)/i , rj/i] number of element which are of multiple of i and therefore number of choices as well.Now, to compute f(i) we need to find a solution to the equationa1 + a2 ... an = m/i where each aj : [(lj+i-1)/i,rj/i] we can use PIE to solve above equation.Now, total number of sequence with gcd 1 will be sum of mu(i)*f(i) over 1 <= i <= m
 » 2 months ago, # | ← Rev. 2 →   +132 Even though I am not the target participant for this problemset, I thought the authors might enjoy some feedback. A: No comment. B: Classic problem. It is ok to give a classic problem as easy problem. C: The construction is clean, I liked it. The difficulty is appropriate. It is very similar to the construction of an Hamiltonian cycle in a tournament. D: Very cool problem. One immediately guesses that it must be possible to add an edge until one of the two forests becomes a tree. Then, it is easy to obtain an $O(n^2)$ solution, which is enough for the easy subtask. The hard subtask, which was quite hard for me, requires to optimize the solution to something pseudo-linear (in my case to $O(n \log(n)^2)$, but I am pretty sure that it is possible to do better). I really enjoy problems about optimizing quadratic solutions to pseudo-linear, and this is a great example of such a problem. It was a very nice idea to split the problem in two subtasks since the easy version is considerably easier than the hard version but still interesting. E: Standard problem. If one knows the right techniques (i.e., mobius mu function and backpack with copies of the same item) this is straightforward. Overall, it was a well-prepared contest. I had fun thinking about problem D. Thanks to the authors.
•  » » 2 months ago, # ^ |   +8 can you share some resources to learn the topics u mentioned for problem e ?
•  » » 2 months ago, # ^ | ← Rev. 3 →   +59 In problem D, you can add all possible edges from $1$ to other vertices. Then, divide all vertices into two groups: the first group consists of vertices in the same CC with $1$ in the first graph and in different CC with $1$ in the second graph, the second group is vice versa (some vertices may not lie in any group). Now we can add an edge between any pair of vertices from different groups, so we just have to maintain two queues of these groups and delete a vertex from a queue if it becomes bad at some point. Overall, it works in $O(n \cdot DSU(n))$.
•  » » » 2 months ago, # ^ |   +3 Neat solution. I would have never found this one during the contest.My solution is more involved (and thus I will not describe it). It maintains a sufficient amount of helping structures so that it is always possible to find a good edge to add in $O(\log(n))$ amortized time per edge (and $O(\log(n)^2)$ amortized time is required to update all the structures when an edge is added).
•  » » 2 months ago, # ^ | ← Rev. 2 →   +8 Interesting, that the mu function makes it straightforward. But since I have no about what it is (:P), I ended up with a separate DP which counts arrangements for all GCDs efficiently, eventually ending up with GCD = 1 arrangements.
•  » » » 2 months ago, # ^ |   +20 The important formula is (valid for any set $S$ of $n$-uples) $|\{(a_1,\dots,a_n)\in S:\ \gcd(a_1,\dots,a_n)=1\}| = \sum_{d=1}^\infty \mu(d)|\{(a_1,\dots,a_n)\in S:\ d|a_1,\, \dots,\,d|a_n\}| \,.$It is not hard to prove (once you look up the properties of the Mobius function $\mu$ on wikipedia) and it comes handy in a large number of problems.
•  » » » » 2 months ago, # ^ |   0 Can you share some resources from where a beginner (in this topic) can practice them?
•  » » » » » 2 months ago, # ^ |   +9 I learned a bit from this Codeforces tutorial Link.
•  » » » » » » 2 months ago, # ^ |   0 Thanks a lot.
•  » » » » 2 months ago, # ^ |   +64 Very cool, thanks a lot! I'm probably going to spend tonight learning more about it :)As for the DP solution I mentioned, the idea is to iterate over all values $g <= M/N$ in decreasing order, calculating the number of arrangements that follow the constraints on the sum and the individual value ranges, such that the GCD of the sequence is $k*g$ for some positive integer $k$. $dp[i][j]$ = number of valid suffixes starting at $i$ and with sum at max $j*g$ that follow the constraints I mentioned above. To transition, take the sum of all $dp[i][j-x]$ such that $l[i]/g <= x <= r[i]/g$. We can make transitions constant time by maintaining prefix sums.Now, let's denote arrangements with GCD exactly $g$ as $count[g]$. $count[g] = dp[0][M/g] - \sum count[x]$, where $x$ are multiples of $g$. Our answer will lie in $count[1]$.
•  » » 2 months ago, # ^ |   0 May you link on set of classic problems as B? It'd be useful for newbie as I.
•  » » 2 months ago, # ^ | ← Rev. 2 →   +79 Edit: I am talking about D2I also had the $(\log{n})^2$ idea initially (small to large merging with some multiset-like data structure). I optimized it by using the following simple idea to construct edges:If any forest becomes connected, we are done. Otherwise, both forests have at least $2$ components. Consider any two nodes $x$, $y$ in distinct components of the first forest and any two nodes $p$, $q$ in distinct components of the second forest.If $x$ and $y$ are in distinct components of the second forest, then add edge between $x$ and $y$. Otherwise, at least one among $u$ and $v$ will be in a different component than $x$ and $y$ in the second forest, say $u$. Now, at least one among $x$ and $y$ will be in different component than $u$ in the first forest, say $x$. So merge $u$ and $x$.This construction in fact acts as a proof for the solution!
•  » » » 2 months ago, # ^ |   0 very cool solution
 » 2 months ago, # |   +6 Solved A and C but with 9 wrong answers and very slow. My worst contest yet. Look forward to improving speed and accuracy.
 » 2 months ago, # | ← Rev. 2 →   -17 One of the easiest div2D1 ever i should have started with D i got idea + implementation in less than 10 min.again unable to solve A,B,C
 » 2 months ago, # |   +74 Thanks for the contest, it had nice problems especially C and E.However I'm not much of a fan of D1. I saw constraints and just guessed that trying every edge in any order would work. I suspect that many other participants did the same without even trying to prove it. Just my opinion, but I'm not much of a fan of problems where guessing the answer and getting proof by AC is significantly easier than proving why it works.
•  » » 2 months ago, # ^ |   -24 I think it was not guessing the answer.If you have read/studied Krushkal algorithm it uses Dsu to ensure that the new vertices do not form cycle with previous edges. Same is the case with this problem.
•  » » » 2 months ago, # ^ |   +11 That does not guarantee optimality of the construction.
•  » » 2 months ago, # ^ |   0 I took all the unaccounted edges in a set and traversed through all and checked whether adding would lead to a cycle in any of the 2 graphs. However, I got time limit exceeded on test 6. Can you tell what extra optimization did you do? Here's my submission.
•  » » » 2 months ago, # ^ |   +8 Going through all the unvisited edges is alredy n^2, checking for cycle makes it n^3 but i'm not sure if it's mathematically n^3 only or not. Rather, just check if it's part of different trees or not by mantaining array marking some sort of tree number for every node and mantain this array. Again, not exactly sure what the complexity will look like for this.
•  » » » » 2 months ago, # ^ |   0 Thank you!
•  » » 2 months ago, # ^ |   0 My explanation is that:$[1]$ Let $u$ and $u'$ are any 2 nodes in Mocha graph that not in the same connected component$[2]$ Let $v$ and $v'$ are any 2 nodes in Diana graph that not in the same connected componentThere will be at least a way to connect $u-v, u-v', u'-v, u'-v'$ to form 2 forests without making a cycle to it. If there is no such $u'$ or $v'$ then there will be no more edge since no matter how we add edge it will form a cycle else we can repeat this multiple timesNo matter what is the order you choose for the edges to be add, it will always such edges that satisfy the statement — which is not making a new cycle into graph — such $u-v$ or $u-v'$ or $u'-v$ or $u'-v'$ satisfied $[1], [2]$Therefor we will have the result of maximum possible edges can be added, by keep finding new $u, u', v, v'$ satisfied $[1], [2]$By using brute-forces algorithm for each possible $i$ and $j$, we tested for all for cases ($i = u$ or $i = u'$) with ($j = v$ or $j = v'$) for any $u, u', v, v'$ satisfied, those who are not will not included in the result, those of which are needed will added to resultWe don't need to redo the brute-forces every times we add a new edges, since those are which either already an edge or will make a new cycle, and will never satisfy againUsing Disjoint Set Union Data Structure, we can check for any 2 nodes that in the same connected component or notTherefore we only need brute-forces for $O(n^2)$ with a little help of data structure $O(\alpha(n))$ amortized per query
•  » » 2 months ago, # ^ |   +5 Well some proofs for D1 did help in solving D2. For example my proof (and solution for D2) described here.
 » 2 months ago, # |   -10 I have firstly met the error "wrong answer Token parameter [name=s] equals to "BRBRRBRBBR", doesn't correspond to pattern "[BR]{1}" (test case 4)" in task B. Funny, I just don't write 5 rows, but description turn me to deep frustration. ha-ha)
 » 2 months ago, # |   0 Video Tutorial C: https://www.youtube.com/watch?v=H8GDDIAOVdQ
 » 2 months ago, # |   +9 Nice contest, kudos to the authors.
 » 2 months ago, # |   +67 Problems were really nice. I would have expected a harder E and an easier D2 but it was good however. Congrats to the problemsetters.
 » 2 months ago, # |   +2 Can someone please tell me when there will be -1 solution for problem C. And also Solution for C. As per my intuition there will always be a answer.
•  » » 2 months ago, # ^ |   0 Yes, there will always be an answer.
•  » » 2 months ago, # ^ |   0 Case 1:jumping from n+1 to 1 Case 2:jumping from n to n+1 Case 3:jumping from i to n+1, then n+1 to i+1
•  » » » 2 months ago, # ^ |   0 How to see that there are no other cases?
•  » » » » 2 months ago, # ^ |   0 you can only visit n+1 once
•  » » » » 2 months ago, # ^ | ← Rev. 2 →   +10 Consider the array A is a binary string. The following 3 cases cover all possible binary strings: String ends with '0' String starts with '1' String contains '01' as a substring Answer exists for all 3
•  » » » 2 months ago, # ^ |   0 I made the same cases but got wrong answer on test case 3. Then I thought my intuition is wrong and gave up. Now I'm waiting system testing to be done to see where did my solution failed.
 » 2 months ago, # |   +5 Did anyone solve E using Polynomial Multiplication and FFT ? I tried to implement it but it gave incorrect output for Sample Test Case 3 and then I could'nt debug it
 » 2 months ago, # |   0 Not good for div 2 contest
•  » » 2 months ago, # ^ |   0 was it easy?
•  » » » 2 months ago, # ^ |   0 yes
 » 2 months ago, # |   +4 WOW!! Score distribution was correct!! :p
 » 2 months ago, # |   -13 Imagine being sponsored by Telegram and ITMO and still be laggy af
 » 2 months ago, # |   0 Does anyone have code for generating random forests so I can test my solution for D1 before the System Test ends?
•  » » 2 months ago, # ^ | ← Rev. 2 →   0 Spoiler#include using namespace std; #define ll long long #define pb push_back const ll MAX = 1e5; int randd(int a, int b){ return a + rand() % (b-a+1); } int main(int argc, char* argv[]){ srand(atoi(argv[1])); int n = randd(2, 10); int m1 = randd(1, n-1); int m2 = randd(1, n-1); cout << n << " " << m1 << " " << m2 << endl; for(int i = 0; i
•  » » » 2 months ago, # ^ |   0 Thanks.
 » 2 months ago, # |   0 can someone tell me how to do A XD?
•  » » 2 months ago, # ^ |   0 u just use the & operation over all the elements...
•  » » » 2 months ago, # ^ |   0 bruh
•  » » » » 2 months ago, # ^ |   0 It is simple problem hidden behind complecated words. Since we can pair any element with any other element, we can remove any bit that is not set in all numbers. One simple way to find that bits is doing AND on all numbers.
•  » » 2 months ago, # ^ |   0 Ha-ha, I used vector of vector of 31 bools (10^9 ~= 2^30) and then & each column to result vector. After that convert binary representation to long long.Wow, it's really funny that it's equal to & over all the elements.
•  » » 2 months ago, # ^ |   +1 ans=a1&a2&a3&a4&...&an, since a&b is always not greater than a and b themselves.
•  » » 2 months ago, # ^ |   0 I just apply operation on the whole array until i get an array with all element being equal.
 » 2 months ago, # |   0 First time in div2 I was able to solve till D (D1) . Though it was an easy contest overall i really enjoyed it after coming back from a long break.
 » 2 months ago, # | ← Rev. 2 →   +38 D2 O(n * dsu(n)) solution from ♂Dungeon master♂Maintain two dsu, one for each forest. Ass long ass there is a vertex that is not connected to vertex 1 in first graph and vertex 1 in second graph, connect it with vertex 1 in both forests. Then ass long ass there is a vertex X in first graph that is not connected to 1 and vertex Y in second graph that is not connected to 1, connect X and Y in both forests. Can be performed with two pointers, one find X, other find Y. Proof is on you, ♂slaves♂
•  » » 2 months ago, # ^ |   0 man that is so easy yet so complicated :D
 » 2 months ago, # |   +24 I'm surprised 5k people solved D1
•  » » 2 months ago, # ^ |   0 Well, DSU is quite a common data structure nowadays most of the newbies and pupils know about them if they have gone through the kruskal's algorithm.
•  » » » 2 months ago, # ^ | ← Rev. 2 →   +2 I expected the sulution to need some clever ordering of connecting the components. I still do not see how any order can allways be optimal. So the problem is not to know DSU, it is to see (or just try) that brute force works.
•  » » » » 2 months ago, # ^ |   0 Ya at first i tried to find any order to add the edges but then I just tried adding the edges manually and see what's the maximum number of edges i can add and after going through some random test cases i noticed that we have to add as many edges as we can until there is not any edge to add. of course by checking if adding that edge is not forming any cycle then i just implemented two dsu's and it worked.
 » 2 months ago, # | ← Rev. 2 →   +1 D2 is truly interesting...Thanks for such problems
 » 2 months ago, # |   0 has anyone solved C using reverse edges and starting dfs from node n + 1? i just want to know if its a correct solution
•  » » 2 months ago, # ^ |   0 it's not a dfs problem tbh, at least i didn't feel it, maybe there exist a solution but i think it makes this problem kinda harder in implementationidea is: if u can't get from n+1 to 1 then u have to start from 1if node n have path to node n+1 u can just go from 1 to n+1if node n+1 have path to 1 then answer is: n+1, 1, 2 .. nif it doesnt just find if there exist any point where node i has path to n+1 and n+1 has path to node i+1, then answer is 1, 2..i n+1 i+1 i+2 .. nbasically u just can't skip any node and can start either from n+1 or 1
•  » » » 2 months ago, # ^ |   0 oh well guess ill try this then thanks
•  » » 2 months ago, # ^ |   +1 Hey, I solved C using DFS with Toposort you can check it here 125991523.
•  » » » 2 months ago, # ^ |   0 Plz explain your approach
 » 2 months ago, # |   +27 Also, was there a reason for $n \leq 10^4$ in problem C? Both the solution and the judge seem trivial to code in $O(n)$. Was the problem initially interactive somehow?
 » 2 months ago, # | ← Rev. 3 →   +3 I will FST on C, I believe there was no pretest with all 1's... Why?Edit: I failed indeed. Overall I enjoyed the contest. I think having some pretest with all 1's was needed. I was surprised because even if it is a useful test or not, it seems like if the input is an array where the values can only be 1 or 0, arrays with all 1's or all 0's naturally come to mind as tests. That's what I think, though I'm not a problemsetter. I hope someone finds this feedback useful. As I said, I really enjoyed the round anyway.
•  » » 2 months ago, # ^ |   -16 I think there is all 1's in 2nd pretest.
 » 2 months ago, # |   +6 arcaea www
 » 2 months ago, # |   0 can we find number of solution of a1 +a2 +a3 ... an = m with upper bound on each variable in O(n) or O(n^2)
•  » » 2 months ago, # ^ |   0 I imagine using Multinomial Theorem and Polynomial multiplication we can do that in $O(N*MlogM)$.
•  » » 2 months ago, # ^ |   0 I think I used the approach you are describing for problem E. I just could not think of anything so I came up with a kind of naive $O(nmlog^2(m))$ solution where we iterate through values from m to 1 and we calculate $f(i)$ which is the number of solutions that satisfies the first and second condition, and the gcd of all n numbers are a multiple of i. Then if we can efficiently find f(i), we can calculate $g(i)$ which is the number of combinations that satisfies the first and second condition, AND the gcd of all n numbers are exactly i, via the relationship $g(i) = f(i) - \sum_{j=2}^{m/i} g(i*j)$ which can be calculated in $O(mlog(m))$ due to the harmonic series. For calculating $f(i)$, you can use a knapsack dp that runs in $O(nmlog(m)/i)$ for each i using BIT. Then we obtain a solution $O(nmlog^2(m))$.
•  » » 2 months ago, # ^ | ← Rev. 2 →   +4 I think I solved it in $O(nm)$ using the formula given by inclusion-exclusion principle, as presented in this Stackexchange link.Firstly, you precompute factorials to be able to compute binomial coeficient fast.Secondly, you compute how many even-sized and odd-sized subsets give a certain sum $x$. We compute sets of different parity separatelly, to quickly compute $(-1)^{|S|}$. This is done by knapsack-like loop (remebember to increase upper bounds by one before running the loop): for each upper bound r: for each possible sum x in m downto r: odds[x] += evens[x - r]; evens[x] += odds[x - r]; Thirdly, now we know the number of subsets that have given sum of $r_i$, so we iterate over those sums and change our ans accordingly: ans += (evens[x] - odds[x]) * binomial(n + m - x, n) (+-1 ommited for clarity).If you want to compute number of solutions to $a_1 + a_2 + ... + a_n \leq m'$ then it corresponds to $m$ going from $0$ to $m'$ in the formula from third step. Notice, that most of those binomial will be equal to $0$ if we process them in the reversed order (aka from $m'$ to $0$).We introduce variable $help = 0$ and simply increment it by $binom(m' - x + n, n)$ and change our ans accordingly: ans += help * binomial(n + m - x, n).Unfortunatelly, I finished coding just after the round and now I'm impatiently waiting for system tests to finish and submit possiblity. #feelsbadmanEdit: It passed systests: Submission 126025440 :D
•  » » » 2 months ago, # ^ |   0 replying to find it later. p.s -> how to find a particular comment easily later ?
•  » » » » 2 months ago, # ^ |   0 There are those permalinks to comments (# symbol in the comment header, like https://codeforces.com/blog/entry/93788?#comment-829093). I guess you could save those in some file comments you find interesting.I, for one, have never needed to save a particular comment. With blogs / articles I intend to read later, in Chrome there is a list to read. You press the favourite star symbol in the address bar and the option pops out.
•  » » » » » 2 months ago, # ^ |   0 I figure the api design. But how will I know the ID is of your comment lol.
•  » » » 2 months ago, # ^ |   0 we could also use generating function to calculate the formula like this basically we need to calculate $[x^m] \prod_{i} \sum_{j = l_i}^{r_i}x^j$ $[x^m]\left( x^{\sum_{}l_i} \right) \times (1-x)^{-n} \times \left( \prod_{i}(1 - x^{r_i - l_i + 1}) \right)$ $[x^{m-\sum_{}l_i}] \times (1-x)^{-n} \times \left( \prod_{i}(1 - x^{r_i - l_i + 1}) \right)$ we can calculate coefficients of this polynomial $\prod_{i}(1 - x^{r_i - l_i + 1})$ in total of $O(n * m)$ time using knapsack dp as we need atmost m powers. as we need sum of all coefficient we need to multiply the equation by $(1-x)^{-1}$ again so finally we need $[x^{m-\sum_{}l_i}] ( (1-x)^{-(n+1)}) \times \left( \prod_{i}(1 - x^{r_i - l_i + 1}) \right)$ As power is fixed this becomes $O(m)$ to calculate, as negative binomial expansion coefficient for any power of $x$ can be represented in closed form after using harmonic sum property for all calculating gcd = 1 total complexity becomes $\sum_{i=1}^{m} calculate(x / i)$ = $O(m.n.log(m))$
 » 2 months ago, # |   +107
•  » » 2 months ago, # ^ |   -29 Yet I passed pretests printing -1 D:
 » 2 months ago, # | ← Rev. 4 →   +73 https://codeforces.com/contest/1559/submission/125941230 — sent at minute 8, evaluated at minute 10 https://codeforces.com/contest/1559/submission/125944849 — sent at minute 13, evaluated at minute 17 https://codeforces.com/contest/1559/submission/125939758 -> https://codeforces.com/contest/1559/submission/125946723 !! — sent at minute 6, evaluated at minute 8my submission: https://codeforces.com/contest/1559/submission/125937327 — sent at minute 4, evaluated at minute 20.This weird late evaluation gave others a faster time to resubmit and eventually get accepted (and they did), but my submission was evaluated very late (although submitted very early!), and that gave me a great disadvantage).Could anyone explain how this could've happened?MikeMirzayanov sorry to tag you, but I don't want to lose rating over this. If my solution would've been evaluated instantly, it would've still taken me a minute to correct the problem, and now I am facing a 15 minute penalty (which normally should be 3, and now costs me a lot of rating) for very ambiguos reasons :(
•  » » 2 months ago, # ^ |   +3 I too had a queue of over 15 minutes for my C. Never seen a contest with this long queue ever being rated. I even had gotten up then thinking the contest would definitely get unrated. I don't mind having long queues for rated contests, just some standard should be followed. On one day a 15 minute queue makes unrated, on some other day it doesn't. RIP Ratings. I got quite nervous.
 » 2 months ago, # |   +2
 » 2 months ago, # |   +4 Thanks for the great round! :) I like problem D2 very much, it's the most interesting problem I've ever seen :)
 » 2 months ago, # |   0 Can't I solve E with FFT or NTT?
•  » » 2 months ago, # ^ |   +3 I tried but it was still slow. I stress-tested on max constraints it took about 1 minute to execute on my PC.Code: 126014845
•  » » » 2 months ago, # ^ |   0 Thanks.
 » 2 months ago, # |   +71 Posted my solutions video: https://www.youtube.com/watch?v=U68R-0_6o9o
 » 2 months ago, # | ← Rev. 2 →   +22 Now that's a contest (UPD: WOW FST on test 57)
 » 2 months ago, # |   0 In C. Mocha and Hiking, can't we just go from 1st village to final village through every village continuously? I mean, 1 2 3 4 ... n+1 Isn't this a solution? I know that if this is a stupid answer, but technically, it is satisfying the conditions, right?
•  » » 2 months ago, # ^ |   +1 Yes, if a[n] == 0 you can just travel from 1 to n+1
•  » » » 2 months ago, # ^ |   0 Shit. Sorry. I thought it included all the villages. My bad.
•  » » 2 months ago, # ^ |   +2 There is no first kind of edge between n and n+1.
 » 2 months ago, # |   +11 Nice round. loved it.
 » 2 months ago, # | ← Rev. 2 →   0 what's this??? My solution for A and C was accepted and pretest(3) and pretest(15) passed for A and C respectively. But after system testing both become WA. If WA shows in the live contest then maybe I solve it with different approach.
•  » » 2 months ago, # ^ |   0 it is because system testing is not yet finished.
•  » » » 2 months ago, # ^ |   0 But solutions which are in testing show in queue but my both solution is showing WA
•  » » » » 2 months ago, # ^ |   0 It's typical of the system to show that, wait and it will turn back.
•  » » » » » 2 months ago, # ^ |   +1 testing completed and I got one AC and one WA (even after getting pretest passed(3) )
 » 2 months ago, # |   0 Can anyone tell me why my submissions for D1 failed test6? This was the first submission 126009094
 » 2 months ago, # |   +9 After solving A-D1, I got nothing to do.
 » 2 months ago, # |   +16 Nice problems guys. Good team work!
 » 2 months ago, # |   +45
•  » » 2 months ago, # ^ |   0 lol. But it was easy. I just guessed the answer without even understanding why it works.
 » 2 months ago, # | ← Rev. 2 →   +13 It's a good contest.But I have a question:Could anyone hack my code(D2): https://codeforces.ml/contest/1559/submission/126013197Maybe it's easy to hack...upd:hacked by peti1234
•  » » 2 months ago, # ^ | ← Rev. 2 →   +8 Unexpected verdict. I don't know what to do with this.UPD: Hacked
 » 2 months ago, # |   +1 i bricked this contest can i hvae some contrubtion points
 » 2 months ago, # |   +25 It's a nice contest in general.But I should say that the difficulty between ABCD1 and D2E is like a cliff
 » 2 months ago, # |   0 Hoping to become pupil after this contest!
 » 2 months ago, # |   0 Tried hard to solve C, BTW nice round
 » 2 months ago, # | ← Rev. 2 →   0 When will rating be updated?UPD: Ratings changed Thanks.
 » 2 months ago, # |   +17 ranran(Diana) you take me away！
•  » » 2 months ago, # ^ |   +3 jiaxintang pi dou mei you yong !
•  » » » 2 months ago, # ^ |   +3 wo men jia xin tang xiang yao zheng fa yi ge ding wan ren hai shi hen rong yi de!
•  » » 4 weeks ago, # ^ |   0 heyheyhey，ranran(Diana)，my ranran，heyheyhey
 » 2 months ago, # | ← Rev. 2 →   -16 Problem D1: This is the easy version of the problem. The only difference between the two versions is the constraint on n. I have an AC code on problem D2 and the same code got WA on D1 ?!!
•  » » 2 months ago, # ^ |   -17
•  » » 2 months ago, # ^ |   +5 please note that your solution on D2 doesn't work on D1
•  » » » 2 months ago, # ^ |   -23 Oops, My "Newbie" teammate is here for contributions LOL, I think I have to reach your rate to understand how you think before replying. (good luck in solving D1 & D2 Mr. Suliman)
 » 2 months ago, # |   +6 editorial?
 » 2 months ago, # | ← Rev. 2 →   0 Is there any way to see the whole input of a test case. I really can't figure out what I did wrong here:https://codeforces.com/contest/1559/submission/126029664Edit: figured it out ;)
 » 2 months ago, # |   +74 To not keep you waiting, the ratings are updated preliminarily. In a few hours/days, I will remove cheaters and update the ratings again!
•  » » 2 months ago, # ^ | ← Rev. 2 →   0 Hi. Can you tell me why my rating decreased even after solving 2 questions of div 2 contest when I am in div 3. My rating decreased from 1078 -> 1060.
•  » » » 2 months ago, # ^ |   +1 It doesn't matter how many problems you solved, what matters is how good you did compared with others and your current rating. You solved less problems or solved them slower than people with similar rating, therefore your rating went down.
•  » » » » 2 months ago, # ^ |   -20 So should I not give contests which are rated for div 1 & 2 for now? I am in div 3 right now and am still learning about competitive programming.
•  » » » » » 2 months ago, # ^ |   0 You should still give contests rated for Div. 2 and everyone, it's a great opportunity to practice your competitive programming skills.
 » 2 months ago, # |   +2 Succeed！I am not a newbie now.
 » 2 months ago, # |   0 This contest was really an amazing experience. 1st time i was able to solve 3 problems of div 2
 » 2 months ago, # |   0 Great Round, thanks!
 » 2 months ago, # |   -10 Thanks for the great contest. But unfortunately I got negative delta again :(
 » 2 months ago, # |   0
 » 2 months ago, # | ← Rev. 2 →   0 How a problem's difficulty is calculated?? like 1600 or 1700. I think this contest's D1 was 1600 but still 4500 plus participants solved it.
 » 2 months ago, # |   +6 Received a mail saying my solution to B coincides with this, and I agree, it does. But I think it's a reasonable solution. Surprised there was only one such clash. Obviously don't have any evidence to "prove" that I didn't copy. Any ideas as to how I can refute this?
•  » » 2 months ago, # ^ |   +1 I think it's reasonable that two submissions is almost the same in a div2.B.
 » 2 months ago, # |   0 finaly experts had an oportunity of participating in a div3 round.
 » 2 months ago, # |   +11 MikeMirzayanov I've got a message that the following solutions coincide: SunTakesTooLongToDie/125962649, Tony1234_/125963558The code is obviously taken from this blog
 » 2 months ago, # |   0 I wonder why pypy3 slower than python3 when run a same code ? Isn't pypy an upgraded version of python? :O python3:https://codeforces.com/contest/1559/submission/126146836 pypy3:https://codeforces.com/contest/1559/submission/126146809
 » 2 months ago, # |   0 MikeMirzayanov, I've received a system message saying :"Your solution 125949787 for the problem 1559C significantly coincides with solutions spy20051623/125949787, ZeldaHuang/125971185."The code is completely written by myself and I didn't send it to anyone during contest time. The problem is not difficult for Experts and Candidate Masters to solve, and it's possible to write similar codes.In addition, I find many solutions similar to it, such as 125971285, 125972457 (I chose them just from common standing page 3). I hope my "violation" to be checked again.Thank you all staffs!
 » 2 months ago, # |   -11 I used ideone.com to write my code in public mode and someone got the access and copied my code. This was a mistake that wont be repeated in future.
 » 7 weeks ago, # |   0 In the official standings how did rank 296 got 100+ delta while CMs above him with lower rating got lesser delta