diskoteka's blog

By diskoteka, 16 months ago, translation, In English

1848A - Vika and Her Friends

Idea: diskoteka

Tutorial
Solution

1848B - Vika and the Bridge

Idea: diskoteka

Tutorial
Solution

1848C - Vika and Price Tags

Idea: pavlekn

Tutorial
Solution

1848D - Vika and Bonuses

Idea: diskoteka

Tutorial
Solution

1848E - Vika and Stone Skipping

Idea: diskoteka

Tutorial
Solution

1848F - Vika and Wiki

Idea: pavlekn

Tutorial
Solution
  • Vote: I like it
  • +149
  • Vote: I do not like it

| Write comment?
»
16 months ago, # |
  Vote: I like it +52 Vote: I do not like it

A,C,D and E are just math problems. Cf should do better.

»
16 months ago, # |
  Vote: I like it +106 Vote: I do not like it

Problem statements were too long.

»
16 months ago, # |
  Vote: I like it +9 Vote: I do not like it

look at As editorial :0

»
16 months ago, # |
  Vote: I like it +21 Vote: I do not like it

I agree with the general mood that A-C of the contest were too hard. D-F were okay, although in E $$$M$$$ should have been set larger than $$$O(Q \log x)$$$ to prevent the edge case where one of the prime powers reaches $$$M$$$.

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

    Why should setters prevent corner cases instead of contestants preventing them in their code?

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

      This is a Div 2 codeforces contest. Because this is Div 2 where the contestants aren't necessarily that strong, and because this is codeforces where the pace of the competition is very fast, it should be more about solving the problem than implementation and avoiding corner cases.

      Also, it looks like the authors made the same mistake, hence the explanation that Test Case 15 (the first case with that corner case) was incorrect and the solutions had to be rejudged.

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

        This is a Div 1.5 contest, so include purples in your thesis. "not strong div2 participants" wouldn't reach E anyway.

        Btw my opinion on this problem is: why the fuck is it variable mod? Why not just use constant mod 1e9 + 7? It seems some coordinators or setters are addicted to using variable mod for no reason other than worsening the runtime of people's solutions.

        I didn't know about test case 15, that slipping by testing is a big oof.

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

          There are problems where variable mod is needed, in particular the problems where there are limited amount of parameters and it's possible to locally compute all the possible answers with a slower code then submit the result.

          I agree that for this problem there is no such reason and a constant 1e9+7 is better.

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

          Div2 contestant also should have rights to solve E with certain wisdom ,instead of getting cornered by this kind of modulo trick. In fact that’s almost irrelevant to the main idea of this problem, which i think is conducting the numbers of factors (forgive my terrible English)

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

      well, stupid edge cases are no fun (the original problem when i tested had a constant mod > 1e9)

      also, the setters themsevles got the case wrong....

»
16 months ago, # |
  Vote: I like it +2 Vote: I do not like it

I liked A and B, even though the latter was mostly implementation. C and D were too mathy and guessable though.

»
16 months ago, # |
  Vote: I like it +13 Vote: I do not like it

problem statement of A was pretty confusing for me.

»
16 months ago, # |
  Vote: I like it +15 Vote: I do not like it

There exists an $$$O(n)$$$ solution for problem C, which is better than the editorial's $$$O(n\log a_i)$$$:

Submission

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

    Can you explain your solution, i read but i can't understand

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

      I can't prove it, but it's correct:)

      The first few steps are the same as editorial. On finding out how to calculate $$$(a,b)$$$'s answer, write a brute force first. Then u can notice the patterns the same in my code:P

      If someone can prove it I'll be very grateful.

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

        Actually it the same as second solution of editorial: "Thus, we can determine the remainder cnt modulo 3 by looking at the pair (a/d, b/d) modulo 2".

        Let a = 2**g * ra, b = 2**h * rb

        ra, rb — odd numbers.

        If g > h, then:

        a / gcd(a, b) = 2**(g — h) * (ra / gcd(ra, rb)) — even number

        b / gcd(a, b) = (rb / gcd(ra, rb)) — odd number

        In case g < h, first will be odd, second even.

        In case g == h, both are odd.

  • »
    »
    16 months ago, # ^ |
      Vote: I like it -31 Vote: I do not like it

    This is O(n log(n)) Only to calculate the number of trailing zeroes it takes log(n) times only.

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

      Hi, __builtin_ctz() is an inbuilt function of G++ that only have $$$O(1)$$$ complexity as far as I know. Correct me if not:)

      • »
        »
        »
        »
        16 months ago, # ^ |
          Vote: I like it -23 Vote: I do not like it

        https://codeforces.me/blog/entry/59268

        Though it does the bitwise calculation, it is too fast to get noticed, but the complexity is still O(log(n)). You can verify this by manually writing the code for it, and you will see that it takes the same time.

        Click on compare the previous solution in the below submission.

        https://codeforces.me/contest/1848/submission/214137912

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

          I can't really agree. It seems on my local machine that __builtin_ctz(x) is at least 30 times faster than the handwritten one. as the handwritten one has the complexity of $$$O(\log n)$$$, I would say that __builtin_ctz(x) has to be something like $$$O(1)$$$.

          Here's my code and results:

          Test 1:

          __builtin_ctz() running 1e7 times, 0.02 s on average
          handwritten __builtin_ctz in your previous submission running 1e7 times, 0.6s on average

          Test2:

          change the lim in the first code to $$$10^8$$$, and it runs 0.2 s on average; change the lim in the second one to $$$10^8$$$, and it runs 6.1 s on average.

          What do u think about that?

          upd: i did another test, i changed the get(x) to:

          int get(int x)
          {
              return 2*x;
          }
          

          and $$$lim$$$ is still $$$10^8$$$. the average time is 0.24s! That means the inbuilt function of g++ seems to be even faster than adding two numbers together! What's ur opinion?

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

            theoretically, it is still n log n but practically it is O(n)

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

              idk how __builtin_ctz() is implemented,but i still think its real complexity should be real close to $$$O(n)$$$.

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

                Godbolt says there's special "bsf" assembler instruction for it.

        • »
          »
          »
          »
          »
          16 months ago, # ^ |
            Vote: I like it -22 Vote: I do not like it

          Stop posting misleading content you are discussing popcount but ctz only needs x&-x

          and popcount isn't O(log n) too it's O(log w) like O(log log n).

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

    how did you arrive at the intuition of using 2 highest power in solving it.

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

      I'm stupid, I don't have intuition, I write brute force, I observe patterns, I draw conclusions, I implement, I pass

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

        What was the logic in your brute force code that showed some pattern?

»
16 months ago, # |
  Vote: I like it +27 Vote: I do not like it

This contest problem statements are too long like a reading comprehension.

I think C is more difficult than D

May be I'm too foolish , but what is the tutorial of C's meaning???

»
16 months ago, # |
  Vote: I like it +11 Vote: I do not like it

Personally I don't think problem A is too hard for its position. The idea is fairly common in game theory puzzles like https://www.youtube.com/watch?v=dh4nEuhZBgg and just requires a bit of good intuition.

»
16 months ago, # |
  Vote: I like it +69 Vote: I do not like it

diskoteka [user:pavlovn]

My thoughts on this round:

The problems themselves were fine.

I do think A was not suitable to be a div2A, but that’s because I think div2A’s should be “submitbait”. The problem itself was fine, and may have done better as div2B.

Perhaps D was too math-y than ideal, but that’s fine.

Perhaps E could’ve had $$$M \geq 10^8$$$ or have been fixed, but it wasn’t much extra (and it is not too hard to generalize to all $$$M$$$). It is bad that the sequence is on OEIS though, so ideally this problem shouldn’t have been used.

Also, don’t listen to the haters, and please keep setting contests. Over time you’ll get better, and this contest probably provided good feedback!

»
16 months ago, # |
  Vote: I like it -20 Vote: I do not like it

C was a beautiful problem!

»
16 months ago, # |
  Vote: I like it +32 Vote: I do not like it

Your tutorial for problem D should write (b+20x)(a-4x), not (b+20x)(a-x) in the 4th paragraph, as reflected in your code.

»
16 months ago, # |
  Vote: I like it +35 Vote: I do not like it

Easier for F is just doing binary lifting as soon as you know the power of 2 thing. It's basically the same solution but O(NlogN) and you don't have to think about reducing it to an array of size N/2.

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

For problem A, vika's friends can see her(vika) right? So they see her and try to modify their movement right? Can vika see her friends as well?

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

    If we color the rooms like a chessboard, and at least one of her friends starts on the same color as her, that friend has the strategy, and can react to her movement(because she moves first) in such a way that no matter what she does, she eventually will be caught, this is explained in the editorial. So, whether Vika tries to avoid her friends or not, it doesn't matter.

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

please explain me this(Problem A):

1 2 1

1 1

1 2

I think when vita goes to right , friend will catch him . Perhaps, i misunderstood something.

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

    both vika and her friend should perform a move .So they're just going to swap rooms forever and never meet each other.

    a friend catches vika only if they find themselves in the same room after performing the move

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

      During contest, I understood from statement so:

      First vika goes, then her friend.

      Thanks

»
16 months ago, # |
  Vote: I like it -103 Vote: I do not like it

This is the WORSR contest i've ever seen. Can you just stop writing such long description of problems?? If you want to show your ability of writing, you don't need codeforces. And problems DEF are so easy to think, the difficulty is too low to be the div2 DEF, it can be used in div3. The quality of the problems are also too low I think. And the awful test cases of problem E, can you just check your test cases before the contest? To my surprise, this contest has not been unrated, but I don't want to see such contest like this anymore. YOU DO NOT NEED TO CREATE THE CONTEST IF YOU DO NOT HAVE THE ABILITY OR YOU DO NOT WANT TO DO IT WELL!!!

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

when problem A has the longest tutorial, you know you did something wrong.

»
16 months ago, # |
  Vote: I like it +7 Vote: I do not like it

wthforces

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

I don't get why so much hate for this round. A is better than normal, I liked problem C quite a bit, and rest of problems were fine. (yet another round with no datastructure tho ;-;)

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

    You could've used a segment tree in order to avoid the corner case in E lol

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

      I wonder why they even used prime mod. Either used fixed or force this....

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

    Problem — A was quite lengthy from a beginner perspective and difficult to prove.
    Otherwise the rest of the contest (I mean A-D, I haven't read E and F) was fine.
    (I struggled a little bit to decipher the language in A (and B for that matter) The story of friends catching "Vika" but having a greater affinity to make a move seems inconsistent and looks like a bad attempt to make the problem look real worldish when it isn't).

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

      I agree A could've been worded better, but I don't think it's bad enough to greatly worsen round.

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

Sorry ,but I feel A lengthy and language is very tricky

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

In solution1 of problem C , it will be ai-4*bi in place of ai-4ai

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

can someone explain me the problem statement of B in easy way.. i have read it multiple times but i am not able to understand

thanks..

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

    vika can paint any particular plank of her choice. you have to figure out which one so that she has to step over minimum number of plank

    condition is that she will be jumping on only same color planks.

»
16 months ago, # |
  Vote: I like it +9 Vote: I do not like it

Problem A was way too unbalanced for its position and difficulty range. Its not a great idea for begineers

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

in task B, isnt it necessary to mention in the problem statement that k distinct colourst will definitely be present.

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

My solution for A :
So we need to check for every position (i,j) in n*m grid, if there is a position where both main person and anyone among the k people have the same distance to (i,j). So we iterate over every position and check whether the distance of main person is same as distance of any of k friends to that position. TC : O(n*m*k).
AC code : 214108505

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

After reading editorial for problem A, do you still feel like this is DIV-2 A problem ?

diskoteka

Only in Vika-land, problem would need this much logical thinking and proof for problem A solution.

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

    I think, by considering it as a problem that could be solved by brute force thus being easy to implement, it's a good Div 2A.

»
16 months ago, # |
  Vote: I like it +15 Vote: I do not like it

Because of problems like A, people start to hate math in cf-contests. The problem would be great if it were at the math contest, but not at cf.

»
16 months ago, # |
  Vote: I like it +57 Vote: I do not like it

Personally, I loved this round! I only solved ABCD, but this round had better problems than most recent Div2s in my opinion. I don't understand why the announcement blog post was downvoted. Keep making rounds!

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

ive done other coding contests but this was my first cf contest and i solved 0 questions, so skill issue for me ig

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

In problem C, I have a different way of finding the $$$cnt_i\% 3$$$ mentioned in the editorial.

Similar to solution 2, we will build the sequence from the end. It will be of the following form:

$$$... x, x/2, x/2, 0 ...$$$

Now try to build a tree of all possible values before $$$x$$$. You will notice values in a particular level are either of the type $$$odd * x / 2$$$ or $$$k * x$$$ where $$$k$$$ is a positive integer. You will also notice that $$$k * x$$$ has a period of $$$3$$$, same as the period of $$$0$$$.

So the problem reduces to finding which of the $$$a_i, b_i, c_i$$$ is of the type $$$k * x$$$.

Here's my submission.

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

    i am still not able to understand your approach, can you explain in more simple way. thanks.

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

      Think of the first time $$$a_i$$$ becomes zero. It will be of the following form:

      $$$...k, k, 0...$$$

      What would come before $$$k$$$? Let it be $$$y$$$, solving $$$|y - k| = k$$$ we would get $$$y = 2*k$$$. So the sequence now becomes

      $$$... 2*k, k, k, 0 ...$$$

      Similarly, try to find what would come before $$$2*k$$$. From here, multiple values might be possible for each position. For example, before $$$2*k$$$, both $$$3*k$$$ and $$$k$$$ are possible values.

      Try to draw a tree of these values. $$$2*k$$$ will be the root and $$$3*k$$$ and $$$k$$$ are its children. It will be something like this: https://binary-tree-builder.netlify.app/?indextree=2*k,3*k,k,5*k,k,3*k,null,8*k,2*k,4*k,null,4*k,2*k.

      In this tree, at each level, the values are either of the type $$$even*k$$$ or $$$odd*k$$$. You will also notice $$$even*k$$$ has a period of $$$3$$$, just like the period of $$$0$$$.

      Now consider a situation where $$$a_1 = even*k$$$ and $$$a_2 = odd*k$$$. Then we know that both $$$a_1$$$ and $$$a_2$$$ won't become $$$0$$$ at the same time.

      So we need all $$$a_i$$$ to be $$$even*k$$$ or all $$$b_i$$$ to be $$$even*k$$$ or all $$$c_i$$$ to be $$$even*k$$$. Only then we will get all zeroes at the same time.

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

        The best explanation I found so far. But why (all ai or all bi or all ci) need to even*k. why not just check if all ci are even*k only? why we have to check ai and bi too?

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

          We might have something like this:

          $$$a = [odd*k_1, even*k_2, odd*k_3, ...]$$$
          $$$b = [even*k_1, odd*k_2, even*k_3, ...]$$$
          $$$c = [odd*k_1, odd*k_2, odd*k_3, ...]$$$

          As you can see, this will not result in all zeroes occurring at the same time.

          Now consider the following:

          $$$a = [odd*k_1, odd*k_2, odd*k_3, ...]$$$
          $$$b = [even*k_1, even*k_2, even*k_3, ...]$$$
          $$$c = [odd*k_1, odd*k_2, odd*k_3, ...]$$$

          This will result in all zeroes occurring at the same time. So its important that you check all $a_i$, $$$b_i$$$, $$$c_i$$$.

»
16 months ago, # |
  Vote: I like it +2 Vote: I do not like it

diskoteka, in the editorial of C, while writing Solution 1: I believe where you wrote

(ai, bi, ai — bi, ai — 2 * bi, ai — 3 * bi, ai - 4 * ai)

(and should have written: ai - 4 * bi)

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

Thank you diskoteka for great math problems, better than previous div(1,2) speedforces

»
16 months ago, # |
  Vote: I like it +36 Vote: I do not like it

E and F are well known math problems.

E: 2016 AMC 12B P16

F: Trivial special case of 2023 USA TSTST P9

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

It has been pointed out to me that the setup for F is actually identical to USA TSTST 2023/9 with $$$p^e=2$$$, although I’m not sure how much knowing the solution to the TSTST problem helps with the codeforces and vice versa. At the very least, one of the solutions to the TSTST problem proves that you will never print $$$-1$$$ (see the first claim in post #5 by a familiar-looking user).

Edit: sniped by the person who pointed this out lol

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

    The first part of the TSTST problem tells you what the operation becomes after applying it $$$2^i$$$ times.

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

      Oh true—the explicit computation of the $$$k$$$-th finite difference implies that for $$$k=2^i$$$, we have $$$\Delta^{2^i} f(n) \equiv f(n+2^i)+f(n) \pmod{2}$$$, since by Kummer's theorem/Legendre $$$\binom{2^i}{a}$$$ is even unless $$$a \in {0,2^i}$$$, which more or less reduces this problem to a straightforward binary search

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

Great round! Like these problems very much :3

We've found some alt ways to solve F, but they have higher time complexity.

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

A is too hard...

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

I think problem A is harder than problem B.

»
16 months ago, # |
  Vote: I like it -18 Vote: I do not like it

Different Approach For Problem C. Code

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

    Can you explain how it works, like why does the highest power of 2 matters?

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

Then, if the cycle is "scroll" x times, the discount will be (b+20x)(a-x)

WHY NOT (b+20x)(a-4x)?

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

In C, I tried to find the number of operations to make ai zero manually in the hope of getting some pattern or some formula but all in vain. May be they should try not to give such mathematical things till C.

C is one of those problems which gives neither the pleasure when I solve them nor guilt when I could not.

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

Can someone break down C for me, I observed a few things during the contest.

Let a>b for all below expressions, if not we can just move to the next stage where b and |a-b| will fit the scenario(moving one parity ahead).

Every pair will eventually reach a loop of GCD(a,b), GCD(a,b), 0. So essentially we needed to check if every pair have the same parity (%3 values of the number of steps they reach 0). I also noted that we can go from a,b to a%b,b keeping the same parity, except for when (a/b ==1). And that is where it stopped for me.

I saw some people use a%2b to move a parity ahead, but where does that 2 come from?

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

    I'll use pair notion meaning $$$(a, b)$$$ pair becomes $$$(b, |a - b|)$$$.

    Consider some large $$$y$$$ and small $$$x$$$: $$$(x, y) \Rightarrow (y, y - x) \Rightarrow (y - x, x) \Rightarrow (x, y - 2x)$$$.

    We made 3 operations meaning it wont change amount operations modulo 3, therefore you need to find largest $$$k$$$ i.e. amount of operations that: $$$0 <= y - k(2x) < 2x$$$ which is literally a definition of remainder.

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

      can u prove doing this way + perform the said operation will not be more than logarithmic

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

        I don't understand why do you need to prove this fact since it's literally gcd-like + you literally can implement it and test on big random numbers but here you are:

        Since operation in pairs are not simmetrical you can't assume WLOG $$$x \leq y$$$ so I'll let you do $$$x > y$$$ by yourself ;)

        So I'll be doing $$$x \leq y$$$ case:

        Now consider two cases:

        1. $$$4x \geq y$$$, then pair $$$(x, y)$$$ becomes $$$(y, y - x)$$$ where $$$y - x \leq \frac{3y}{4}$$$, $$$(y, y - x) \Rightarrow (y - x, x) \Rightarrow (x, y - 2x)$$$. Congrats! we have reduced second term by at least 3 quarters, since $$$y - x \leq \frac{3y}{4} \Rightarrow |y - 2x| \leq \frac{3y}{4}$$$

        2. $$$4x \leq y$$$, then $$$(x, y)$$$ becomes $$$(x, y \ \% (2x))$$$. Congrats! we reduced second term by at least half

        This yields next conclusion: rough estimate for upper bound of steps is $$$3*log_{4/3}(y)$$$ which is good enough. The rest of the proof is up to you

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

Typo in d editorial:

$$$(b+20x)*(a-4x)$$$

»
16 months ago, # |
  Vote: I like it +6 Vote: I do not like it

I found a very interesting pattern for problem C. For every i, we count number of trailing zeroes in binary representation of A[i] and B[i], now if A[i] has more, then this pair can be made 'dull' in 3k steps, if B[i] has more, then 3k+1 steps, and if they both have equal trailing zeroes, then 3k+2 steps. And we just have to ignore A[i]=B[i]=0 case.

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

Can someone provide me with clear insights on Problem C? Or provide resources to learn the topic. It is clear to me that the only thing that matters is the modulo 3 of the first occurrence of zero for each position of the array. But I find the tutorial very confusing on how to proceed further (maybe I am missing some number theory / modular arithmetic prerequisites)?

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

    Consider several cases of a[i] and b[i]. Such as:

    1. Both are odd. [O,O]

      • Then the first difference ($$$O-O = E$$$) will be an even number. [O,E]
      • second difference ($$$O-E = O$$$) will be an odd number. [E,O]
      • third difference will be an odd number. [O,O]
      • Now, we know that the sum of the numbers keeps reducing and one of them reaches $$$0$$$ eventually.
      • So at what parity can a[i] = 0 occur from above observations?
      • Ans: At all "second differences" , because zero is even
    2. Similarly analyse cases of [O,E] and [E,O]

    3. The case of [E,E] is interesting. You can observe that they will mimic the behave of the numbers we obtain by doing successive division by 2.

      • Eg: [4,6] will mimic the behaviour of [2,3].
      • So case 3 can be collapsed into cases 2 and 1.

    You know the story after this.

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

Did everyone lose rating? Half of the people must have gained acc to algo

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

I didn't understand the solution explained for problem C. Can someone explain it clearly.

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

Who can explain the tasks C, D? I didn't understand the author's decision at all

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

    problem C:

    Hint1
    Hint2
    Tutorial
    • »
      »
      »
      16 months ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      how to prove complexity of urs code is log

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

        It's similiar to the complexity of GCD and that's log.

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

          But that we can prove .Here (a,b) where a>=2*b or b>=2*a remains in the same state for more times.Its not exactly same .from this state to say them same is not reasonable

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

            Assume that a>=2*b.(if 2*b>a>=b , My code do the same thing as GCD)

            GCD : (a,b) → (b,a%b) , 1 step makes the biggest num decrease from a to b.

            Mycode :(a,b) → (a%(2*b),b).

            I. 0< a%(2*b) < b. 1 step too , same as GCD.

            II. b<= a%(2*b) <2*b . Then we go the second step: (a%(2*b),b) → (b,a%(2*b)-b). 2 steps makes the biggest num decrease from a to b.

            so Mycode's complexity is no more than twice of GCD's . That's log.

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

              (a,b)

              three cases :

              1) a>=2*b

              2) 2*b>a>=b

              3) a<b

              fourth thing each state will be one of three

              first case u proved in 1 or 2 steps will be same as (b,a%b)

              second case u also proved in 1 step can get to (b,a%b)

              third case can be reduced to (b,b-a) one of case 1 or 2(can take 3 steps)

              a %b==a-b only if 2*b>a>=b

              VERY WELL DONE

              here is my implementation of the same approch (not even a single change ) https://codeforces.me/contest/1848/submission/214252557

              • »
                »
                »
                »
                »
                »
                »
                »
                16 months ago, # ^ |
                Rev. 2   Vote: I like it -16 Vote: I do not like it

                if wanted its complexity can also be O(2*logn) or O(3*logn) -complexity at the heart

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

      thank you very much!

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

      Hey man, how were you specifically able to come up with the a >= 2 * b condition. Can you please explain your thought process behind it?

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

The tutorial is clear.

»
16 months ago, # |
  Vote: I like it -10 Vote: I do not like it

WTF you haven't said that sum of Ks over all test cases is at most 200000 in B!

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

Is the kind of reasoning used in problem E familiar to high-rated coders? Looking at the tutorial, I don't see any way I could have solved the problem on my own, so I want to know if people who solved it are well-versed with such kinds of reasoning or if it came to them naturally.

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

Can someone please explain what does area to Vika mean? Is it something other that the number of blocks between Vika and one of her friends?

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

Simpler Solution for A:

  1. Every move, the parity of R+C changes by 1 for both Vika and her friends. Therefore, a friend can catch up to Vika if and only if the sums of their coordinates have the same parity.

  2. Because the friend moves after Vika, she can always decrease the distance between the two of them. By contrast, Vika can only increase distance by moving in the same direction as the gap between her and her friend (e.g. if Vika is three units to the right of her friend, she can only decrease horizontal distance by moving to the right). Because the map is finite, Vika will be forced to decrease the distance between her and her friend after a maximum of R+C moves, and so she will eventually be captured.

  • »
    »
    16 months ago, # ^ |
      Vote: I like it -8 Vote: I do not like it

    Nice .In both dimensions the distance cannot remain same .just follow vika steps .he will be caugth

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

Problem E Observation: # of odd divisors = # of distinct initial f can also be proved in the following manner:

  • Consider all the pairs of [l,r] such that $$${\sum_{i = l}^r i = x}$$$

  • We are sure the the lengths len of all these segments have to distinct

  • So we need to find what all valid lengths are there. We have the following formula

$$$x = len \cdot ((len+1) / 2) + len \cdot k$$$
  • Consider one of the case where len is even. The case when len is odd is similar to prove.
  • let len = 2p and p>=1
$$$x \equiv len \cdot ((len+1) / 2) \pmod{ len }$$$
$$$x \equiv p \cdot (2 \cdot p + 1) \pmod{ 2 \cdot p }$$$
$$$x \equiv ((2 \cdot p) \cdot p) + p \pmod{ 2 \cdot p }$$$
$$$x \equiv p \pmod{ 2 \cdot p }$$$
$$$x = (2 \cdot t + 1) \cdot p $$$
»
16 months ago, # |
  Vote: I like it 0 Vote: I do not like it

where did the formula (b+20x)(a-x) in D come from?

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

    In any case, except for 5 and 0, the last digits will start following the pattern of 2,4,6,8 after a certain point. so we can make the formula as for not taking a discount 4 times we will have an increase in b by 20(2+4+6+8) and a decrease in the number of purchases left by 4.

    if we do this process x times then the discount i can get is (b+20*x)*(a-4x).

    and the formula in the editorial is partially wrong(missed 4*x).

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

I have created video editorial for problem A,B and C in english link. If you understand it, upvote.

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

Can anyone please give me a more intuitive idea of the induction of problem F? I mean how can we see it happen beside trying to prove the equation?

»
16 months ago, # |
  Vote: I like it +11 Vote: I do not like it

Maybe there is something wrong with problem A statement. What will happen when $$$n=1,m=1$$$?

In this case none of the girls can move to the neighbouring rooms, which violates your statement.

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

Finding $$$cnt_i\%3$$$ in problem C is not that hard I think.

$$$[a,b]$$$ will change like this $$$[odd,odd] \to [odd,even] \to [even,odd] \to [odd,odd] \to ... $$$

And $$$a$$$ can be $$$0$$$ in only $$$[even,odd]$$$.

(of course if both number is $$$0$$$ a is always $$$0$$$ and otherwise we can divide numbers by $$$gcd(a,b)$$$ so we can remove $$$[even,even]$$$ case)

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

Can anyone share there solution for D using ternary search. Mine is failing. My solution for D

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

In Problem D why are we only subtracting 1 from k after every iteration, shouldn't we take into account the fact that we are performing 4 * x number of operations and adjust k accordingly?

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

cf should do better

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

A can be done through brute force too , just go to each cell , if distance from vika's starting cell == distance from any of her friend's cell , then vika can't escape

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

great contest, do consider making more contests please. [user:diskoteka][user:pavlekn]

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

I spent quite a long time upsolving C in coming up with the formulas to accelerate the procedure when $$$a>b$$$... I have no knowledge of gcd algorithms... how can it make the problem easier?

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

Alternative solution to F using SOS DP:

Notice that the value of $$$a_0$$$ after $$$k$$$ operations is the xor of all $$$a_i$$$ such that $$$\binom{k}{i}$$$ is odd.

Why?

Lucas's theorem states that $$$\binom{p}{q}$$$ is odd if and only if $$$q$$$ is a submask of $$$p$$$. Thus, the value of $$$a_0$$$ after $$$k$$$ operations is the xor of all $$$a_i$$$ such that $$$i$$$ is a submask of $$$k$$$. This can be computed in $$$O(n \log n)$$$ using SOS DP. We know that after $$$n$$$ operations all $$$a_i$$$ become zero, so the answer is the first moment that $$$a_0$$$ becomes zero and stays zero.

Submission

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

    Yeah this was the solution I found (admittedly I didn't realize its truth was due to Lucas's Theorem). Let to a very beautiful implementation :)

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

F: Could the answer be -1? Why?

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

    3 2 2 0

    at this testcase isn't it -1?

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

I'm wondering how is one suppossed to come up with a proof such as one presented in tutorial E (or even think of proving the idea that number of odd divisors affects the answer)? Is that even Div2E level? The ideas used in the proof such as considering the parity of $$$cnt$$$ seem so random to me. I'd be grateful if any math gods would explain to me how to think about such problems or if you would show me more intuitive proof than the one in tutorial.

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

nvm