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

Автор k1sara, 18 месяцев назад, По-русски

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 - Камилька и барашки

Author: k1sara

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


2092B - Леди Баг

Author: sergeev.PRO

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


2092C - Асуна и комары

Author: sergeev.PRO

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


2092D - Мишкин Энергетик

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 - Андрюша и CCB

Author: k1sara

Hint 1
Hint 2
Hint 3
Solution
Code (C++)
Rate the problem
Разбор задач Codeforces Round 1014 (Div. 2)
  • Проголосовать: нравится
  • +34
  • Проголосовать: не нравится

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

why first question was harder than the second

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

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

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 :(

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

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

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

first one was guess work!

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

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

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

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

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

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.

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

We Got Diddy collab with codeforces before gta 6

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

We got a diddy collab before gta 6

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

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

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

    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.

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

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

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

    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.

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

    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.

    • »
      »
      »
      18 месяцев назад, скрыть # ^ |
       
      Проголосовать: нравится +1 Проголосовать: не нравится
      Thank you
  • »
    »
    18 месяцев назад, скрыть # ^ |
     
    Проголосовать: нравится -21 Проголосовать: не нравится

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

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

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

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

If you think no one is cheated in this contest:

read this Blog

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

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

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

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

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

      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

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

        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.

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

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.

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

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

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

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! ◝(ᵔᵕᵔ)◜

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

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

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

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

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

    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.

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

      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?

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

        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.

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

          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.

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

            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.

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

              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)

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

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

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

Can anyone help with the editorial of D? I don't understand either solution.

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

for problem F , despite writting a very efficient and low constant factor code for it the TL is way too tight, is it meant to cut down any solutions or was it just not thought of carefully ?

313191690

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

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

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

    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.

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

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

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

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

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

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

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

In the solution for F, we iterate over $$$m$$$ and just increment range accordingly as we go from $$$k = 1 \dots O(sz / m)$$$, but how can we be sure that each possible $$$k$$$ for some index $$$i$$$ has been updated to $$$i$$$ exactly once (to avoid overcounting) ?

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

Problem E:

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

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

    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.

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

    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.

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

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

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

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.

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

In Problem E, Why are we excluding the corners?

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

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

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

Dam problem E is based on diddy party

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

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.

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

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

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

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.