MLA19's blog

By MLA19, 8 months ago, In English

Hello, Codeforces!

Sorry for the late editorial. Our national olympiad just finished and we were sorting everything out.

We also apologize for weak tests on D that made an incorrect solution pass. Many testers submitted the same solution and we mistakenly thought that it was correct given the low bound on the number of batteries. Still, we hope that the contest was a fun and valuable experience for all contestants.

The editorial was prepared by efishel and me. If you have any questions about the problems or the solutions, please ask in the comments.

2155A - El fucho

Hint 1
Solution 1
Code (C++)
Solution 2
Code (C++)

2155B - Abraham's Great Escape

Hint 1
Hint 2
Solution
Code (Python)

2155C - The Ancient Wizards' Capes

Hint 1
Hint 2
Solution
Code (Python)

2155D - Batteries

Hint 1
Hint 2
Solution
Code

2155E - Mimo & Yuyu

Hint 1
Hint 2
Solution
Code

2155F - Juan's Colorful Tree

Hint 1
Hint 2
Hint 3
Hint 4
Solution
Code
  • Vote: I like it
  • +58
  • Vote: I do not like it

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

Bricked D couldn't observe that. Good contest Nice problems. C is Nice

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

MLA19 In problem D, what about the state of batteries not being constant. The batteries that were working in the beginning, do they always work and rest change ??

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

    The positions of the batteries that work can change during the interaction. It might be more intuitive to think of the problem as "prove that $$$\left \lfloor \frac{n}{a} \right \rfloor$$$ trials are always enough to find a pair of working batteries without any sort of luck involved". That is, we are working with the worst case possible in a sense (in which we don't guess a pair we want on the first try by pure luck, for example).

    The interactor guarantees that the underlying configuration of working batteries is consistent with the queries at every single step, so you could also think of it as interacting with the final configuration all along (to which the analysis in the editorial obviously applies).

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

      Appreciate the reply.

      But isn't it always possible to keep moving the non-working battery, for example n=20, a=19. At every d=1...(n-1) where d is the distance at which we're checking, we can make the "i+d" as non-working and rest as working.

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

        Same doubt, please someone explain this

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

        No, it isn't, because the configuration of batteries has to be consistent with the information given at every step.

        In your example (n = 20, a = 19), we query batteries 1 and 2. If the interactor replies that they don't turn the flashlight on, then either 1 or 2 has to be the non-working battery. This fact has to remain true during the interaction.

        When we query 2 and 3, the interactor can make it so that battery 2 is the non-working battery (and so 2 and 3 don't turn the flashlight on). Notice that this is consistent with the information provided by the first query.

        Finally, when we query 3 and 4, the interactor is going to reply that those 2 batteries turn the flashlight on. The reason the non-working battery can't be moved to one of those positions is that it wouldn't be consistent with the first two queries, so those two batteries definitely work.

        I hope it's clearer now.

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

          Yes got it now, thanks!

          So technically The interactor is adaptive has no role here for us (except it guarantees we receive worse case scenario from interactor each time) as there exists a configuration of a working batteries that is consistent with the information that you have received so far.

          It's a really cool interactive problem in recent times :)

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

        No. If $$$d \gt 1$$$ and you followed the solution algo up to this point, you must have queried $$$(i, i+d-1)$$$ before. If $$$i+d$$$ was the only broken battery you already found a solution and wouldn't make this query anyway.

        If it helps, look at the hangman cheating strategy described in this video by jan Misali. From the player POV there was a some chosen word at the start. From the executioner POV though, they can swap the word at any time to be consistent with information they already gave and the player never knows the difference.

        The reason the interactor does this is to force you to have a worst-case solution. You'd expect random guesses to find a pair really quickly, so the interactor needs to simulate you being extremly unlucky while not cheating by contradicting some previous guess.

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

You can also use the grundy number logic to solve E. First for n > 1

Every cell in col 1 has grundy value 0

Every cell in col 2 has grundy value 1

Every cell in col 3 has grundy value 2

Every cell in col 4 has grundy value 4

...

Every cell in col m has grundy value 2^(m-2)

Now xoring 2^i and 2^j for different i,j would never give 0 So the game state will be 0 if and only if every col (except the 1st one) has even number of tokens. And in that case 2nd player will win.Otherwise, 1st player is the winner.

For n == 1 The grundy value for

Col 1 is 0

Col 2 is 1

Col 3 is 0

Col 4 is 0

...

Col m is 0

So we only need to check if the number of tokens in the col 2 is even or odd.

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

    How are we actually calculating the Grundy Value for Col2 as 1, Col3 as 2, Can you please explain once? Please do share any reference if possible

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

      Col 1 is losing state because you cant move anymore so the grundy is 0

      From col 2 you can only do 1 move that is to go to Col 1 so the grundy is MEX(grundy(col 1)) = 1

      From col 3 you can go to odd/even number of cell in Col 2 so you can go to both grundy = 0 state (even col2) or grundy = 1 state , So the grundy is MEX(0,1) = 2

      From col 4 you can go to odd/even number of cell in Col 3 then odd/even number of cell in Col 2 then col1 so you can go to every state with grundy 0 to 3 thus grundy = mex(0,1,2,3) = 1

      generalising this

      from Col i you can goto odd/even number of cell in Col (i — 1) then odd/even number of cell in Col (i — 2), .... then go to cell Col 1

      Thus you can reach any state with grundy (2^ (i — 3) or 0) + (2^ (i — 4) or 0) + ... (1 or 0) = every state from grundy 0 to (2 ^ (i — 2) — 1)

      So the grundy is mex (0 to (2 ^ (i — 2) — 1)) = 2 ^ (i — 2)

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

I really liked problem E very much

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

Can anyone help me understand why my code fails the last sample test case for problem C? Thanks!

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

    I assume you've read the editorial and that your code is an implementation of the explanation.

    Note that at the very end it says that you should check your constructed solutions. The reason why they might not be valid is that we aren't accounting for the information given by the first value in Harry's list. For both the constructions and the list given in the input, the differences between consecutive values will match, but this doesn't guarantee that their entries are equal.

    In the last sample test case, your code constructs a cape arrangement that produces the following list (if we simulate Harry's procedure): "2 1 1". This, of course, doesn't match the input "3 2 2", but notice that $$$2-1 = 3-2$$$ and that $$$1-1 = 2-2$$$.

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

    same

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

I think the tests of problem E may be a bit weak. See my submission 342673253

When $$$n = 1$$$, I simply simulate the process from the maximum column that contains tokens to column $$$1$$$ while updating tokens being held(not in column $$$1$$$) using std::map. See the code below:

Code

The time complexity of the process turns out to be $$$O(m\log m)$$$. After getting Accepted, I soon realized that the sum of $$$m$$$ is not guaranteed and it should get TLE. The last test seems to be $$$n = 1, m = 2\cdot10^5, k = 1$$$ and the only token is $$$(1, 1)$$$ for $$$t = 10^4$$$ testcases.

Can anyone tell me, if the tests are too weak or my code actually has the correct time complexity?

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

    I'm also a bit confused about how that code passes all tests... The process seems completely wrong, but it passes. In fact, the correct way to check if Mimo will win the game when $$$n = 1$$$ is to check whether mp[2] is odd. This conclusion has been mentioned here,

»
7 months ago, hide # |
 
Vote: I like it -11 Vote: I do not like it

Hello team,

I received a plagiarism warning for problem 2155C (submission: 342105783). I want to clarify that I solved the problem independently and did not share my code or copy from anyone else. If needed, I am happy to explain my detailed thought process and how my solution came about, and the solution i did on paper, because that is how I came up with the approach.

I fully understand the rules and will ensure even stricter isolation in future contests. Please review my case again; I assure you there was no intention of rule violation.

— Codishhh

»
7 months ago, hide # |
 
Vote: I like it -11 Vote: I do not like it

Hello team, Recently, I got a warning for problem B. I solved it completely on my own and can explain my approach if needed. I think this happened because of a similar approach or code structure. From next time, I will make sure to write code with a different template to avoid such coincidences.

»
7 months ago, hide # |
 
Vote: I like it -30 Vote: I do not like it

problem D is the worst problem i have ever seen. whoever made this problem never make problems ever again, pls. this is the dumbest shit i've ever seen in my 18 years of life. please find me one honest contestant who figured out the circle circumference bs and didn't just do a simple for loop in for loop without having a clue why it works lol.

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

    maybe solve C before crashing out over D lol. Also here ya go

    • »
      »
      »
      7 months ago, hide # ^ |
       
      Vote: I like it -11 Vote: I do not like it

      maybe consider that i didnt have the time to solve C and that D is still a dumb ass question. lmao the guy didn't even specify that he specifically noticed the circumference insight, and the question was specifically formulated to be done with that approach because hacking was not allowed (which in the exact same thread is proven to be possible) therefore making it a worthless algorithm for even the exact question given, hmm i wonder why? maybe because it's a dumb as fuck question that cannot be solved within the constraints and can be hacked whatever approach you choose? but i must be in the wrong, a higher rank has attacked. i will back down now in despair because we reside in a class society.

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

        The comment says "array is cyclic" which means the same thing as "elements are on the circumference of a circle". Quering pairs by distance on a cyclic array would pass the constraints even with better testcases. Yea weak tests suck but all they need to do is have $$$n \lt 25$$$ and non-cyclic solutions become correct

        btw I'm not replying after this I don't want to get stuck in a yt comment war

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

      he literally did a O(n^2) check and crossed his fingers this guy i cant

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

There is one more way to look at Problem E.

For n = 1, the number of operations is fixed, so we just need to check the parity of the total sum.

Otherwise:

1 → If a player selects a token from position (r, c), then he/she can either change or keep the same parity of the number of tokens in columns (1 to c - 1). However, the parity of the current column (c) will always get inverted (from even to odd or odd to even).

How ?

Since n > 2, it means the player can always make two moves in a column. To change the parity of a column, the player will pick only one row. To keep the parity the same, the player will choose two rows in that column.

2 → Now consider the case where all columns have an even number of tokens. Then, Player 1 makes a move by selecting a token from column c, which may change the parity of some previous columns (c₁, c₂, c₃, …, cₖ) where cₖ < c.

Next, Player 2 chooses a token from the same column c. After this move, the number of tokens in that column becomes even again, and the parity of all the previously changed columns (by Player 1’s move) will also be restored.

Thus, after every two moves (one by each player), all columns will have even parity again. Hence, Player 2 will always have a counter-move for Player 1, and Player 2 will always win in this case.

3 → Now consider the case where at least one column has an odd number of tokens. Let these columns be (c₁, c₂, …, cₖ) where c₁ < c₂ < … < cₖ < m.

In the first move, Player 1 will choose the last column having an odd number of tokens (cₖ). This move will make the parity of column cₖ even and will also flip the parity of all previous columns that had an odd number of tokens.

In this way, Player 1 makes all columns have an even number of tokens. From point (2), we know that in such a situation, Player 2 is in a losing position. Therefore, Player 1 will always win in this case.

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

didn't participate in contest but interesting problems. a nice way to do O(k) implementation for problem E is to replace the set in the solution with a single integer variable which keeps track of the number of columns with odd tokens.

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

Problem D has another solution by Divide and conquer:https://mirror.codeforces.com/contest/2155/submission/343548658

»
7 months ago, hide # |
 
Vote: I like it -8 Vote: I do not like it

Problem $$$D$$$ is a perfect example where the nested loop positioning of outer vs. inner loops makes a real difference.

If the outer loop is on the batteries, we may exhaust the search limit before finding the target pair. On the other hand, having the outer loop for the distance ensures that we find the target once the distance reaches $$$\lfloor{\frac{n}{a}}\rfloor$$$ even though we do not know $$$a$$$.

Nice problem.

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

Clean af implementation for C!!!

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

If anyone can answer in problem E 1 13 1 1 4

why is Yuyu winning ?

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

Problem E could've been one of my all-time favourite, if not for the case $$$n=1$$$. I got stuck for 15 minutes trying to count like an idiot lmao.

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

I think the 4th possibility in the editorial of C is stated wrong. it should be that i has cape to right and i+1 has cape to left ig

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

Problem F is a special case of 506D - Mr. Kitayuta's Colorful Graph. I wanted to point out that F is solvable by a fast enough 506D implementation, not just "being simmilar to 506D".