Bazoka13's blog

By Bazoka13, history, 3 years ago, In English

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, Oshwiciqwqq and me. We hope you will enjoy the round. :P

We would like to thank:

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

  1. Suckmycode
  2. Wlxsohandsome
  3. idontwannawin
  4. shu_ya_zi
  5. _Kubic_

Div. 1 + Div. 2

  1. neal
  2. ksun48
  3. Geothermal
  4. sjc061031
  5. Kirill22
  • Vote: I like it
  • +796
  • Vote: I do not like it

| Write comment?
»
3 years ago, # |
  Vote: I like it +595 Vote: I do not like it

Darn, my VIP tester streak ended.

»
3 years ago, # |
  Vote: I like it -185 Vote: I do not like it

Announcement blog 3 days before round -> bad round

»
3 years ago, # |
  Vote: I like it +59 Vote: I do not like it

As a tester, have fun!

»
3 years ago, # |
Rev. 3   Vote: I like it +60 Vote: I do not like it

As a tester. You must be careful with your code and try to solve $$$x$$$ ($$$1 \leq x \leq 5$$$) problems!

Good luck!

-QuangBuiYT

»
3 years ago, # |
  Vote: I like it +8 Vote: I do not like it

Hoping to regain specialist after this round!

»
3 years ago, # |
  Vote: I like it +119 Vote: I do not like it

As a tester, oooops I find myself a problem setter! lol

»
3 years ago, # |
  Vote: I like it +81 Vote: I do not like it

As a coauther & tester for the first time, I hope you enjoy this round!

»
3 years ago, # |
  Vote: I like it +12 Vote: I do not like it

orz

»
3 years ago, # |
  Vote: I like it +86 Vote: I do not like it

As a tester, hope you enjoy those excellent problems and wish you all high rating!

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

Hope to become pupil again this time!

»
3 years ago, # |
  Vote: I like it +1 Vote: I do not like it

The scoring distribution looks noice!!!

»
3 years ago, # |
  Vote: I like it +22 Vote: I do not like it

hoping for nice round and thanks author for spending your time for us

»
3 years ago, # |
  Vote: I like it +8 Vote: I do not like it

Hope for a great round,and thanks for the early score distribution!

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

OrzOrz

»
3 years ago, # |
  Vote: I like it +17 Vote: I do not like it

As a tester,I'm sure that it is a fabulous round!

»
3 years ago, # |
  Vote: I like it +14 Vote: I do not like it

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 ?
»
3 years ago, # |
  Vote: I like it +4 Vote: I do not like it

speedforces ABC?

  • »
    »
    3 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Maybe not speedforces, but balanced like 1300 A, 1500 B, 1700 C or something like that but harder than normal round ABCs.

»
3 years ago, # |
  Vote: I like it +31 Vote: I do not like it

why he write 6problems as e is the hard version of d only

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

    Thank you for your reminding, I have updated the announcement :)

»
3 years ago, # |
Rev. 7   Vote: I like it +5 Vote: I do not like it

Behold The Chinese Round! Orz

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

Good luck to everyone!

»
3 years ago, # |
  Vote: I like it +2 Vote: I do not like it

Auto comment: topic has been updated by Bazoka13 (previous revision, new revision, compare).

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

    If we are given 5 problems so why the scoring distribution is saying we're ganna have 6 problems ?

    Spoiler
    • »
      »
      »
      3 years ago, # ^ |
        Vote: I like it +14 Vote: I do not like it

      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.

»
3 years ago, # |
  Vote: I like it +2 Vote: I do not like it

As a participant,Orz yourself

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

I have a mock round for my ICPC regionals and it ends just 5 minutes before the start of this codeforces round. Challenge accepted.

»
3 years ago, # |
  Vote: I like it -106 Vote: I do not like it

As a tester up vote me ,problems are very nice

»
3 years ago, # |
  Vote: I like it +18 Vote: I do not like it

As a tester, hope you enjoy those excellent problems and wish you all high rating!

»
3 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Glad to see partial Scoring :)

»
3 years ago, # |
  Vote: I like it -34 Vote: I do not like it

i hope i can get top 10 in this contest

»
3 years ago, # |
  Vote: I like it +8 Vote: I do not like it

Hope I can become Candidate Master again.

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

    Wow, this round was prepared by students from Beihang, which my ideal university is!

»
3 years ago, # |
  Vote: I like it +11 Vote: I do not like it

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.

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

i wanna be specialist again, wish me good luck qwq

»
3 years ago, # |
  Vote: I like it +2 Vote: I do not like it

pls not bitwise again

»
3 years ago, # |
  Vote: I like it +1 Vote: I do not like it

I hope PUPIL this time

Spoiler
»
3 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Have they forgot to send an email? I didn't receive any!

»
3 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Hoping for Pupil :)

»
3 years ago, # |
  Vote: I like it -9 Vote: I do not like it

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 .

»
3 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Ok. I'm ready to help my new friend Mocha, if can :D

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

The downside of giving an easy A is you get a long queue...

»
3 years ago, # |
  Vote: I like it +17 Vote: I do not like it

queue not ending!

»
3 years ago, # |
  Vote: I like it +9 Vote: I do not like it

queue forces

»
3 years ago, # |
  Vote: I like it +2 Vote: I do not like it

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

»
3 years ago, # |
  Vote: I like it -20 Vote: I do not like it

queueforces ???

»
3 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Speedforces + long queue = RIP ratings:(

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

I think so many cheaters around there , solution are leaked in telegram, youtube

  • »
    »
    3 years ago, # ^ |
      Vote: I like it -18 Vote: I do not like it

    Dude, Why are u searching that in contest time. xD

    • »
      »
      »
      3 years ago, # ^ |
        Vote: I like it -19 Vote: I do not like it

      Dude cheating doesn't make sense , I suspected submissios for B and C

      Especially B , See how less submission difference for A and B

      • »
        »
        »
        »
        3 years ago, # ^ |
          Vote: I like it -14 Vote: I do not like it

        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 ^_^

»
3 years ago, # |
  Vote: I like it -46 Vote: I do not like it

I want to see that shittiest pretest 2 for B

»
3 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Hope I can become Candidate Master.

»
3 years ago, # |
  Vote: I like it +1 Vote: I do not like it

div2.5

»
3 years ago, # |
  Vote: I like it +20 Vote: I do not like it

one of the most standard rounds I have seen in my life

»
3 years ago, # |
  Vote: I like it -11 Vote: I do not like it

Hope to becume ♂Dungeon master♂ after this round

»
3 years ago, # |
  Vote: I like it 0 Vote: I do not like it

is the solution to D2 some form of optimization of D1 using bitset in C++?

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

    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.

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

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:

Solution
  • »
    »
    3 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    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.

    • »
      »
      »
      3 years ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      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

      • »
        »
        »
        »
        3 years ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

        How to find it using binary search?

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

          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

      • »
        »
        »
        »
        3 years ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

        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 )

  • »
    »
    3 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    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

  • »
    »
    3 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    What type of queries we can ask from interactor?

  • »
    »
    3 years ago, # ^ |
    Rev. 2   Vote: I like it 0 Vote: I do not like it

    It exists on cf https://mirror.codeforces.com/problemset/problem/1019/B . It is one of my fav problem.

»
3 years ago, # |
  Vote: I like it +18 Vote: I do not like it

How to solve E?

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

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

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

    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 equation

    a1 + 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

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

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.

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

    can you share some resources to learn the topics u mentioned for problem e ?

  • »
    »
    3 years ago, # ^ |
    Rev. 3   Vote: I like it +59 Vote: I do not like it

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

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

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

  • »
    »
    3 years ago, # ^ |
    Rev. 2   Vote: I like it +8 Vote: I do not like it

    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.

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

      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.

      • »
        »
        »
        »
        3 years ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

        Can you share some resources from where a beginner (in this topic) can practice them?

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

        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]$$$.

  • »
    »
    3 years ago, # ^ |
    Rev. 2   Vote: I like it +79 Vote: I do not like it

    Edit: I am talking about D2

    I 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!

»
3 years ago, # |
  Vote: I like it +6 Vote: I do not like it

Solved A and C but with 9 wrong answers and very slow. My worst contest yet. Look forward to improving speed and accuracy.

»
3 years ago, # |
  Vote: I like it +74 Vote: I do not like it

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.

  • »
    »
    3 years ago, # ^ |
      Vote: I like it -24 Vote: I do not like it

    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.

  • »
    »
    3 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    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.

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

      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.

  • »
    »
    3 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    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 component

    There 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 times

    No 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 result

    We 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 again

    Using Disjoint Set Union Data Structure, we can check for any 2 nodes that in the same connected component or not

    Therefore we only need brute-forces for $$$O(n^2)$$$ with a little help of data structure $$$O(\alpha(n))$$$ amortized per query

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

    Well some proofs for D1 did help in solving D2. For example my proof (and solution for D2) described here.

»
3 years ago, # |
  Vote: I like it +9 Vote: I do not like it

Nice contest, kudos to the authors.

»
3 years ago, # |
  Vote: I like it +67 Vote: I do not like it

Problems were really nice. I would have expected a harder E and an easier D2 but it was good however. Congrats to the problemsetters.

»
3 years ago, # |
  Vote: I like it +2 Vote: I do not like it

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.

  • »
    »
    3 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Yes, there will always be an answer.

  • »
    »
    3 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    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

    • »
      »
      »
      3 years ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      How to see that there are no other cases?

      • »
        »
        »
        »
        3 years ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

        you can only visit n+1 once

      • »
        »
        »
        »
        3 years ago, # ^ |
        Rev. 2   Vote: I like it +10 Vote: I do not like it

        Consider the array A is a binary string. The following 3 cases cover all possible binary strings:

        1. String ends with '0'
        2. String starts with '1'
        3. String contains '01' as a substring

        Answer exists for all 3

»
3 years ago, # |
  Vote: I like it +5 Vote: I do not like it

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

»
3 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Not good for div 2 contest

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

WOW!! Score distribution was correct!! :p

»
3 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Does anyone have code for generating random forests so I can test my solution for D1 before the System Test ends?

  • »
    »
    3 years ago, # ^ |
    Rev. 2   Vote: I like it 0 Vote: I do not like it
    Spoiler
»
3 years ago, # |
  Vote: I like it 0 Vote: I do not like it

can someone tell me how to do A XD?

  • »
    »
    3 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    u just use the & operation over all the elements...

    • »
      »
      »
      3 years ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      bruh

      • »
        »
        »
        »
        3 years ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

        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.

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

    ans=a1&a2&a3&a4&...&an, since a&b is always not greater than a and b themselves.

  • »
    »
    3 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    I just apply operation on the whole array until i get an array with all element being equal.

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

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♂

»
3 years ago, # |
  Vote: I like it +24 Vote: I do not like it

I'm surprised 5k people solved D1

  • »
    »
    3 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    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.

    • »
      »
      »
      3 years ago, # ^ |
      Rev. 2   Vote: I like it +2 Vote: I do not like it

      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.

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

D2 is truly interesting...Thanks for such problems

»
3 years ago, # |
  Vote: I like it 0 Vote: I do not like it

has anyone solved C using reverse edges and starting dfs from node n + 1? i just want to know if its a correct solution

»
3 years ago, # |
  Vote: I like it +27 Vote: I do not like it

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?

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

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.

»
3 years ago, # |
  Vote: I like it +6 Vote: I do not like it

arcaea www

»
3 years ago, # |
  Vote: I like it 0 Vote: I do not like it

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)

  • »
    »
    3 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    I imagine using Multinomial Theorem and Polynomial multiplication we can do that in $$$O(N*MlogM)$$$.

  • »
    »
    3 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

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

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

    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. #feelsbadman

    Edit: It passed systests: Submission 126025440 :D

    • »
      »
      »
      3 years ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      replying to find it later.

      p.s -> how to find a particular comment easily later ?

      • »
        »
        »
        »
        3 years ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

        There are those permalinks to comments (# symbol in the comment header, like https://mirror.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.

        • »
          »
          »
          »
          »
          3 years ago, # ^ |
            Vote: I like it 0 Vote: I do not like it

          I figure the api design. But how will I know the ID is of your comment lol.

    • »
      »
      »
      3 years ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

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

»
3 years ago, # |
  Vote: I like it +107 Vote: I do not like it
»
3 years ago, # |
Rev. 4   Vote: I like it +73 Vote: I do not like it

https://mirror.codeforces.com/contest/1559/submission/125941230 — sent at minute 8, evaluated at minute 10 https://mirror.codeforces.com/contest/1559/submission/125944849 — sent at minute 13, evaluated at minute 17 https://mirror.codeforces.com/contest/1559/submission/125939758 -> https://mirror.codeforces.com/contest/1559/submission/125946723 !! — sent at minute 6, evaluated at minute 8

my submission: https://mirror.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 :(

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

    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.

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

Thanks for the great round! :) I like problem D2 very much, it's the most interesting problem I've ever seen :)

»
3 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Can't I solve E with FFT or NTT?

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

    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

»
3 years ago, # |
  Vote: I like it +71 Vote: I do not like it
»
3 years ago, # |
Rev. 2   Vote: I like it +22 Vote: I do not like it

Now that's a contest (UPD: WOW FST on test 57)

»
3 years ago, # |
  Vote: I like it 0 Vote: I do not like it

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?

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

    Yes, if a[n] == 0 you can just travel from 1 to n+1

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

    There is no first kind of edge between n and n+1.

»
3 years ago, # |
  Vote: I like it +11 Vote: I do not like it

Nice round. loved it.

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

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.

  • »
    »
    3 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    it is because system testing is not yet finished.

    • »
      »
      »
      3 years ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      But solutions which are in testing show in queue but my both solution is showing WA

      • »
        »
        »
        »
        3 years ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

        It's typical of the system to show that, wait and it will turn back.

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

          testing completed and I got one AC and one WA (even after getting pretest passed(3) )

»
3 years ago, # |
  Vote: I like it +9 Vote: I do not like it

After solving A-D1, I got nothing to do.

»
3 years ago, # |
  Vote: I like it +16 Vote: I do not like it

Nice problems guys. Good team work!

»
3 years ago, # |
  Vote: I like it +45 Vote: I do not like it

  • »
    »
    3 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    lol. But it was easy. I just guessed the answer without even understanding why it works.

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

It's a good contest.

But I have a question:

Could anyone hack my code(D2): https://codeforces.ml/contest/1559/submission/126013197

Maybe it's easy to hack...

upd:hacked by peti1234

  • »
    »
    3 years ago, # ^ |
    Rev. 2   Vote: I like it +8 Vote: I do not like it

    Unexpected verdict. I don't know what to do with this.

    UPD: Hacked

»
3 years ago, # |
  Vote: I like it +1 Vote: I do not like it

i bricked this contest can i hvae some contrubtion points

»
3 years ago, # |
  Vote: I like it +25 Vote: I do not like it

It's a nice contest in general.But I should say that the difficulty between ABCD1 and D2E is like a cliff

»
3 years ago, # |
  Vote: I like it +17 Vote: I do not like it

ranran(Diana) you take me away!

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

    jiaxintang pi dou mei you yong !

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

      wo men jia xin tang xiang yao zheng fa yi ge ding wan ren hai shi hen rong yi de!

»
3 years ago, # |
Rev. 2   Vote: I like it -16 Vote: I do not like it

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 ?!!

»
3 years ago, # |
  Vote: I like it +6 Vote: I do not like it

editorial?

»
3 years ago, # |
  Vote: I like it +74 Vote: I do not like it

To not keep you waiting, the ratings are updated preliminarily. In a few hours/days, I will remove cheaters and update the ratings again!

  • »
    »
    3 years ago, # ^ |
    Rev. 2   Vote: I like it 0 Vote: I do not like it

    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.

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

      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.

      • »
        »
        »
        »
        3 years ago, # ^ |
          Vote: I like it -20 Vote: I do not like it

        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.

        • »
          »
          »
          »
          »
          3 years ago, # ^ |
            Vote: I like it 0 Vote: I do not like it

          You should still give contests rated for Div. 2 and everyone, it's a great opportunity to practice your competitive programming skills.

»
3 years ago, # |
  Vote: I like it +2 Vote: I do not like it

Succeed!I am not a newbie now.

»
3 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Great Round, thanks!

»
3 years ago, # |
  Vote: I like it -10 Vote: I do not like it

Thanks for the great contest. But unfortunately I got negative delta again :(

»
3 years ago, # |
  Vote: I like it +6 Vote: I do not like it

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?

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

    I think it's reasonable that two submissions is almost the same in a div2.B.

»
3 years ago, # |
  Vote: I like it +11 Vote: I do not like it

MikeMirzayanov I've got a message that the following solutions coincide: SunTakesTooLongToDie/125962649, Tony1234_/125963558

The code is obviously taken from this blog

»
3 years ago, # |
  Vote: I like it 0 Vote: I do not like it

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!

»
3 years ago, # |
  Vote: I like it 0 Vote: I do not like it

In the official standings how did rank 296 got 100+ delta while CMs above him with lower rating got lesser delta