SanguineChameleon's blog

By SanguineChameleon, 17 months ago, In English

Sorry about problem H.

Thank you for understanding, and we hope you enjoyed the rest of the problems :D


2096A - Wonderful Sticks

Idea: SanguineChameleon

Step 1
Step 2
Step 3
Step 4
Step 5 (Optional)
Implementation

2096B - Wonderful Gloves

Idea: SanguineChameleon

Step 1
Step 2
Step 3
Step 4
Step 5
Step 6
Step 7
Implementation

2096C - Wonderful City

Idea: thenymphsofdelphi

Step 1
Step 2
Step 3
Step 4
Step 5
Step 6 (Optional)
Implementation

2096D - Wonderful Lightbulbs

Idea: thenymphsofdelphi

Step 1
Step 2
Step 3
Step 4
Step 5
Step 6
Step 7
Implementation

2096E - Wonderful Teddy Bears

Idea: SanguineChameleon

Step 1
Step 2
Step 3
Step 4
Step 5
Step 6
Step 7
Implementation

2096F - Wonderful Impostors

Idea: SanguineChameleon

Step 1
Step 2
Step 3
Step 4
Step 5
Step 6
Step 7

2096G - Wonderful Guessing Game

Idea: SanguineChameleon

Step 1
Step 2
Step 3
Step 4
Step 5
Step 6
Step 7

2096H - Wonderful XOR Problem

Idea: SanguineChameleon

Step 0
Step 1.1
Step 1.2
Step 1.3
Step 2.1
Step 2.2
Step 2.3
Step 2.4
Step 3.1
Step 3.2
Step 3.3
  • Vote: I like it
  • +242
  • Vote: I do not like it

| Write comment?
»
17 months ago, hide # |
 
Vote: I like it +6 Vote: I do not like it

Thanks for the fast tutorial!

»
17 months ago, hide # |
Rev. 3  
Vote: I like it -21 Vote: I do not like it

In problem D, Why can't we first fix the y and then find x? See 316293937. A vast majority of submitted solutions can be easily hacked by just mirroring the coordinates given in sample testcase 2 along the x = y line. Was the decision to disable hacks taken during the contest or before the contest?

Edit: Just woke up. Realized my mistake. I misread the question. We had to make a ladder shape, not a plus shape. I initially solved the problem using the flawed logic and it passed 2/4 sample testcases which led to this confusion.

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

why were hacks disabled for problem D?

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

Wow! Such a well written editorial(and fast). Thanks to everyone involved!

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

I wonder how did you verify your tests for problem D? Is the condition for validity just checking that the number of groups of (x + y) with odd number of elements is 1, and the number of groups of x with odd number of elements is 1? I think that there should be other conditions satisfied.

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

    I think they manually created tests, that's why hacks are disabled because they can't come with polynomial time solution, without the condition that it is indeed possible to get a point.

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

      Yes, that is the one of explanations. But I wonder, can't wrong solutions pass with these manually created tests? Although there is only answer for the task, the algorithm for reaching it may be flawed. I wonder did authors consider this?

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

        Although there is only answer for the task

        Because of this, there is no need to verify actual reachability. It just needs to trust that the main solution generated the correct and the only answer, and simply compare it to the participant's output.

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

          I mean that the participant's solution may be wrong, but it generates the same output as author's solution.

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

            If the output is the same as the author's solution, then by definition the solution is correct.

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

    Can't they do it backward? Get a treasure location and sequences of toggles.

»
17 months ago, hide # |
 
Vote: I like it +18 Vote: I do not like it

Was problem B's statement confusing for anybody else? I couldn't figure out if they meant pairs of different color for the left and right glove or same color gloves.

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

In problem E, why is it always possible to perform exactly $$$\left | \left \lfloor \frac{a}{2} \right \rfloor - b \right |$$$ operations so that the number of zeros on even positions equals $$$\left \lfloor \frac{a}{2} \right \rfloor $$$?

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

    While the array isn't sorted:

    • Always do an operation of type B or D if you can.
    • If you can't, you are in the state mentioned in step 4. Any 10 you choose to swap to 01 will decrease $$$|\lfloor a/2\rfloor -b|$$$ by one.
»
17 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

In the easier version of problem F where Alice doesn't ignore any queries, does this solution work?

For each bit from $$$2^0$$$ to $$$2^{\lfloor log_2 n \rfloor }$$$ , ask a query with all numbers from $$$1$$$ to $$$n$$$ which contain this bit. The order of the numbers in the query doesn't matter.

Then look at the set of queries that Alice responded with L or R to. These queries represent exactly the bits in her secret number. Thus, we know her secret number.

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

    Do you mean G? You need to ensure that the number of integers from $$$1$$$ to $$$n$$$ that you ask in each query ($$$k$$$) is even. Moreover, the number of queries that you use is $$$\lceil \log_2 n \rceil$$$, which is unoptimal.

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

      Yes, I meant G. Thanks for the answer -- I forgot that k has to be even and that you have to minimize the number of queries.

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

note to myself: one day i will solve b constantly

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

In problem H, in step 2.3, maybe $$$c = [\frac{r}{2^{p + 1}}]$$$?

»
17 months ago, hide # |
Rev. 5  
Vote: I like it +5 Vote: I do not like it

FOR D =>

We can think of the lights as functioning like an XOR operation. Every time we step on a coordinate, it toggles the light, changing its state from 0 to 1 or 1 to 0. If we step on the same coordinate again, it flips back. This behavior is like XOR, where applying the same value twice cancels it. If we observe the x-coordinates involved, they are of the form x, x, x+1, x+1. Using the XOR property (a ⊕ a = 0 and a ⊕ b ⊕ b = a), we can easily deduce the value of x by taking the XOR of all x-coordinates. This will cancel out the repeated values and give us the unique x.

However, we can’t directly apply the same logic to the y-coordinates because the XOR of y-values may not cancel out cleanly. But there’s a workaround — consider the values of x + y. These values follow a similar pattern: x + y, x + y, x + y + 1, x + y + 1. Again, the same XOR principle applies here. Taking the XOR of all x + y values will eliminate the repeated ones and leave us with the unique x + y.

Once we have both x and x + y, finding y becomes straightforward: simply subtract x from x + y, and you get y. This approach cleverly uses XOR properties and pattern recognition to deduce both coordinates, making it a neat and efficient solution to the problem.

I HOPE IT HELPS... MY SOLUTION — https://codeforces.me/contest/2096/submission/316257978

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

thanks for these creative problems

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

I am unable to grasp why horizontal and vertical operations can be solved independently in problem C. Can someone explain it in brief. Thanks in advance.

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

    Horizontal operations can never introduce or resolve a horizontal 'conflict'. Here a conflict is a pair (i, j) such that h[i][j-1] == h[i][j]. That's because they don't change the difference h[i][j-1] - h[i][j]. For all the same reasons, vertical operations can never introduce or resolve a vertical 'conflict'.

»
17 months ago, hide # |
 
Vote: I like it +100 Vote: I do not like it

Many people have said in the comments that in problem D, it is not possible to verify if the given set of points is actually achievable by a set of operations, and the authors seem to think so too given that hacks are disabled. However, I believe it's actually quite easy to prove that the condition is if and only if. Let's state the problem as follows (we'll switch to the $$$(x, x+y)$$$ coordinate system and remove the special point):

In one operation, we can flip the points $$$(x, y)$$$, $$$(x+1, y)$$$, $$$(x, y+1)$$$, and $$$(x+1, y+1)$$$. Given a set of points such that the frequency of every $$$x$$$-coordinate and $$$y$$$-coordinate is even, show that some set of operations can turn everything off.

Proof: By applying the operation on all points in the set $$$(x+i, y+j)$$$ with $$$0\leq i \lt w$$$ and $$$0\leq j \lt h$$$, we can use the operation to flip the corners of a rectangle $$$(x, y)$$$, $$$(x+w, y)$$$, $$$(x, y+h)$$$, $$$(x+w, y+h)$$$. While the set of points is nonempty, pick an arbitrary point $$$(x, y)$$$ in the set. Since all row and column frequencies are even, there must exist another point with the same $$$x$$$ value, and another point with the same $$$y$$$ value. We can flip the rectangle with these points as corners. Each step reduces the number of points by at least $$$2$$$, so we will eventually finish.

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

    We had a proof that it was always achievable before the contest — in fact, all tests are generated randomly and not by hand. The main reason we disabled hacks was because of concerns over std::unordered_map hacks. We were also aware of the $$$O(n)$$$ solution without any data structures and using only the XOR operator, but we wanted to ensure that no contestant would get hacked mid-contest.

    The proof was omitted from the editorial since I believed it wasn't needed to solve this problem. Sorry about the confusion!

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

      I don't think it's really necessary. Relying on a particular inefficient implementation is a mistake that everyone should be free to make. In addition, there's a simple, faster choice with better functionality called std::map. Hacks are good for breaking special-case-bad solutions like this.

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

        On the other hand, it makes for a terrible contest experience if there are hacks and i have to go around looking for how to hack thos particular implementation of the dictionary yet again

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

In the solution code of problem D

map<int, int> cntVer, cntDiag;
    for (int i = 0; i < n; i++) {
        int x, y;
        cin >> x >> y;
        cntVer[x]++;
        cntDiag[x + y]++;
    }

cntVer[x]++; Does this mean that if we find key x in map,add the value by 1.else the default value is 0,insert{x,0} to the map?

Seems this is a syntactic sugar.We can use map like an array.But is this code always right?

»
17 months ago, hide # |
 
Vote: I like it +30 Vote: I do not like it

I really like this format of editorial—it allows me to go through the solution step by step when I'm stuck. After each step, I can pause and consider whether I can solve the problem at that point. I think this approach is highly effective for improving both thinking process and skill level.

I strongly recommend that editorials for other Codeforces Rounds adopt this format as well.

»
17 months ago, hide # |
 
Vote: I like it +18 Vote: I do not like it

What a detailed editorial!Hope that contest in the future will be the same as this one.

»
17 months ago, hide # |
 
Vote: I like it +20 Vote: I do not like it

This is one of the best editorials I have ever read. Thank you!

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

Great Editorial!!

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

Answer in steps is better than hints

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

Thank you for the detailed editorial! Appreciate the effort put into writing this.

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

Very understandable, thank you for the tutorials

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

Questions about Step 7 for problem E — Wonderful Teddy Bears:
1) What does it guarantee us that we can make operation A or operation C first d times? What if array is not sorted, but we can't make operation A or C?
2) What does it guarantee us that we can make operation B or operation D every time after first d times? What if array is not sorted, but we can't make operation B or D?

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

    I'm not sure if I understand correctly.

    If the array is not sorted, but we can't make operation A or C, the string doesn't contain "010"(operation A) or "101", so it is like "111...1000..00" (all ones are on the left of all zeros), then we can do operation B or D first.

    However, no matter how we do operation B or D doesn't change $$$b$$$. $$$d = \lvert \, \left\lfloor \frac{a}{2} \right\rfloor - b \, \rvert$$$ does not change, so we must do operation A or C sooner or later, if it is necessary.

    A certain number of A or C operations are necessary and do not necessarily need to be performed first.


    During the contest, I come up with a solution more like "bruteforce" but maybe more understandable.

    We need a stack (empty initially) and from left to right, we try to add every $$$s_i$$$ in the 0-1 string.

    1. If $$$s_i$$$ is equal to the top of the stack, we pop the top.

    It means we can see $$$top$$$ and $$$s_i$$$ as a combination. More specifically, if $$$top=s_i=0$$$ we perform operation B continuously to move this "00" to the front of the sequence. The case $$$top=s_i=1$$$ is simillar. Every time we perform B or D, the Inversions of the sequence are reduced by 2.

    1. Otherwise, push $$$s_i$$$ to the stack.

    Finally, if the stack is empty, we don't need operation A or C.

    Otherwise the characters in stack will be "1010....01010". Its size is Len.

    We perform operation A or C to make every four "1010" to be "1001", the final stack will be "100110011001...10011001"

    Then we can certainly use only B and D to sort it.

    So the number of operation A and C we performed is $$$cnt=\lfloor \frac{Len}{4} \rfloor$$$.

    So the answer is (Inversions-cnt)/2+cnt.

    my submission

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

What's wrong with this approach in problem E?

1.Bring 2 B's together in pair, eg. PBPPPB -> PBBPPP

2.After step 1, bring pair to left such that no P is in left of that pair, eg.

BPPPBBPP -> BBBPPPPP

Code

Please someone guide.

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

the tutorial of F doesn't declare about how to remove a statement from the begining, and it is not obvious actually. May anyone tell me how to remove, please?

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

    For the statements of type 0 you do perform add(l, r, -1).

    For the statements of type 1 you remove $$$l$$$ from the set $$$s_x$$$ and do set(l, max(s[x])). (-1 if it's empty)

    Now the thing you probably don't understand is how to tell if the current set is good.

    It's always good. But when you are trying to add a statement you need to check that condition in the editorial. If it's bad then you don't add it yet and remove the current leftmost condition. If not then you can finally add it.

    316435804

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

      Definitely RIGHT! I did thinking about how to find out the fault statements, but it is clever to maintain the correctness of the set of the statements! Thanks for your clear answer!

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

I understand the steps for problem E, but I can't motivate it(Particularly checking the number of 0s in the even, positions). I don't even know how you would come up with it. Can someone explain thier thought process on how you approached the problem.

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

    During the contest, I come up with a solution more like "bruteforce" but maybe more understandable.

    You can read this comment. Hope it will help.

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

How can we show that $$$x - d$$$ will always be even in problem E?

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

    In the end, when you can no longer make a move of type A or C, the string will look like 00100100. At that point, only the patterns 100 or 110 will have an effect, and both contain 2 (even) inversions.

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

This is the best way of Editorial ever

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

An (unnecessarily complicated) way to generate columns for G:

Let $$$f_0(1) = \{[0]\}, f_{-1}(1) = \{[-1]\}, f_1(1) = \{[1]\}$$$, and let $$$\text{append}(S, x)$$$ be the set of all $$$v \in S$$$ with $$$x$$$ appended to them.

Then, for all $$$i \gt 1$$$, define $$$f_0$$$, $$$f_{-1}$$$, and $$$f_1$$$ inductively as follows:

$$$f_0(i) = \text{append}(f_0(i - 1), 0) \cup \text{append}(f_{-1}(i - 1), -1) \cup \text{append}(f_1(i - 1), 1)$$$
$$$f_{-1}(i) = \text{append}(f_0(i - 1), 1) \cup \text{append}(f_{-1}(i - 1), 0) \cup \text{append}(f_1(i - 1), -1)$$$
$$$f_{1}(i) = \text{append}(f_0(i - 1), -1) \cup \text{append}(f_{-1}(i - 1), 1) \cup \text{append}(f_1(i - 1), 0)$$$

We can induct with the following claims:

$huh why did mathjax break??$

  • $$$f_0, f_{-1}, f_1$$$ are pairwise disjoint, each has size $$$3^{i - 1}$$$. All of them satisfy the property that for every 2 columns inside of them, they differ in at least 2 positions.
  • For all $$$v \in f_0$$$, $$$-v \in f_0$$$
  • For all $$$v \in f_{-1}$$$, $$$-v \in f_1$$$

To select columns, we can pick things from $$$f_0$$$ in the last layer.

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

This is the coolest tutorial I've ever seen.

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

My favorite editorial's style

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

In the problem statement of problem A '<' symbol is defined as \lt and '>' symbol is defined as \gt. There seems to be conversion issues in the symbols or maybe its my own browser.