Блог пользователя SanguineChameleon

Автор SanguineChameleon, 12 месяцев назад, По-английски

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
  • Проголосовать: нравится
  • +242
  • Проголосовать: не нравится

»
12 месяцев назад, скрыть # |
 
Проголосовать: нравится +6 Проголосовать: не нравится

Thanks for the fast tutorial!

»
12 месяцев назад, скрыть # |
Rev. 3  
Проголосовать: нравится -21 Проголосовать: не нравится

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.

»
12 месяцев назад, скрыть # |
 
Проголосовать: нравится +6 Проголосовать: не нравится

why were hacks disabled for problem D?

»
12 месяцев назад, скрыть # |
 
Проголосовать: нравится +2 Проголосовать: не нравится

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

»
12 месяцев назад, скрыть # |
 
Проголосовать: нравится -8 Проголосовать: не нравится

Can anyone explain problem B? I couldn't get after reading editorial :| (me dumb)

  • »
    »
    12 месяцев назад, скрыть # ^ |
     
    Проголосовать: нравится 0 Проголосовать: не нравится

    think in reverse , let's say for test case (in which ans is 481) if you take total no. of gloves you picked == 329. how are you going to prove it wrong . in next take pick gloves == (97 + 77 + 50 + 87 + 74 ) . try to prove it wrong. now observe if you just pick one extra glove you will have atleast one pair . what minimum number is required to pick , such that you have atleast 2 different pairs(color) gloves. hint ==> try to pick 95 and one more from any of remaining gloves.

    • »
      »
      »
      12 месяцев назад, скрыть # ^ |
       
      Проголосовать: нравится 0 Проголосовать: не нравится

      yes, so the answer should be 425 and not 481... how is that ?

      • »
        »
        »
        »
        11 месяцев назад, скрыть # ^ |
        Rev. 2  
        Проголосовать: нравится 0 Проголосовать: не нравится

        i also did the same mistake as we have to take the worst possible case. in the worst case, we would pick the maximum of li,ri. eg: i=1, max(97,95)=97 now if we take 1 glove from 95 the, it would be 1 pair. but we will not do that now. lets just pick the max of li,ri (97+77+50+87+74 = 385). now to have 2 pairs, in the worst case we have to pick max of remaining li,ri (or max(min(li,ri)) as we have counted max(li,ri) already. in that case we pick 95 gloves and picking 1 more glove will guarantee us 2 pairs. so (385+95+1)=481.

»
12 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

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.

»
12 месяцев назад, скрыть # |
 
Проголосовать: нравится +18 Проголосовать: не нравится

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.

»
12 месяцев назад, скрыть # |
 
Проголосовать: нравится +10 Проголосовать: не нравится

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

»
12 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

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.

»
12 месяцев назад, скрыть # |
 
Проголосовать: нравится +11 Проголосовать: не нравится

note to myself: one day i will solve b constantly

»
12 месяцев назад, скрыть # |
 
Проголосовать: нравится +11 Проголосовать: не нравится

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

»
12 месяцев назад, скрыть # |
Rev. 5  
Проголосовать: нравится +5 Проголосовать: не нравится

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://mirror.codeforces.com/contest/2096/submission/316257978

»
12 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

thanks for these creative problems

»
12 месяцев назад, скрыть # |
 
Проголосовать: нравится +8 Проголосовать: не нравится

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.

  • »
    »
    12 месяцев назад, скрыть # ^ |
    Rev. 2  
    Проголосовать: нравится +13 Проголосовать: не нравится

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

»
12 месяцев назад, скрыть # |
 
Проголосовать: нравится +100 Проголосовать: не нравится

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.

  • »
    »
    12 месяцев назад, скрыть # ^ |
     
    Проголосовать: нравится +39 Проголосовать: не нравится

    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!

    • »
      »
      »
      12 месяцев назад, скрыть # ^ |
       
      Проголосовать: нравится +20 Проголосовать: не нравится

      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.

»
12 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

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?

»
12 месяцев назад, скрыть # |
 
Проголосовать: нравится +30 Проголосовать: не нравится

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.

»
12 месяцев назад, скрыть # |
 
Проголосовать: нравится +18 Проголосовать: не нравится

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

»
12 месяцев назад, скрыть # |
 
Проголосовать: нравится +20 Проголосовать: не нравится

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

»
12 месяцев назад, скрыть # |
 
Проголосовать: нравится +10 Проголосовать: не нравится

Great Editorial!!

»
12 месяцев назад, скрыть # |
 
Проголосовать: нравится +10 Проголосовать: не нравится

Answer in steps is better than hints

»
12 месяцев назад, скрыть # |
 
Проголосовать: нравится +10 Проголосовать: не нравится

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

»
12 месяцев назад, скрыть # |
 
Проголосовать: нравится +11 Проголосовать: не нравится

Very understandable, thank you for the tutorials

»
12 месяцев назад, скрыть # |
 
Проголосовать: нравится +3 Проголосовать: не нравится

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?

  • »
    »
    12 месяцев назад, скрыть # ^ |
     
    Проголосовать: нравится 0 Проголосовать: не нравится

    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

»
12 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

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.

»
12 месяцев назад, скрыть # |
 
Проголосовать: нравится +35 Проголосовать: не нравится

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?

  • »
    »
    12 месяцев назад, скрыть # ^ |
    Rev. 2  
    Проголосовать: нравится +29 Проголосовать: не нравится

    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

    • »
      »
      »
      12 месяцев назад, скрыть # ^ |
       
      Проголосовать: нравится +8 Проголосовать: не нравится

      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!

»
12 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

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.

»
12 месяцев назад, скрыть # |
Rev. 2  
Проголосовать: нравится 0 Проголосовать: не нравится

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

  • »
    »
    12 месяцев назад, скрыть # ^ |
     
    Проголосовать: нравится 0 Проголосовать: не нравится

    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.

»
12 месяцев назад, скрыть # |
 
Проголосовать: нравится +16 Проголосовать: не нравится

This is the best way of Editorial ever

»
12 месяцев назад, скрыть # |
Rev. 2  
Проголосовать: нравится 0 Проголосовать: не нравится

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.

»
12 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Sorry SanguineChameleon, I could not understand problem E editorial. Can any1 explain the proof and why this works? I understood till step 4, that 0000..010101..01111..11 will happen. After that I am at a loss. (I am dumb and again starting CP seriously)

»
11 месяцев назад, скрыть # |
 
Проголосовать: нравится +11 Проголосовать: не нравится

This is the coolest tutorial I've ever seen.

»
5 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

My favorite editorial's style

»
4 недели назад, скрыть # |
Rev. 2  
Проголосовать: нравится 0 Проголосовать: не нравится

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.