0mar's blog

By 0mar, 7 weeks ago, In English

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++
  • Vote: I like it
  • +72
  • Vote: I do not like it

»
7 weeks ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

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

»
7 weeks ago, hide # |
 
Vote: I like it +2 Vote: I do not like it

B was so good, I like it

»
7 weeks ago, hide # |
Rev. 2  
Vote: I like it +4 Vote: I do not like it

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

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

    What is your failure probability? There are 40 pretests.

    • »
      »
      »
      7 weeks ago, hide # ^ |
      Rev. 3  
      Vote: I like it +1 Vote: I do not like it

      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

      • »
        »
        »
        »
        7 weeks ago, hide # ^ |
         
        Vote: I like it -7 Vote: I do not like it

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

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

          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.

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

            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.

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

              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?
              • »
                »
                »
                »
                »
                »
                »
                »
                7 weeks ago, hide # ^ |
                Rev. 2  
                Vote: I like it 0 Vote: I do not like it
                Oops, this is now a cryptanalysis problem
                • »
                  »
                  »
                  »
                  »
                  »
                  »
                  »
                  »
                  7 weeks ago, hide # ^ |
                  Rev. 2  
                  Vote: I like it +1 Vote: I do not like it

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

                • »
                  »
                  »
                  »
                  »
                  »
                  »
                  »
                  »
                  7 weeks ago, hide # ^ |
                   
                  Vote: I like it -16 Vote: I do not like it

                  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.

                • »
                  »
                  »
                  »
                  »
                  »
                  »
                  »
                  »
                  7 weeks ago, hide # ^ |
                  Rev. 2  
                  Vote: I like it +11 Vote: I do not like it

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

  • »
    »
    7 weeks ago, hide # ^ |
     
    Vote: I like it +8 Vote: I do not like it

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

    • »
      »
      »
      7 weeks ago, hide # ^ |
       
      Vote: I like it +8 Vote: I do not like it

      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

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

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

»
7 weeks ago, hide # |
Rev. 2  
Vote: I like it +1 Vote: I do not like it

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.

»
7 weeks ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

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.

  • »
    »
    7 weeks ago, hide # ^ |
     
    Vote: I like it +14 Vote: I do not like it

    C felt 1800 to me. It's quite hard, it's not your standard DP, you have to make some extra observations (like how if you have an odd number of elements you have to have an odd number of -1s and everything must be paired up except for one pairwise difference which must be +1) and then do 2 cases.

    • »
      »
      »
      7 weeks ago, hide # ^ |
       
      Vote: I like it +3 Vote: I do not like it

      there is no dp in C? you just need a basic understanding of combo to know that sum of even binominal coefficients is the same as sum of odd binomial coefficients.

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

        Oh idk. I did it super scuffed DP way (you can check my submission lol). I thought of calculating directly with math but it seemed way too complicated when you have a case like -1 [2 2] [4 4] [5 6] [9 9]

        • »
          »
          »
          »
          »
          7 weeks ago, hide # ^ |
           
          Vote: I like it +3 Vote: I do not like it

          You can first just calculate the total for cases where each element appears even no. of times by just multiplication of even possibility for each element which is just (nC0 + nC1 + nC2 + ... ) which is just 2^(n — 1). For the case where -1 appears once and some consecutive elements appear odd times, just add the even possibility value / even possibility of -1 * frq of -1. Maybe I over complicated it

    • »
      »
      »
      7 weeks ago, hide # ^ |
       
      Vote: I like it +3 Vote: I do not like it

      C felt like 1600ish rating to me when I did with math. CLIST predicts it will be 1300 though TwT

    • »
      »
      »
      7 weeks ago, hide # ^ |
       
      Vote: I like it +3 Vote: I do not like it

      Difficulty of this problem depends a lot on "boldness" of font of this text: "array is non-decreasing" :)

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

    i figured out B somehow, but what was that question C? I feel like authors are trying to put harder problems at C nowadays to counter cheaters but legitimate users are being screwed this way.

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

    I think a lot of people used AI because the problem looks like it should be rated around 1800. After the contest, I asked ChatGPT how to solve it and to rate that problem and it said it should be around 1800-2000.

»
7 weeks ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

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

»
7 weeks ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

how fast

»
7 weeks ago, hide # |
 
Vote: I like it +3 Vote: I do not like it

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

»
7 weeks ago, hide # |
 
Vote: I like it -6 Vote: I do not like it
An Informal E Bonus for Hackers
  • »
    »
    7 weeks ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    In fact, the first question is already answered in the editorial, because you will know how the solution determine m_0 and m_1. Thus, the second question has no solution.

»
7 weeks ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

C is straightup from some math olympiad.

»
7 weeks ago, hide # |
 
Vote: I like it +32 Vote: I do not like it

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

  • »
    »
    7 weeks ago, hide # ^ |
     
    Vote: I like it +3 Vote: I do not like it

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

    • »
      »
      »
      7 weeks ago, hide # ^ |
       
      Vote: I like it +3 Vote: I do not like it

      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.

      • »
        »
        »
        »
        7 weeks ago, hide # ^ |
         
        Vote: I like it +3 Vote: I do not like it

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

    • »
      »
      »
      7 weeks ago, hide # ^ |
       
      Vote: I like it +4 Vote: I do not like it

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

      • »
        »
        »
        »
        7 weeks ago, hide # ^ |
         
        Vote: I like it +6 Vote: I do not like it

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

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

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

»
7 weeks ago, hide # |
 
Vote: I like it +1 Vote: I do not like it

My post contest discussion stream for ABCD can be found here

»
7 weeks ago, hide # |
 
Vote: I like it +10 Vote: I do not like it

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

»
7 weeks ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

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

  • »
    »
    7 weeks ago, hide # ^ |
    Rev. 4  
    Vote: I like it 0 Vote: I do not like it

    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?

»
7 weeks ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

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

»
7 weeks ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

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

»
7 weeks ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

B is really hard

»
7 weeks ago, hide # |
 
Vote: I like it +1 Vote: I do not like it

C was so good

»
7 weeks ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

B is nice problem.

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

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!

»
7 weeks ago, hide # |
 
Vote: I like it +1 Vote: I do not like it

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?

  • »
    »
    7 weeks ago, hide # ^ |
    Rev. 2  
    Vote: I like it +1 Vote: I do not like it

    I think I have construction for $$$a_i \leq 840$$$. I'll edit when I confirm it works.

    Edit: see the following submission: 382388477

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

      Can i know the logic behind your hardcoded value or its just satisfying the condition somehow ???

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

        Maybe it's dp approach like this

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

        Not completely sure; the construction is mostly found by optimized brute force. That being said, I came across many recurring values, so it seems that there are some desirable properties that lend themselves to small constructions. I guess the most obvious property is that numbers with a lot of divisors tend to work well as the sum, but there are probably some other ones that help.

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

      hell yeah

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

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

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

    try

    1
    2
    1 15
    
  • »
    »
    7 weeks ago, hide # ^ |
     
    Vote: I like it +3 Vote: I do not like it

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

»
7 weeks ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

you should provide the source code at the end always

»
7 weeks ago, hide # |
 
Vote: I like it +1 Vote: I do not like it

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.

  • »
    »
    7 weeks ago, hide # ^ |
     
    Vote: I like it +8 Vote: I do not like it

    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.

    • »
      »
      »
      7 weeks ago, hide # ^ |
       
      Vote: I like it +3 Vote: I do not like it

      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.

    • »
      »
      »
      7 weeks ago, hide # ^ |
       
      Vote: I like it +8 Vote: I do not like it

      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.

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

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

»
7 weeks ago, hide # |
Rev. 2  
Vote: I like it +11 Vote: I do not like it

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]
»
7 weeks ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

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

»
7 weeks ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

D > E

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

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 weeks ago, hide # |
Rev. 2  
Vote: I like it 0 Vote: I do not like it

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