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

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

We hope you enjoyed the contest as much as we enjoyed writing it! Thank you especially to PCTprobability for your very entertaining submissions to problem E.

Rating predictions

2246A - farmpiggie and Subset Sum

Hint 1
Hint 2
Solution

2246B - ezraft and Array

Hint
Solution

2246C - 0mar and Alternating Sums

Hint 1
Hint 2
Hint 2.1
Hint 3
Hint 3.1
Hint 4
Solution

2246D - diss_quack and Array Game

Hint 1
Hint 1.1
Hint 1.2
Hint 2
Solution

2246E - lce4113 and Security Game

Hint 1
Hint 2
Hint 3
Solution

2246F - Whoname and Unsorted Array

Hint 1
Hint 1.1
Hint 2
Hint 3
Solution
Bonus
Bonus++
Разбор задач Codeforces Round 1108 (Div. 2)
  • Проголосовать: нравится
  • +72
  • Проголосовать: не нравится

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

Auto comment: topic has been updated by 0mar (previous revision, new revision, compare).

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

B was so good, I like it

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

Now that the contest is over, can I know? (Also I love how it's in red)

If there's 3.5 million total tests (if t <= 10^5 and 40 pretests) then there's a 0.65% failure chance. Maybe I'll see if I can submit my lucky number and make it fail lmao

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

    What is your failure probability? There are 40 pretests.

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

      Same as intended, 1 in 2^-29. (Some of my friends / me initially thought of the 2^-15 way, I presume that is supposed to instantly fail) I plugged this into python

      >>> (1-1/536870912)**(3_500_000)
      0.9935019462305397
      

      Assuming independence. If not then maybe I need to start fopen("/dev/urandom")ing

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

        you joke but there's kinda a reason hacks are disabled; lack of independence would do things to the problem

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

          If you randomize properly (like the classic mt19937 with chrono steady clock), I don't think hacks (assuming they would be in the format like, give fixed v and which operation and b) should affect you.

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

            You would think this is true, except as it turns out if the only layer of defense you use is mt19937 + chrono steady clock, you actually can get hacked! mt19937 is actually very well known for being hackable if you learn enough information about the state, so at the very least a naive implementation that would work as it is in a hackless environment shouldn't work. There is a stronger random you can use to defend against this, but we're getting to the point where the crux of the problem becomes a cryptography check and not an algorithms check.

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

              Oh that's interesting. What part of it is weak? I know that mt19937 is not crypto-secure but it should be good enough for this case right?

              Here are all the attacks I am aware of:

              1. You can predict all the seeds for the next 10^5 nanosecs and build your case around them but that doesn't seem likely.
              2. You can reverse-engineer and predict the generation. Doesn't appear to be useful here since you have to submit your case before learning anything useful about the generator.
              3. That's it lol
              4. Use /dev/urandom?
              • »
                »
                »
                »
                »
                »
                »
                »
                4 месяца назад, скрыть # ^ |
                ← Rev. 2  
                Проголосовать: нравится 0 Проголосовать: не нравится
                Oops, this is now a cryptanalysis problem
                • »
                  »
                  »
                  »
                  »
                  »
                  »
                  »
                  »
                  4 месяца назад, скрыть # ^ |
                  ← Rev. 2  
                  Проголосовать: нравится +1 Проголосовать: не нравится

                  I don't think you can do that. I would agree with you iff you could see my first 600ish outputs and then construct your failing test case afterward, but in the hack format, you must specify the complete multitest ahead of time.

                  If the attack model is one where I can generate the next test case based on the previous, then all bets are off, you have to use a CSPRNG that's seeded with good entropy (like from the OS, in this case steady clock will not save you because the attacker can brute force over a few hundred million possible seeds to find which one you used).

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

                  Well, I think it depends on whether or not generator is allowed I believe? I think there have been some cases where generators been allowed, and some cases where hack format is "To hack, manual and write your u/v", but please correct me if this is false. At the very least, any sufficiently evil author could've done this against a weak enough combination (e.g. just a single PRNG like mt19937 or splitmix64 that gets the next seed)

                  But yes, I agree that if the hack format was manual then you would have no way of doing this because you cannot first decrypt the state. I would be included to agree that such a hack rule would've also be fine, if your goal is instead to allow only the hacking of deterministic solutions. So in short, yes I would agree it simply depends on which model the hacks are in.

                  As for the seed, I'm pretty sure that you do have some options to chain together, except your seed gets fed into some ChaCha20 implementation or similar CSPRNG that can cleanly fit on CF. I believe this blog has a strong enough combination that considers start time, process time, and a random pointer value as your initial entropy.

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

                  Editorial has been updated to include a proof that a deterministic solution doesn't exist.

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

    I think it worked out fine because it didn't seem like anyone with a 2^(-29) sol didn't pass, but we probably should have made it 60 bits instead of 30 to make the failure probability much lower than 0.65%.

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

      I think 60 bits might be too much because then splitting in half would've worked. I think 0.65% is probably fine although I would definitely crash out if I WA23'd or something like that after waiting like 2 mins to judge lol. Maybe 40 bits could've been better but I also would have to admit that it does kinda risk exposing the answer (since 30 bits seems like your typical constraint that doesn't mean anything obvious). Overall E is super absolute cinema I liked it a lot

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

    I asked whether adaptive value of v depends on ty, and recieved the same answer lol

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

Good contest and fast editorial. Upvoted.

Although it's sad to see how far off the ratings are gonna be from those predictions, due to all the cheaters and such (at least that's what it seems like after checking the ratings on clist). Well, it does make me feel better about my performance ngl.

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

From no where C is going to be 1600-1700 . It would be around 1300-1400 .

Either author misjudged the difficulty of the problem or mass usage of AI by participant affected its rating a lot .

The same apply for B.

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

i like d(even tho i couldnt solve it in contest)

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

how fast

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

c get wrong just becasue not using mod in final ans (crying emoji crying emoji)

»
4 месяца назад, скрыть # |
 
Проголосовать: нравится -6 Проголосовать: не нравится
An Informal E Bonus for Hackers
»
4 месяца назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

C is straightup from some math olympiad.

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

Btw D can be solved in $$$O(n\log A)$$$ using prefix minimum

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

    Can you explain? And are you counting the cost calculation (with bitcount and popcount) as O(log A)? Because if you count it as O(1) instead then the solution described in the editorial is already O(n log A).

    (And if we count the cost calculation as O(log A) then the whole analysis becomes more complex because technically addition is logarithmic in the length of the integers involved too.)

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

      This requires one more observation. First we fix the LSB to be at least $$$x$$$ for all numbers. It is always optimal to pick the minimal number at least $$$a[i]$$$ that has that LSB. You can precompute all of these values and their cost for every element.

      This is true to get a number with the same LSB that’s different, you must first go through a number with a greater LSB which is smaller.

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

        OK but how does this reduce the time complexity?

        What is the complexity you claim for that algorithm, assuming arithmetic operations including bitcount and popcount are $$$\mathcal{O}(1)$$$?

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

      The editorial's solution is $$$O(n\log^2 A)$$$ with $$$O(1)$$$ cost calculation; it does a search over both $$$k$$$ and $$$b$$$, both of which are $$$O(\log A)$$$.

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

        No, because it only considers the values of $$$b$$$ between $$$0$$$ and $$$\log A$$$ that are divisible by $$$2^k$$$.

        Take a look at this submission, which uses no precomputation: 382321482. I claim it performs only $$$\mathcal{O}(n\log A)$$$ calls to Cost() and other trivial arithmetic operations per test case. (using $$$A = \max a_i$$$).

        This follows from the fact it has three nested loops:

            for k in range(ceil(log2(max(A))) + 1):
                ...
                for x in A:
                    ...
                    for i in range(1, min_cost >> k):
                        ...
        

        The first loop is clearly $$$\mathcal{O}(\log A)$$$.

        The second is clearly $$$\mathcal{O}(n)$$$.

        For the third loop, consider that min_cost = $$$\mathcal{O}(\log A)$$$, but the right shift means it is halved each time $$$k$$$ is incremented, so the total time complexity is: $$$\mathcal{O}(n×\log A + n×(\log A)/2 + n×(\log A)/4 + n×(\log A)/8 + ... + n×1) = \mathcal{O}(n×2×\log A) = \mathcal{O}(n \log A)$$$.

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

          You are right. If carefully implemented and analyzed the editorial solution is also $$$O(nlogA)$$$. We were describing a different way to implement it.

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

My post contest discussion stream for ABCD can be found here

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

Upsolving E, I saw that failing submission feedback has a "model solution interaction log". Is this new? I have solved interactive problems in the past and never seen something like this. IMHO this is too big of a hint and spoiled this solution. Is there a way to disable this (but keep my own interaction log)?

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

In B solution, why does the alternating sum need to be -1 for the positive elements? should not need to be +1?

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

    It's technically correct, but I can see why it is confusing. If you take an odd number from the $$$-1$$$ group, then the alternating sum after that would start with a negative. So that negative alternating sum would need to be $$$+1$$$ overall. However, the way we defined alternating sum is that it starts with a positive number, so we can just negate the value we need to reach and use the same term.

    Does that make sense?

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

I really liked C! I didn't realise that #ways to pick even number = #ways to pick odd number and that made my solution a lot more complex :P

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

For E, can the interactor determine $$$v$$$ based on one of the previous $$$ \lt t$$$ test cases?

If not, could save a bit of coding time by just hardcoding a random value

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

B is really hard

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

C was so good

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

B is nice problem.

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

Anyone got a small hint for Problem F?? I'm implementing the greedy approach in Python, but it keeps giving WA on test 2. The checker says a valid solution exists, while my code prints -1. The issue seems to be around this part:

while found > l:
    if found + 1 >= r:
        do_op(found)
        found -= 1
        continue
    do_op(found + 1)
    found -= 1

I've been debugging for quite a while but still can't spot the mistake. Am I missing an edge case, or is my greedy approach fundamentally flawed? A small hint would be really appreciated!

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

I have a much more complicated solution for B. consider this array $$$a$$$:

$$$\frac{1}{1}$$$ , $$$\frac{1}{1} - \frac{1}{2}$$$ , $$$\frac{1}{2}-\frac{1}{3}$$$ , $$$\frac{1}{3}-\frac{1}{4}$$$ , ... $$$\frac{1}{n-1} - \frac{1}{n}$$$ , $$$\frac{1}{n}$$$

The sum of this array is $$$2$$$. Since $$$\frac{1}{i-1} - \frac{1}{i} = \frac{1}{i \times (i-1)}$$$ , we can find out $$$ 2 \div \frac{1}{i \times (i-1)} = 2 \times i \times (i-1)$$$ is an integer. That satisfy division constraint.

So it seems that we can multiply each $$$a_i$$$ by $$$lcm(1,2,...,n)$$$ to get an integer array. But for n up to 50, $$$lcm(1,2,...,50) = 3099044504245996706400 \gt 10^{17}$$$ , which is too large.

To decrese the lcm , we can delete some big primes $$$p$$$ (like 31,37,...). To do this, we can replace ($$$\frac{1}{p-1} - \frac{1}{p}$$$ , $$$\frac{1}{p} - \frac{1}{p+1}$$$) with ($$$\frac{1}{p-1} - \frac{1}{p+1}$$$) so $$$p$$$ wouldn't appear in lcm and we would't violate division constraint.

Another issue is sometimes $$$\frac{1}{n}$$$ would equal to $$$\frac{1}{i}-\frac{1}{i+1}$$$ (like $$$i=2,n=6$$$) , but we can handle it by change $$$n$$$ to $$$n-1$$$ or $$$n+1$$$.

implement here (with many hardcode number):382360757

This make me wonder what the minumum value of the maximum $$$a_i$$$ among all valid $$$a$$$ with length $$$n$$$. maybe a bonus? Is it doable?

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

i have a doubt in D, say i have fixed X zeros in the suffix of the binary rep. of each number.(now Alice can divide the whole array for atleast X times before any odd number appears in the array)

say, the transformed array is B ,WHY do i have to check for some more numbers in the range [B[i],B[i]+32] , like what advantage does it give? can't i just check for B[i] and move on? (any examples where it helps?)

My A/C submission with this extra check

My submission Without this extra check,(WA on tc3)

Thanks!!

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

    try

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

    I struggled with this as well. Here is my reasoning:

    For a fixed $$$k$$$ and $$$a[i]$$$ we want to zero the first $$$k$$$ bits of $$$a[i]$$$. Define $$$p = 2^k$$$ as the least power of 2 greater than or equal to $$$a[i]$$$.

    Alice is left to choose some $$$b$$$ such that $$$b \geq a[i]$$$ and $$$b \equiv 0 $$$ (mod $$$p$$$).

    The cost after such incrementing to b is $$$(b - a[i]) + opCount(b / p)$$$. We wish to minimize this function.

    The important observation is that opCount is NOT a smooth function.

    It is often smooth: for example opCount(6) = 4 and opCount(7) = 5.

    However, consider that opCount(127) = 13 yet opCount(128) = 8.

    Thus simply choosing the least multiple of $$$2^k$$$ may or may not be optimal.

    I'd be curious to see if there's a less brute force way of finding the optimal choice of $$$b$$$ besides just trying $$$a[i]$$$ + $$$d \in [0, 32]$$$.

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

you should provide the source code at the end always

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

It's a little surprising that the difficulty of problem E is probably above 2600 which may(I think) contradict with what authors and testers had predicted.

If the final ratings are 800 — 800 — 1300 — 1800 — 2600 — 2800 as clist shows,It will give out

1.The biggest D~E difficulty gap so far in 2026.

2.The most complex counting problem on C which is just 1300.

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

    The fact that C is 1300 is crazy to me. We weren’t very worried about the D -> E gap and were very worried about the B -> C gap.

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

      I feel that a difficult problem showing up early in a contest pushes people to cheat. If somebody gets stuck on E or F, it's an "oh well I will place fine". When people are at risk of going 2/6 on a contest, they panic and turn to AI.

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

      C really needs observation for at least experts, and maybe a bit math (or you'll enumerate c(cnt,an even number) to calculate 2^{cnt-1} and write a code which is hard to debug like me) so it's crazy for it to be 1300.

      I think there are many participants using ai so that the difficulty is much lower than we think.

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

    no way, I almost got the idea on E on a virtual contest, and spent the current last 3 hours understanding D

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

In F the second case can also be solved with 4 operations:

  • op(2) The permutation becomes [n, n-1, 2 ,…, n-2, 1]
  • op(1) The permutation becomes [n, 2,…, n-2, 1, n-1]
  • op(n-1) The permutation becomes [1, n, 2 ,…, n-2, n-1]
  • op(1) The permutation becomes [1, 2,…, n-2, n-1, n]
»
4 месяца назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

So I still don't understand how to solve C.

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

D > E

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

In case someone finds this useful, I had a different approach to problem D.

First, we try to solve without Alice's initial moves.

For each $$$a_i$$$, it will be decremented a certain number of times (say $$$u(i)$$$) and divided by 2 a certain number of times (say $$$v(i)$$$).

There's no way for Alice to decrement more than one number at a time, so she will definitely have to do at least $$$\sum_{i=1}^{n} v(i)$$$ operations, and at most $$$\sum_{i=1}^{n} u(i) + v(i)$$$. Next, if Bob can always ensure that an odd number is second in the array, we can see that this maximum value will be reached. As soon as there is any odd element in the array, we can see that Bob will always be able to make swaps so that it is second.

Therefore, the game after the initial part of the array consists of two parts.

PART 1: all $$$a_i$$$ are even, there is nothing Bob can do to prevent Alice from getting $$$n$$$ divisions by 2 for the cost of only one operation.

PART 2: there is at least one odd element of $$$a$$$. On his turn, Bob can always swap this element into the second position, meaning that Alice gets to do only one division.

Now we can find the answer for a fixed array (with no initial operations).

First, let's say $$$S = \sum_{i=1}^{n} u(i) + v(i)$$$ (note since the $$$a_i$$$ aren't big we can precompute $$$u(x) + v(x)$$$ for all possible $$$x$$$). We find the biggest power of 2 that divides all $$$a_i$$$ (say $$$p$$$) and we know that Alice will get to do $$$n log(p)$$$ operations in only $$$log(p)$$$ steps, and will have to do all the other operations separately. Therefore, Alice will be able reach an empty array in $$$S - (n - 1) log(p)$$$ operations.

Now, we have to figure out how Alice can do better by using her initial moves to increment the numbers. We'll consider 17 different possible values of $$$p$$$ (from $$$1$$$ to $$$2^{16}$$$, since $$$2^{17}$$$ is too far above $$$10^5$$$). For each possible value of $$$p$$$, we have to go through $$$a_i$$$ and consider the cost of incrementing $$$a_i$$$ to a nearby value of $$$p$$$.

Why "nearby" and not just the next multiple of $$$p$$$? Consider $$$p=1, a_i = 15$$$. Even though $$$a_i$$$ is already divisible by $$$p$$$, $$$u(16) + v(16) + 1 \lt u(15) + v(15)$$$, so its worth increasing $$$a_i$$$ to 16. Checking with a bruteforce, I found that for $$$a_i \lt 10^5$$$, the maximum $$$k$$$ such that there exists $$$x \le 10^5 : u(x) + v(x) \lt u(x + k) + v(x + k) + k$$$ is $$$k = 11$$$, so for each $$$a_i$$$, we only have to check multiples of $$$p$$$ within 11 of the very next multiple of $$$p$$$.

To summarise, we just have to go through the 17 values of p and for each one find the total cost of increasing all the $$$a_i$$$ to the optimal value near to the next multiple of $$$p$$$, and take the minimum of these 17 values.

Submission: 385742595

P.S.: thanks to authors for a really great contest!

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

Is it just me or just B is just hard for its rating? Or just contests getting harder over time? or maybe i am just trash

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

it took me a while to figure it out for C , i was first overcomplicating by thinking of using modulo inverse but then i realised # of ways to even numbers = # of ways to choose odd number , no-way this is 1400 problem.