ZhouShang2003's blog

By ZhouShang2003, 6 hours ago, In English

1991A — Maximize the Last Element

Hint
Solution
Code

1991B — AND Reconstruction

Hint
Solution
Code

1991C — Absolute Zero

Hint 1
Hint 2
Solution
Code

1991D — Prime XOR Coloring

Hint
Solution
Code

1991E — Coloring Game

Hint
Solution
Code

1991F — Triangle Formation

Hint
Solution
Code

1991G — Grid Reset

Hint 1
Hint 2
Solution
Code

1991H — Prime Split Game

Hint 1
Hint 2
Hint 3
Hint 4
Hint 5
Solution
Code

1991I — Grid Game

Hint 1
Hint 2
Hint 3
Hint 4
Hint 5
Hint 6
Hint 7
Hint 8
Solution
Code
  • Vote: I like it
  • +46
  • Vote: I do not like it

»
6 hours ago, # |
  Vote: I like it +33 Vote: I do not like it

so zengminghao told me during the round that problem I can be found at https://www.brand.site.co.il/riddles/200802q.html

Fortunately, it seems it has affected almost no one. Sorry for this unfortunate coincidence though :/

»
6 hours ago, # |
  Vote: I like it -96 Vote: I do not like it

D is nice

»
6 hours ago, # |
  Vote: I like it +98 Vote: I do not like it

imo, D wasn't so good

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

    D is going on bullet point 1 of my suicide note

    • »
      »
      »
      5 hours ago, # ^ |
      Rev. 2   Vote: I like it +21 Vote: I do not like it

      I came to that conclusion of minimum number of colors being 4 in a more rigorous way and paid dearly for it by being unable to implement it.

      I had this idea, let edges between $$$a$$$ and $$$b$$$ have the number $$$XOR(a, b)$$$ being a prime number say $$$p_1$$$. then let's take $$$3$$$ numbers $$$a, b, c$$$
      where $$$b$$$ and $$$c$$$ have edges with $$$a$$$.

      then if $$$a$$$ and $$$b$$$ have edge with value $$$p_1$$$
      and $$$a$$$ and $$$c$$$ have edge with value $$$p_2$$$
      (and none of $$$p_1$$$ or $$$p_2$$$ is 2)

      then the associated edge number between $$$b$$$ and $$$c$$$ must be $$$XOR(p_1, p_2)$$$ but both of them are odd. so this $$$XOR$$$ must be even or perhaps $$$2$$$!

      if $$$XOR(p_1, p_2)=2$$$ and $$$XOR(a, d) = 2$$$; then $$$XOR(p_1, 2) = p_2$$$ and $$$XOR(p_2, 2) = p_1$$$ which implies that all $$$a, b, c, d$$$ are connected strongly and must have different colors.
      There can be no higher form of "strong" connection. (I assume it's trivial by now).

      I was first thinking about pruning a DFS/BFS like thing. I thought these $$$p_1$$$ and $$$p_2$$$ must be twin primes (ending with 01 and 11 in binary). Wrote a program to see how many such primes are and found they were less than 1400 till 200000, also did a bunch of weird stuff. but ultimately failed to do the thing.

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

        I also tried so so many complex things. Actually, I reached conclusion that for n = 2 * 1e5, we need at maximum 36 colors, if we colour the graph greedily. And then implemented completely different thing. tried multiple appraoches, but all failed.

      • »
        »
        »
        »
        5 hours ago, # ^ |
        Rev. 3   Vote: I like it +33 Vote: I do not like it

        $$$K_4$$$ appears as a subgraph for $$$n \geq 6$$$ as $$$(1,3,4,6)$$$ is completely rigorous...

        • »
          »
          »
          »
          »
          5 hours ago, # ^ |
          Rev. 2   Vote: I like it +7 Vote: I do not like it

          My comment was partially supposed to be a rant, (I understand $$$(1, 3, 4, 6)$$$ is $$$K_4$$$) Perhaps I focused too much on proving it without assuming it.
          Had I assumed and then validated my assumption, I could have reached the solution.

          Edit: Perhaps rigor is not the word I should have used. but you get what I wanted to say, I just meant proving it without assuming it. (which I understand, is in no way more complete or anything).

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

          Also you ultimately prove your bound of $$$4$$$ by giving a valid construction.

          saying that $$$K_4$$$ appears as a sub graph for $$$n>5$$$ just tells that the number of colors cannot be less than $$$4$$$. (for $$$n>5$$$)

          you prove that it is in-fact, $$$4$$$, by providing a valid construction.
          (Just putting it here so that others don't confuse this statement with a completely rigorous proof).

»
5 hours ago, # |
  Vote: I like it +8 Vote: I do not like it

If you're wondering about about the connection between XOR and modulo 4, you can upsolve CF15C : Industrial Nim

»
5 hours ago, # |
  Vote: I like it +1 Vote: I do not like it

quite a few constructives

  • »
    »
    5 hours ago, # ^ |
    Rev. 2   Vote: I like it -10 Vote: I do not like it

    constructiveforces

    edit: A master posted the exact same comment and got +38. What are the downvotes for??

»
5 hours ago, # |
  Vote: I like it +20 Vote: I do not like it

Probably my worst contest so far, I knew what to do but had some errors. Might need to take a step back and re-eval my approaches

»
5 hours ago, # |
  Vote: I like it +22 Vote: I do not like it

Problem E is so similar to this Problem.

»
5 hours ago, # |
  Vote: I like it +9 Vote: I do not like it

I can't note that $$$4\mid \left(a\oplus (a+4k)\right)$$$. So sad.

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

    Why does 4∣(a xor (a+4k))? Is there an easy way to see this?

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

      The last two bits of a and a + 4k are the same. So the last two bits of (a xor a+4k) are 0, which is the same as being divisible by 4.

»
5 hours ago, # |
  Vote: I like it +28 Vote: I do not like it

I can easily solve problems of E and F, but I struggled with problem D for a long time before coming up with a solution

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

B can be solved like this also ~~~~~

void Solve() { int n; cin >> n; vi a(n-1); cin >> a;

vi ans;
ans.pb(a[0]);
for(int i = 1; i < n-1; ++i) {

    int num = a[i] | a[i-1];
    if((ans.back() & num) != a[i-1]) {
      cout << -1 << nl;
       return ;
    }

    ans.pb(num);
}
ans.pb(a[n-2]);

cout << ans << nl;

}

~~~~~

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

Why is the title of problem C "Maximize the Last Element"? Shouldn't it be "Absolute Zero"?

UPD: Changed.

»
5 hours ago, # |
  Vote: I like it +23 Vote: I do not like it

A round full of ARC&AGC problems. :)

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

    F could maybe be AGC A so I struggle to understand you since 3 problems don't make a full round. Is it sarcasm?

»
5 hours ago, # |
Rev. 4   Vote: I like it +4 Vote: I do not like it

Alternative solution for C (for the "YES" case):

Until all values become zero, do this for each iteration: Get the minimum and maximum of the current array. Change the values of the array with x = (maximum+minimum) / 2; At each iteration the value of (maximum-minimum) reduces by a factor of 2. So we will achieve the desired result in at most ceil(log(maximum-minimum)) operations.

»
5 hours ago, # |
  Vote: I like it +9 Vote: I do not like it

Enjoyed the round a lot, especially D and E are great. Thanks to coordinators, authors and testers!

»
5 hours ago, # |
  Vote: I like it +10 Vote: I do not like it

Human intelligence round

»
5 hours ago, # |
  Vote: I like it +7 Vote: I do not like it

D should have come after E I swear. I almost had E even though I only spent the last 30 mins on it, just didn't have time to get color assignment bugs sorted :(

»
5 hours ago, # |
  Vote: I like it +21 Vote: I do not like it

No evaluation of good or bad but problem D strikes me as utterly absurd.

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

    I think it's a perfect example of the current meta, where the first 3-4 problems are discrete math puzzles that are trivial to implement and only after them you get to the actual programming problems. Also not sure if this is good or bad

»
5 hours ago, # |
  Vote: I like it -19 Vote: I do not like it

D is a good problem, I like it very much!

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

For any unselected sticks between the chosen sticks, if there exists a stick to its left and a stick to its right that belongs to the same triangle, we can replace the rightmost stick of this triangle with the unselected stick.

This is incorrect. Let's consider sticks 2, 4, 10, 11 and select non-consecutive 2, 10 and 11. Then we can't replace rightmost 11 with unselected 4 because 2 + 4 < 10. I think correct proof here should be something like: if we consider our triangle as two connected intervals left and right ([2;10] and [10;11]), then if the unselected stick is in the left interval (4 is in [2;10]) then we can replace the leftmost stick of the triangle with it, otherwise we can replace the rightmost.

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

Constructive Forces.

»
5 hours ago, # |
  Vote: I like it -19 Vote: I do not like it

trash round

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

    Is this because you didn't perform well?

»
5 hours ago, # |
Rev. 3   Vote: I like it 0 Vote: I do not like it
WA - E

same solution as editorial. why still WA ??

upd: got it. thanks

»
5 hours ago, # |
  Vote: I like it +1 Vote: I do not like it

anyone tried colouring graph greedily in the problem D ???

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

    yeah, when you do that it makes a weird pattern:

    pattern
    • »
      »
      »
      4 hours ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      been there, and it touches 36, at n = 2054... and then we don't need any more colour than 36 till n = 2 * 1e5.

»
5 hours ago, # |
  Vote: I like it 0 Vote: I do not like it

Problem C Video Editorial

https://youtu.be/wsD3l8J1Hog

»
5 hours ago, # |
  Vote: I like it 0 Vote: I do not like it

G killed me, maybe guessing that the construction is not that hard will help next time

»
4 hours ago, # |
  Vote: I like it 0 Vote: I do not like it

In H, it's possible to get AC without using FFT or bitset operations to find winning/good positions. Just generate all primes <= 2*10^5, find out if they're winning or losing, and sum every pair of losing primes (to find winning positions) and every pair of winning primes (for good positions).

»
4 hours ago, # |
  Vote: I like it 0 Vote: I do not like it

can some body explain E and F? in E how it is biparitie and F would'nt it will be tle if for n queries there are there is multiple for loops ?plz explain

»
4 hours ago, # |
  Vote: I like it 0 Vote: I do not like it

My another solution for $$$C$$$:

Note $$$k$$$ is the maximum integer such that $$$2^k \le max(a_i)$$$. I subtract $$$x=2^k-1$$$ from all the numbers. In most cases, the highest position will drop. But there is one exception: $$$max(a_i)=2^{k+1}-1$$$. In this case, I will perform an additional operation — randomly select a number between $$$[1,2^k-1]$$$.

It looks wrong in the worst case. But idk if it is hackable.

https://codeforces.com/contest/1991/submission/273218080

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

I tried a long ahh time, but can someone tell me how is this wrong for problem E. Let alone out of bounds error because theres no way thats possible

https://codeforces.com/contest/1991/submission/273238586

Edit: I found out, when clearing my adj list, i was clearing from 0 to n-1 instead of 1 to n :((

Atleast I'm happy i wasnt wrong

»
4 hours ago, # |
  Vote: I like it -7 Vote: I do not like it

D: The sample says the answer is $$$4$$$ if $$$n=6$$$. So let's guess, in the general cases the answer is $$$4$$$ <- This is just a riddle.
I couldn't find any rules yet, so tried around $$$n=20$$$ with Chromatic Number. Then I said the answer is $$$4$$$, so starting to consider construct $$$4$$$-coloring.
I think it's somewhat natural, still it's a mascle approach.

»
4 hours ago, # |
  Vote: I like it +7 Vote: I do not like it

Different solution to F:

For each right point you find the maximal left endpoint for which the answer is yes. It is easy to see that you can use the two pointer technique to compute this. We maintain a set (for its sorted order) and then moving the pointers basically amounts to inserting or removing from the set. To check whether a set is valid, treat it as a sorted vector and find the number of indices $$$i$$$ for which $$$a_i \lt a_{i-1}+a_{i-2}$$$; if it's at least 4 then we can show that two disjoint non-degenerate triangles exist, otherwise run a bruteforce. To make the solution efficient enough, we maintain the number of such indices throughout the insertions and removals, noticing that an element can only affect the state of at most three indices.

»
4 hours ago, # |
  Vote: I like it 0 Vote: I do not like it

why this code is wrong (for problem D)???

let me explain in short what i have done.

first of all, i can find the array of colors for n <= 5 myself. for n > 5, there will be two cases: n is odd or n is even.

now if n is odd, it will never connect with vertex 1 (because odd ^ 1 = even ( >= 4) when odd >= 5, which are not prime) hence i can give color 1 to the all odd numbers after 3.

we will have more subcases when n is even. n ^ odd can be prime but n ^ even can never be prime except when n ^ even is 2, which is only possible when n & 2 is 2 (that is, binary representation of n has 2 in it) and even is n — 2 (as it will have all the 1s and 0s at the same position except the 2nd bit).

for checking with odd, we only need to care about 3 as it is colored with color 2, whereas all other odds are colored with color 1. Now we will keep track of the colors we have remaining. if n ^ 3 is prime, we will not have color 2. also if n ^ (n — 2) is prime, we will not have the color of vertex n — 2 as well. as we know that chances of n ^ odd being prime are significant, hence we assume that we do not have color 1 for n. so if n ^ 3 is not prime and n ^ (n — 2) is not prime or n ^ (n — 2) is prime but n — 2 has larger color (like 3 or 4) we will have color 2 free for n, else we will have color 3 free. else if n ^ 3 is prime we will have color 3 and 4 free for n (using the same logic).

so we will never require more that 4 colors and no two connected vertices will have the same color.

pls find any logical shortcoming in my answer, if there is any....

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

    If n >= 14, then any two vertices from (11, 9, 12, 14) are adjacent. It means, that they must be with different colors. But in your code for every i > 5 vertex i can be colored in colors 2, 3, 4.

»
4 hours ago, # |
  Vote: I like it 0 Vote: I do not like it

I would like to share another approach for Problem C : while the 40 operations are not over we will sort the array provided to us find the minima and maxima find the middle value and then use this middle value to form the new array and find absolute diff between array and mid and again sort the array till either all the values are 0 or the operations are over.

My code:Have a look

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

My cool (imo) solution to G :

Lets keep a buffer of size K * K at top left

The right section of K * (M — K) will be my V-placing zone

The bottom section of (N — K) * K will be by H-placing zone

We normally put any H or V in their respective zones, except for when the zones are full, then we use the buffer

Lets call a H block => buffer has a H type thing

H full => we cant place H in its zone

V full and V block defined similarly

If we can ensure V-zone full and H block doesnt happen simulatenously (and ofc its symmetric thing as well), we win

However, its easy to do that

1) if there is a H block, filling up V — zone naturally gets rid of that

2) if V — zone is full, there exists a row such that the row becomes full upon placing a H there

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

D is ok-ish, don't think all the hate is justified. (though reasoning in the editorial is strange – looks way too observation-based while just thinking about xor of odd/even almost immediately provides a solution)

But E imo is atrociously uninspiring – I couldn't believe that I understood the problem correctly until I got AC.

  • »
    »
    2 hours ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Can you explain the odd/even logic for D?

    • »
      »
      »
      108 minutes ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      my thought process:

      xor of same-parity numbers is even, which is usually not prime

      so the most greedy approach would be to divide in two groups – even and odd

      of course it doesn't work, e.g. 1^3=2

      We know (at least from test case) that at some point we would need at least 4 groups, so let's try to divide both current groups in two

      Let's just take odd numbers starting with one trying to avoid 2 as xor-sum of last two elements: 1, 5, 9, 13, 17...

      And at this point I got the solution from the editorial

      after writing it up I guess there are still some strange observations, but well, problem is mathy

      • »
        »
        »
        »
        100 minutes ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

        Oh that's actually much more straightforward than I thought. That's a lot more intuitive than I thought.

»
2 hours ago, # |
  Vote: I like it +8 Vote: I do not like it

ZhouShang2003, could you please share how the checker for problem D is implemented?

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

    ZhouShang2003 shared Bitwise Xor Convolution, which can be applied to the values of each color to validate that no two numbers of the same color have their XOR equal to a prime number. Thanks!

»
2 hours ago, # |
  Vote: I like it 0 Vote: I do not like it

The most cool thing was proving that range greater than equal to 48 will always be yes.

»
86 minutes ago, # |
  Vote: I like it 0 Vote: I do not like it

Swap D and E

»
38 minutes ago, # |
  Vote: I like it 0 Vote: I do not like it

I clearly am doing something wrong while writing code. My question is whether anyone can tell me what :pleading_face:

»
26 minutes ago, # |
  Vote: I like it +1 Vote: I do not like it

So many constructive problems, I got stuck on D for 10 minutes and nearly failed to get positive delta

»
a moment ago, # |
  Vote: I like it 0 Vote: I do not like it

Problem D could've been erased from the contest