k1sara's blog

By k1sara, 13 months ago, translation, In English

Thank you for participating, and we truly hope you enjoyed the contest!


How did you find the contest?
Which problem was your favorite?
Which problem did you find the least enjoyable?


2092A - Kamilka and the Sheep

Author: k1sara

Hint
Solution
Code (C++)
Code (Python)
Rate the problem


2092B - Lady Bug

Author: sergeev.PRO

Hint 1
Hint 2
Solution
Code (C++)
Code (Python)
Rate the problem


2092C - Asuna and the Mosquitoes

Author: sergeev.PRO

Hint 1
Hint 2
Solution
Code (C++)
Code (Python)
Rate the problem


2092D - Mishkin Energizer

Author: k1sara

Hint
Solution 1
Code 1 (C++)
Solution 2
Code 2 (C++)
Rate the problem


2092E - She knows...

Author: k1sara

Hint
Solution
Code (C++)
Rate the problem


2092F - Andryusha and CCB

Author: k1sara

Hint 1
Hint 2
Hint 3
Solution
Code (C++)
Rate the problem
  • Vote: I like it
  • +34
  • Vote: I do not like it

| Write comment?
»
13 months ago, hide # |
 
Vote: I like it -7 Vote: I do not like it

why first question was harder than the second

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

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

I didn’t like the round. I simply guess forced B, C and D. Particularly I think you are required to guess D. Also, this contest (up till E, as I didn’t solve F) was full adhoc: no DP, no binary search, no algorithmic analysis, no graphs (ok, this one is basically a myth in div. 2 at this point), no trees, no particular DS, simply full adhoc the entire contest :(

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

    well you can prove no of operations you will use like mine was 2n-3, but then i also ran a guess solution which adds L I T as long as each of their count is less than n, and it passed too. im not really big fan of guess problems.

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

    This seems to be a bit common on cf.

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

I thought i < j in C.

I thought i < j in C.

I thought i < j in C.

I thought i < j in C.

i spent 2 hours getting WAs after solving AB in 10 mins

someone kill me NOW

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

Why was constraint for n kept to be<=100?

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

    Maybe the checker need to insert $$$2n$$$ times and it is $$$O(n^2)$$$.

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

    Make brute force pass. $$$O(tn^2)$$$ is acceptable although there is an $$$O(tn)$$$ solution.

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

I believe step 1 of solution 1 for question D should say bac instead of bca.

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

Another easier way to E:

If a connected component is completely surrounded by another, the contribution must be even. So if we add a black circle to the outermost, the answer must be even too.

Consider what the black circle do: Contribute 2 for the white corner cells and 1 for the white border cells. So when the black circle removed, the number of white border cells also must be even.

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

We got a diddy collab before gta 6

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

how to come up with C? The solution gives a formula and tries to prove it. How do i come up with such formulas? just guess something and try to prove it??

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

    First, we notice that odd and even numbers need to be combined. Then, we observe that the combination of an odd and an even number always results in an odd number. You can imagine the odd number 'devouring' the even number and turning into a larger odd number.

    From a greedy perspective, we want the largest possible even numbers to be 'devoured' to maximize the resulting number. Thus, we can devour all the even numbers. However, we haven’t fully utilized the odd numbers. We can extract an even component from one of the odd numbers and add it to the original even numbers, making the even portion larger.

    To optimize this, we leave just one odd number and merge all the remaining parts into the even numbers. Then, we let the odd number devour all the even numbers, achieving the desired result.

    i use deepseek to translate my thoughts into English.

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

    Revised explanation: We should reduce all odd numbers to 1 (each remaining as 1), instead of combining them into just one odd number.

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

    Lets say u have all the numbers odd or even then the answer is the max this u can easily see as odd + odd = even & even + even = even. Now consider the maximum number to be odd lets say the array is 21 11 9 2 then when we consider 21 as the maximum value then when we add 2 to it becomes 22 and 2 becomes one thus no even number left but then even + odd = odd so 11 becomes 10 so it alternates so all the even numbers eventually become 0 and odd numbers become equal to 1. Then if the maximum number is even eventually you will see the number you have to minus is (count of odd-1) if you just use and example.... Sorry Didn't provide with a mathematical proof.

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

    It's useful to think about invariants on the data, and about lower and upper bounds on the answer.

    In this case, there are two invariants that are helpful:

    1. Operations do not change the total sum of the array. (This one is pretty obvious.)

    2. Operations do not change the total number of towers with even/odd height. (This is slightly less obvious, but since each operation involves 1 tower of odd height and 1 tower of even height, and increasing/decreasing a tower's height flips its parity, that means the two towers involved in an operation always swap their parity, keeping the total number of even and odd towers unchanged. This is true regardless of whether you move from the odd to the even tower, or vice versa.)

    This allows you to prove an upper bound on the answer of (sum of heights) — (number of odd towers — 1), because given the above invariants, the very best case is where your "highest" tower has an odd height, all the other odd towers have height 1, and all the even towers have height 0.

    Then you just need to prove that this is always achievable, which is fairly easy in this case.

    • »
      »
      »
      13 months ago, hide # ^ |
       
      Vote: I like it +1 Vote: I do not like it
      Thank you
  • »
    »
    13 months ago, hide # ^ |
     
    Vote: I like it -21 Vote: I do not like it

    Yes!! Just guess bro, this is the current codeforces meta.

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

Felt D to be more easier today. But still can't solve it, due to miscalculation

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

If you think no one is cheated in this contest:

read this Blog

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

I can't understand the second question. Could someone explain it to me? (this is my first contest)

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

    "You can observe that you can swap any two elements if they are in the positions of a₀, b₁, a₂... or b₀, a₁, b₂... Since swaps can be performed any number of times, all elements can be freely rearranged. For the first case where arbitrary swaps are possible, we need to make all elements at a₀, a₂... positions zero. This means the number of zeros in the a₀, b₁, a₂... sequence should be greater than or equal to the total number of elements at a₀, a₂... positions, which is the ceiling of n/2."

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

      Why the number of zeros needs to be greater or equal n/2? And why in the c++ code, the conditional of cnt1, in the output, is (n+1)/2

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

        The reason for using (n + 1) / 2 is to perform ceiling division, i.e., computing the smallest integer p such that p * k ≥ n (using the formula (n + k — 1) / k). This ensures that the number of 0s in Position 1 (i.e., cnt1) is at least the minimum required number of 0s.

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

About problem E: it might just be a me problem, but when writing a problem about a grid and cell coordinates on that grid, I think there needs to be an explanation on how the rows and columns are numbered (from left to right, top to bottom, …) to avoid confusion.

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

Get blocked by Cloudflare for nearly twenty minutes while solving C :(

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

Thanks for the contest! I was able to solve 3 problems. Nothing could have made me happier than waking up as a Pupil! Thanks again! ◝(ᵔᵕᵔ)◜

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

In D solution 1, why does 2 cnt(c) — cnt(b) — cnt(a) = 0 imply cnt(a) = cnt(b) = cnt(c)?

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

Is D solvable by just inserting the lowest frequency element(that we can insert) every time ?

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

    No, because sometimes you can't insert it. For example in this case:

    cccabbb — here a the rarest element, but there is no way to insert it

    UPD. Oh, I misunderstood the question. Yes, it can be solved, but it is more difficult to prove the correctness.

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

      Why is it hard to prove correctness. If freq(a) < freq(b) < freq(c), you need to insert 'a' freq(c) — freq(a) times, so it's not worse to insert a. You never lose any options when you do this, and every operation is independent from each other. If you don't have any options left, you are forced to insert c. It feels fairly straightforward to me. Am I missing something?

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

        Because if you do this, the frequency of the b element will not be constant, so it is difficult to use claim 2 to estimate the number of operations.

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

          But you don't have to prove that the number of operations is < 2n. You can just simulate and if at any point the number of operations is too much you can stop. It's still equally correct.

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

            No. It has been proven that an algorithm with $$$\le 2n$$$ operations always exists if the string does not consist of identical characters. Therefore, if a solution is not optimal — let's say it requires $$$3n$$$ operations — and stops at $$$2n$$$ operations when a valid solution actually exists, it is incorrect.

            What sergeev.PRO was trying to say is that the aforementioned solution does work; however, a formal proof that it performs no more than $$$2n$$$ operations is required to demonstrate its correctness.

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

              I don't understand why you need a formal proof that it never performs more than 2n operation. Isn't enough to show that it's optimal, because then it would never incorrectly stop when a valid solution does exist.

              My reasoning for why its optimal is:

              1) It doesn't matter where you insert a letter in the string, all insertions of the same letter are equal.

              2) The order in which you perform operations doesn't matter, in the sense that performing one operation doesn't stop you from performing any of the other operations that you could before.

              3) Any optimal solution must insert at least freq(c) — freq(a) 'a's, and freq(c)-freq(b) 'b's, so its never worse to insert them first (all it does is open up more options).

              Obviously this isn't a formal proof, but I feel like it's intuitive that its optimal (unless I'm missing something obvious which is definitely possible)

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

                Yeah, I guess with this reasoning, the algorithm is indeed optimal, although there might still be some corner cases. Sorry for the inconvenience.

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

for problem F, despite writting a very efficient and low constant factor code, it still TLEs, was the TL set so tight to cut down any solutions ?

313191690

without push backs

313191925

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

    The intended solution has a time complexity of $$$O(n \log n)$$$ and a memory complexity of $$$O(n)$$$, so ideally, we wanted to exclude solutions with higher complexities. My solution ran in under $$$300$$$ ms, so setting the time limit $$$6 \times$$$ of that seemed sufficient.

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

I tried visualizing all the problems in a single image — this is what I came up with. LOL!

Image For the Contest *AI generated image

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

Very good A problem that makes you think, thanks for the round

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

WHY (N+1)/2 IN LADYBUG PROBLEM IS TAKEN ?

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

Problem E:

can someone explaine me, why the even neighbours cells will not have any effect on the answer ?

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

    Think about putting some black cells in an infinitely large field filled with white cells. Take a connected segment of black cells. Then the number of pairs of adjacent cells with different colors is equal to the length of perimeter of the segment (if the segment has an inner hole, its perimeter also counts). And the length of the perimeter of the segment is always even (it's easy to prove this).

    With this fact in mind, you can see the number of pairs of adjacent cells with different colors is always even, provided that the field is infinitely large. If the dimension of the field is finite, only the colors of the edge cells contribute to the parity of the number of pairs of adjacent cells with different colors -- because other cells' contribution cancels out. More precisely, the contribution of corner cells can be ignored, because they change the parity twice.

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

    Another way to see it is:

    Letting black cells be 1 and white cells be 0, we want $$$\sum\limits_{(u,v)\in E}^{} (u+v) = 0$$$ (mod 2). It's easy to see that this is equivalent to $$$\sum\limits_{u\in V}^{} deg(u)*u $$$ (mod 2). So cells with an even count of neighbors don't contribute to the answer.

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

I think reading the solution of F is like doing some blank filling tests.

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

Thanks for the fun round!

Just wanted to make a note that in problem F, the reason why we can update the answer the way the editorial says is because for a fixed pair $$$(k, i)$$$, there is at most one value of $$$m$$$ for which we can split the prefix of the first $$$i$$$ blocks into $$$k$$$ groups with $$$m$$$ changes in each group. Assume for the sake of contradiction that $$$m = x$$$ and $$$m = x + 1$$$ are both good. When $$$m = x$$$, there are at most $$$x * k + k - 1$$$ changes in the prefix (there are $$$x$$$ changes in each block, and at most $$$k - 1$$$ changes between blocks). On the other hand, when $$$m = x + 1$$$, there are at least $$$(x + 1) * k = x * k + k$$$ changes in the prefix (there are at least x + 1 changes in each block). Contradiction. The same argument can be applied for two values of $$$m$$$ which differ by more than $$$1$$$ as well, proving that for a fixed pair $$$(k, i)$$$ there is only a single good value of $$$m$$$.

Maybe it was obvious to other people, but I had to think a while before realizing.

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

In 2092B C++ solution, should there be an OR condition like this

(cnt2 >= (n + 1) / 2 && cnt1 >= n / 2 ? "Yes" : "No")

along with this?

cout << (cnt1 >= (n + 1) / 2 && cnt2 >= n / 2 ? "Yes" : "No") << '\n';

Because if n is odd then cnt2 could also be of odd length and cnt1 of even?

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

Nice problem

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

In Problem E, Why are we excluding the corners?

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

Was having a hard time figuring out what the optimal value of $$$ d $$$ would be for A, and didn't quite get how they arrived at the result even after reading the editorial. So heres a more noob friendly explaination if anyone else is having the same doubt:

Assuming $$$ a \lt b $$$, we know $$$ gcd(a, b) = gcd(a, b - a) $$$. Applying this on the the condition we want to optimize in the problem, $$$ gcd(x + d, y + d) = gcd(x + d, y - x) $$$. The maximum possible $$$ gcd $$$ of two positive integers would be the lesser of the two numbers which is $$$ y - x $$$ here. Therefore, we arrive at the conclusion that $$$ gcd(x + d, y - x) \leq y - x $$$.

Now, addressing the part thats not explicitly explained in the editorial, to maximize the $$$ gcd $$$, or to make it equal to the maximum possible value we established earlier that is $$$ y - x $$$, we want $$$ gcd(x + d, y - x) = y - x $$$. We know that $$$ gcd(a, b) = b \Longleftrightarrow b \mid a $$$. So clearly we get $$$ y - x \mid x + d $$$. This means that $$$ x + d \equiv 0 \pmod{y - x} $$$. Therefore, on rearranging the terms, the smallest non-negative solution is $$$ d = (-x) \bmod{y - x} $$$, which is the proposed value of $$$ d $$$ that maximizes the condition.

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

In the Solution 2 of the problem D, the total operations should be $$$2z+2y-4x$$$

firstly we require $$$ 2x-2y$$$ operations to make $$$x=y$$$ as it takes atmost 2 operations to add one $$$a$$$ as we need to add both $$$a$$$ and $$$c$$$ in worst cases.

and now $$$x'=y$$$ , now we need exactly $$$2(z'-y)$$$ operations, now $$$z'$$$ may have become $$$z+(y-x)$$$

so, total operations = $$$2(z+(y-x) - y) + 2(y-x) $$$

finally = $$$2(z+y-2x) $$$

which is obviously < $$$2 *n$$$

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

Dam problem E is based on diddy party

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

For D problem the optimal solution would be always inserting the current rarest character. Let's say cnt(a) <= cnt(b) <= cnt(c), if bc or cb is present we can insert a and if it is not present then at least ac or ca must be present. Let's take the ac case.

  • abc

  • abac

  • acbac

  • acabac

by this we have inserted 2a, 1b and 1c.

And eventually by doing this we will reach cnt(a) == cnt(b) == cnt(c)

Then why do we need to prove that operations will end within 2n steps. Even though there is a proof, I think its unnecessary because this is the optimal way to insert.

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

Does problem E have anything to do with Galois Field. I was trying to understand the editorial with the help of some tool and it said that the idea of cells with even neigbours not affecting the answer is something related algebraically to xor and mentioned something about GF(2). but I still do not understand how non-border cells will not affect the answer especially if they are neighbours of fixed cells. can someone explain

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

for second question we can directly find it like for any even indices of first string can be replaced by any odd indices of second string and vice a versa. so we want to replace all ones of first string with zeros from second string such that their indices have different parity. so we need to count ones at even indices in first string and it should be less than or equal to the zeros count at odd indices in the second string and it should be same for ones count at odd indices in first string should be less than or equal to the zeros count at even indices in second string.