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

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

Unfortunately, the round turns out to be very unbalanced :( I'm deeply sorry about this issue.

I hope you still enjoy the problems.

Rate the contest! (definitely not copied from past contests)

2134A - Painting With Two Colors

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

2134B - Add 0 or K

There are (at least) two solutions to the problem. Vote for your solution!

How did you solve the problem?
Hint 1
Hint 2
Solution
Code for solution 1 (C++)
Code for solution 1 (Python)
Code for solution 2 (C++)
Code for solution 2 (Python)
Rate the problem!

2134C - Even Larger

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

2134D - Sliding Tree

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

2134E - Power Boxes

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

2134F - Permutation Oddness

Thanks to Misuki for coming up with a better solution! My original solution has a much larger constant.

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

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

Speedforces, but still better than no contest. Thanks for the contest!

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

thanks for speedy editorial for speedyforces round

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

Only if the writers had swapped D and E

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

deleted

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

Fun round, problems were really nice. I think I also hit Master for the first time! Somehow I bricked A for an eternity and thought that I was on the path to a total disaster...

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

Who got stuck on D and didn't see E?

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

wow that D problem was out of this world

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

Nice solution for D, the "diameter increment" property is a very interesting "invariant". I wish I had observed it during the contest.

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

Very nice problems but E was by far too easy. Obviously easier than D and arguably even div2C difficulty

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

Queueforces, but great problem, thank you!!

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

Swapping D and E makes a lot of sense. Wasn't it the case with testers?

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

    My original proposal was D and E swapped. During testing we found the gap between C and D (which is current E), so we decided to swap DE but E got nerfed to only output the minimum number of operations. Most testers tested with this version, and it seemed like the right difficulty. Then ~10 days before the contest my coordinator advised me to add the first operation output and made the current problem set.

    So I don't know, maybe the first operation output really adds a lot to the problem, or the gap is still huge even with current DE swapped, it is really hard to tell.

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

    D was very easy for me, maybe because initially I started to consider the diameter of the tree and understood that optimal operation will increase diameter with one.

    I am surprised that the problem D is hard for the most participants.

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

Can anyone tell why this is giving wrong answer https://mirror.codeforces.com/contest/2134/submission/335699285

It works on my VSCode :(

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

C is too easy to guess, especially when D is this hard

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

Couldn't solve D but the idea is so cool.

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

Does there exist $$$O(n^2)$$$ or $$$O(n^2logn)$$$ solution for F? The last convolution can be speed up but I am not sure how to speed up the other part.

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

    I am not sure about convolution, but I was trying generating functions for $$$dp[c0][c1][c2][c3][len][last\_symbol]$$$, and you can create it with 5 vars for $$$c0, c1, c2, c3, len$$$, and 4 functions for $$$last\_symbol$$$, and there will be a very unpleasant system, $$$l = len$$$:

    $$$F_0 = a(1 + l^0F_0 + l^1F_1 + l^2F_2 + l^1F^3)$$$ $$$F_1 = b(1 + l^1F_0 + l^0F_1 + l^1F_2 + l^2F^3)$$$ $$$F_2 = c(1 + l^2F_0 + l^1F_1 + l^0F_2 + l^1F^3)$$$ $$$F_3 = d(1 + l^1F_0 + l^2F_1 + l^1F_2 + l^0F^3)$$$

    Maybe if you solve it, there will be explicit and efficient formula for coefficients.

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

      I am not sure if this direction even works. I was trying to optimize the first part of editorial

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

        Sorry for the late reply, but it seems that we can solve F in $$$\mathcal{O}(n^2 \log n)$$$ time with an adaptation from maspy's write-up.

        Let's define $$$r'_{i,j}$$$: number of ways to arrange $$$c_0$$$ zeros and $$$c_2$$$ twos into $$$i$$$ segments, so that the total number of adjacent pairs inside all segments is $$$j$$$.

        Let's calculate $$$r'_{i,j}$$$ in increasing order of $$$i$$$. For $$$i = 1$$$ it's easy. For $$$i \gt 1$$$, we try to take a combination of $$$i - 1$$$ segments and make one more split to make $$$i$$$ segments. We have the following formula:

        $$$r'_{i,j} = (j + 1) \cdot r'_{i - 1, j + 1} + (c_0 + c_2 - 1 - j) \cdot r'_{i - 1, j}$$$

        This is simply the addition of two cases whether the split happens at an adjacent pair with same/different numbers.

        However $$$r'_{i,j}$$$ is not the real count. We have to divide it by $$$i!$$$ because we overcount each way of splitting by $$$i!$$$ times.

        Therefore $$$r_{i,j}$$$ can be calculated in $$$\mathcal{O}(n^2)$$$ time and the whole algorithm runs in $$$\mathcal{O}(n^2 \log n)$$$ time.

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

Hold on, im new here, so the contest is not rated?

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

Despite my performance in this contest was good, but frankly this one is speedforces. Don't be surprised if you find a specialist outperformed or a CM underperformed.

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

Thanks for the contest ! , I think I'll finally Be MathModel , It was a fun speed run.

A is good.

B was funny , The construction is $$$a_i:=a_i+(a_i \bmod (k+1) \cdot k)$$$ , my favorite problem of the round.

C good as well.

Given that speed running , I wonder how I'm estimated to get expert because I feel like I'm far from expert smh.

Funny round , Thanks henotrix !

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

    This might be stupid, but how does someone come up with this elegant looking formula for B.

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

      number theory stuff & do some test cases with hand, the desired gcd is a number you can reach with adding ks from 0 to k times, so number of possible variations for an element is k + 1, so if we set out desired gcd to be k + 1, we can change an element's mod over k + 1 however we want since each time we add k the number's mod decreases by 1, we want to make all elements 0 mod (k + 1) so if an element is cong. to a % (k + 1) we add k (a) times

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

I solved E 15 minutes after contest. It was such a cool problem, but my coding skills really need to be improved.

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

C felt much easier than B.

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

For D, we can construct the whole operation sequences in $$$\mathcal{O}(n)$$$.

Code

And implement the checker in $$$\mathcal{O}(n\log^2n)$$$

Part of checker

If the problem D is changed to this, how would it be rated in the cf rating?

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

Why was there no hacking phase? For people in Python doing B and doing naive modulo each element, you could make a brutal test with a lot of testcases, with k very huge and odd, and the mod step taking a long time, and every element in the arrays odd so that there was a better solution, but you didn't implement it, there would be a TLE IMO unless I am mistaken.

Edit: I underestimated Python lol. But, it would definitely trip people using print for huge numbers.

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

C is pretty good, it took me quite a while to sol. Wonder why everone got it so quickly?? anyway, thanks for the contest :3

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

Almost got E. Spent too much on D but failed. Only little time left to figure out how to determine a[1] when the length is an odd number...

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

i dont know how the hell in B $$$ a_i + k*c_i \equiv c_i + k*c_i $$$ why $$$a_i = c_i$$$

can some explain it to me

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

    we defined c_i = a_i % (k + 1), hence a_i and c_i are congruent modulus (k + 1)

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

    What is c[i] bro? I dont understand what did u said..

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

      Consider this: you want all of the indices $$$a_i$$$ to have some common factor. So, you can either add 0 or add k to $$$a_i$$$. Hence, we can say that $$$a_i \leftarrow a_i + c_i*k$$$ where $$$c_i$$$ depends on what $$$a_i$$$ is. Now one observation that can be made is that if you take $$$c_i=a_i \mod k+1$$$, you can write your new assigned $$$a_i$$$ as $$$ a_i + (a_i \mod k+1)*(k+1-1)$$$ which further simplifies to $$$(a_i - (a_i \mod k+1)) + (k+1)*(a_i \mod k+1)$$$ which you can see is divisible by $$$k+1$$$. So, we can assign such an $$$a_i$$$ to each of the element, so that that it becomes divisible by $$$k+1$$$. Also notice our factor with k is $$$a_i \mod k+1$$$ which is less than or equal to $$$k$$$, so we are at most only doing k operations.

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

No worries about the imbalance. Any contest where the LLM crowd is not on the top of the leaderboard is a good one these days.

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

One of the best contests in CF.

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

is this round or contest is rated or not ?

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

In problem B's editorial, it says, you can also find the smallest integer x such that gcd(x,k)=1. Why should it be coprime with k? I didn't get this point. Can anyone explain this, please

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

    modular inverse of a (mod m) exists only if a and m are relatively prime

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

    I am not sure what coprimes are, but the goal is to find a common divisor (factor) for all of b.

    Lets say we try some x. If x is a (prime) factor of k, then adding k to b, (where k % x==0) will not change the remainder.

    Hence, you have to find a prime p which is not a factor of k (k % p !=0). Thereby you are guaranteed to change the remainder and it will at some point be divisible by p.

    Since k<10**9, you only need to try primes up to 30 or so.

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

    When you have X and K as coprime, and a number A!

    If you keep adding K to A and take modulo X then you'll see that, within X additions, you would have covered all the range 0 to X — 1.

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

i'm not getting that in problem B if we solve by the first approach how we ensure that at the same time the number of operations required are at most k ??

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

swap(B, C); swap(D, E);

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

I have a doubt in the E problem, we are using n throw queries first and then if there are n/2 unknown indices, doesn't that mean we are performing n/2 swap and n/2 throw queries so isn't it total 2n queries or am I mistaken?

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

Can anybody please help me with this D submission? Why does it fail? on pretest 2, test 33

335722832

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

Fun round! Thanks for letting me hit CM orz

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

I want to share some feedback about problem D. I very much like this version of the problem even though it is much harder compared to usual Div2 D. I saw in one of your comments that it was initially about just asking the minimum number of operations. That would be the exact type of problem that I(and hopefully many others) hate because the difference in difficulty between guessing the solution and proving the solution is like 400 points and it basically encourages everyone to guess solutions in contests if they want to improve their rating. I am fine with having an imbalanced round that doesn't have any guess problems. However, if a problem's proof is pretty much of the same difficulty compared to guessing(Example: Today's problem B), then I don't mind it. Thanks for the contest!

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

Could anyone share their motivation behind thinking of the diameter of the tree in problem D (other than taking an educated guess)?

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

The AC rate between ABC and DEF is insane lol

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

A, B and C is too easy, they should be in A, B and C in Div 3

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

Very good contest, the diff between C and D is crazy

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

The time I solved problem A and B beat most people in this contest, cuz I took alomost 2 hours...

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

Please tell me if my approach for Problem D is correct or not

My approach for D The best operation would be: To do the operation from a node with degree > 2 in the direction of the leaf node. Since there could be multiple combinations of leaf nodes and nodes with degree > 2, we need to choose the combination that has the minimum distance between the leaf node and the node with degree > 2.

To find the best combination, I am using BFS simultaneously from all the leaf nodes, and as soon as I encounter any node with the maximum degree, I return the BFS for that particular combination. This, I believe, is O(n) time complexity because I don't add any node in the queue twice.

In my approach b --> node with maximum degree (>2) c --> either a leaf node (if the leaf node is directly connected to b), or a directly connected node in the direction of the leaf node (computed above using BFS) a --> It will be any node directly connected to b (doesn't matter)

But, my solution is getting TLE on TC-2 (335747332)

I believe my solution's time complexity is O(n). Please correct me if I am wrong (Currently, I am not worried if my approach is correct or not; I am more worried about why my solution is giving TLE)

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

Everyone said C is easy, but not in my case :( Maybe im stupid or something but i feel it quite greedy and seem to be wrong. Can someone explain it mathematically?

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

    Try to see that, if the condition of A[i] >= A[i — 1] + A[i + 1], holds true for all such possible values of 2 <= i <= N — 1, then no matter what subarray size you take, it'll never be violated.

    During Update you just need to make sure the gap of A[i] — (A[i — 1] + A[i + 1]), should be first used to reduce the A[i + 1] to the very extreme untill it reaches zero if it's possible, so that you can get the benefit for the later 3 length subarray segment {A[i], A[i + 1], A[i + 2]}

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

In editorial for 2134B - Add 0 or K the statement "take $$$k+1$$$ as $$$g$$$" seems not very trivial to me, but note $$$\{0.k, \dots, k.k\}$$$ is a complete residue system modulo $$$k+1$$$, which means by adding these to a set of numbers you can always make them divisible by $$$k+1$$$. That's how I got it. maybe you find it useful.

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

No, my rating drops after I participated in this contest!

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

bruh i solved D when the contest got only 20 minutes to end.

I feel lucky to solve it but also sad because i didn't see E.

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

Problem B is so-so good

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

How does the checker for problem D works??

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

    I think it calculates the set of element that satisfies b is on the diameters(if many, then any of it) ,a is connected to b and on diameter too, c connected to b.Then it check if your answer is on the set. I guess the element have to be on the set ,any other operations cannot expand the diameter therefore would fail to reach the minimum numbers of operations.

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

    If the diameter's length increased after performing an operation, operation was optimal.

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

I spent a long time on problem B and solved it with exgcd

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

Should swap E and D.I solved the first three problems very fast and tried very hard to solve D in the remaining time but failed, didn't even look at E...After contest find E is easier than D..(D's property about diameter is really hard to notice).Anyway thanks for the contest!

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

According to me the question statement for D was incorrect.. it was written that every neighbour of 'b' will be slided to 'c', but in the solution we can slide each neighbour independently to either 'b' or 'c'..! The question was not well framed..!^⁠_⁠^

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

I have a slightly different solution for problem E that only does one pass.

Start by finding $$$a_n$$$ and $$$a_{n-1}$$$. Also find $$$a_{n-2}$$$ if $$$n$$$ is odd. This can be done in $$$3$$$ or $$$5$$$ operations. (always query $$$n-1$$$).

Now assume you know $$$d_i$$$ and $$$d_{i+1}$$$. You want to use at most $$$3$$$ queries to find $$$a_{i-1}$$$ and $$$a_{i-2}$$$ (and then find corresponding $$$d$$$).

Case 1: $$$d_i = d_{i+1} \implies$$$ query $$$i-2$$$. If the answer is $$$d_i + 1$$$ then $$$a_{i-2} = 2$$$, otherwise it is $$$1$$$. Swap $$$i-2$$$ and $$$i-1$$$ and redo the query. In total we have $$$3$$$ queries.

Case 2: $$$d_i \neq d_{i+1} \implies$$$ query $$$i-1$$$. If the answer is $$$d_i$$$ then $$$a_{i-1} = 2$$$, otherwise it is $$$2$$$. Swap $$$i-2$$$ and $$$i-1$$$ and redo the query. In total we have $$$3$$$ queries.

You figured out $$$2$$$ values in $$$3$$$ queries. The total is $$$\frac{3n}{2}$$$ for even $$$n$$$ and $$$\frac{3n+1}{2}$$$ for odd $$$n$$$.

This is basically the same solution given in the editorial, but only one pass is required.

I wonder if there is a strategy that can do better in general (i.e. no matter the original configuration do at most $$$\left\lceil{\frac{3n}{2}}\right\rceil-1$$$)

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

Why not swap D and E

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

I solved 2134B - Add 0 or K using a slightly different approach.

Let's recall $$$g$$$ as some integer $$$ \gt 1$$$ such that each $$$a_i + k \cdot c_i$$$ is divisible by $$$g$$$ then:

$$$\begin{align} a_i + c_i\cdot k \equiv 0\ (mod\ \ g) \\ c_i\cdot k \equiv -a_i\ (mod\ \ g) \end{align}$$$

Now, we need to apply Fermat's Little Theorem. So, $$$g$$$ and $$$k$$$ must be coprime.

$$$\begin{align}c_i \equiv -a_i \cdot k^{\ g\ -\ 2}\ (mod\ \ g)\end{align}$$$

The immediate value for $$$g$$$ that came to my mind is $$$k + 1$$$ as $$$gcd(k,\ k + 1) = 1$$$. So,

$$$\begin{align}c_i \equiv -a_i \cdot k^{\ k\ -\ 1}\ (mod\ \ k + 1)\end{align}$$$

Then the smallest $$$c_i$$$ that satisfies the equation is $$$(-a_i \cdot k^{k\ -\ 1})\ \%\ (k + 1)$$$, and the final answer is:

$$$a_i ← a_i +[(-a_i \cdot k^{k-1})\ \ \%\ \ (k + 1)] * k$$$

I hope my explanation is clear :) I know that I overthink it, but this is the first approach that came to my mind, and it took me a lot of time to verify during the contest.

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

Problem E is clever!

I will write down my initial approach, which gives correct answer, but exceeds the query limt (at max $$$2n-1$$$ queries) Observations: $$$\newline$$$ $$$(1)$$$ It is easy to see that throwing at coordinate $$$n-1$$$, will directly reveal $$$a_{n-1}$$$ (infact its given as hint 1) $$$\newline$$$ $$$(2)$$$ If $$$jumps[i+1] \ne jumps[i+2]$$$, then we can determine $$$a_i$$$ in exactly one query. $$$\newline$$$ $$$(3)$$$ If we write down $$$jumps[i]$$$, then if $$$jumps[i] = jumps[i+1] \implies jumps[i+1] \ne jumps[i+2]$$$ $$$\newline$$$

Now, my algo was as follows: $$$\newline$$$ 1) Query $$$throw \, n-1$$$ [uniquely determines $$$a_{n-1}$$$ from observation $$$(1)$$$ ] $$$\newline$$$ 2) Perform $$$swap \, n-1$$$ and $$$throw \, n-1$$$, this will determine $$$a_n$$$ and $$$jumps[n]$$$ $$$\newline$$$ 3) For $$$i = n-2 \, \text{to} \, 1$$$, if $$$jumps[i+1] \ne jumps[i+2]$$$, query $$$throw \, i$$$ and get $$$a_i , jumps[i]$$$, else : $$$swap \, i$$$, and query $$$throw \, i+1$$$ and get $$$a_i$$$.

$$$\newline$$$ The trouble? It exactly follows the observations as the editorial, but in the worst case, it can go in the else part of step 3, for every $$$i$$$, thus giving $$$2n-1$$$ queries :(

Spoiler

Though, my idea and observations were the same, but this way you would exceed queries :(

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

    My solution is quite similar to yours but doesn't exceed query limit. It is easy to show that if throws[i + 1] == throws[i + 2] then a_{i-1} can be determined in one query.

    Mine is

    1) Find out a_n and a_{n-1} in the same way as you.

    2) Then for i = n — 2 to 2:


    if throws[i + 1] != throws[i + 2] determine a_i in one query continue else throw i - 1 update a{i-1} swap i - 1 throw i - 1 update a{i} i = i - 1

    Similarly determine a_1 in the case of odd n.

    Since I either use 1 query per element or 3 queries for 2 elements. The total queries is bounded by ceil(3n/2).

    Code

    This fails on TC140 in Test 2 and I have no idea why.

    Can someone help me fix it?

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

      I think I was doing a similar mistake, when you perform swap, you are actually swapping the values of $$$a_i$$$, but when outputting, are you making sure to output the original $$$a$$$ and not the swapped one?

      PS: I checked your code on some manual test case, it works fine, maybe you can try some edge cases, logic looks fine, you might be doing something silly.

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

    If you know jumps[i+2] and jumps[i+3], you can work out positions i and i+1 in 3 operations:

    • If jumps[i+2] == jumps[i+3], you can work out position i, swap positions i and and i+1, and work out the new value at position i once more.
    • If jumps[i+2] != jumps[i+3], you can work out position i+1, swap positions i and and i+1, and work out the new value at position i+1 once more.

    This uses 3 queries for every 2 values.

    At the end we might might be left with position 1 if n is odd, but we have two queries to play with. If jumps[2] != jumps[3], we can query position 1 directly, otherwise we swap positions 1 and 2 and query the new position 2 (as jumps[3] and jumps[4] must be different in this case).

    Note that we can set jumps[n+1] = jumps[n+2] = 0 to make things easier.

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

In problem 2134B - Add 0 or K, can anyone explain why $$$a_i ← a_i + k⋅(a_i\ mod (k+1))$$$ is correct?

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

After reading the editorial --> D is such an amazing problem.

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

For problem b, I didn't get it why k+1 is the best gcd, can anyone explain please

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

Can anyone tell me why my F code always gets TLE on test #16? Is it just me? If it is not, I dreadfully need a tutorial to optimize constant.

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

guys why in problem B we can say, that (ai + k ⋅ ci ≡ ci + k ⋅ ci)? a[i] = c[i]?

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

I have a solution for problem E that seems slightly simpler in my opinion: going backwards from n to 1, consider pairing adjacent indices, and we will attempt to solve the values for each of the pairs in 3 queries. If n is odd, we shall simply try to solve for i=1 in 2 queries after having solved for the rest of the indices.

I maintain two arrays, val[1..n] and dp[1..n + 2], where val[i] is the value of the i th index and dp[i] corresponds to the value of the throw(i) (in the current hidden array configuration) for i <= n, and dp[n + 1] = dp[n + 2] = 0.

I also maintain the list of swaps that are made, and in the end I shall go in the reverse order of this list to restore the original array.

For each pair (i + 1, i) belonging to {(n,n-1), (n-2,n-3)..( ,2 or 1)} we calculate val[i] and val[i + 1] by observing the following:

  • if dp[i + 2] == dp[i + 3], then
    • if throw(i) == dp[i + 2] + 1, then val[i] must be 2. Else val[i] must be 1.
    • We swap i and i + 1, and again we ask throw(i) to get the new val[i] that corresponds to the previous val[i + 1]. We also assign the previous val[i] to the new val[i + 1]
  • if dp[i + 2] != dp[i + 3]
    • if throw(i + 1) == dp[i + 2] + 1, then val[i + 1] must be 1. Else val[i + 1] must be 2.
    • We swap i and i + 1, and again we ask throw(i + 1) to get the new val[i + 1] that corresponds to the previous val[i]. We also assign the previous val[i + 1] to the new val[i]
  • We compute dp[i] and dp[i + 1] using dp[i + 2], dp[i + 3], val[i] and val[i + 1]

If n is odd, we have 2 queries left to use for ascertaining val[1].

We notice that either dp[2] != dp[3] or dp[3] != dp[4]

(proof by contradiction: if dp[2] == dp[3] == dp[4], but val[2] = 1 or 2, which means dp[2] == 1 + dp[3] or 1 + dp[4], which contradicts the original assumption).

If dp[2] != dp[3], we simply ask throw(1) and if it equals 1 + dp[2], then val[1] == 1. If it is not equal to 1 + dp[2], then val[1] == 2.

If dp[2] == dp[3], then dp[3] != dp[4]. So we first swap the values at indices 1 and 2, and then query throw(2) to determine the value of the new val[2] which corresponds to the previous val[1]. If throw(2) == 1 + dp[3] then val[2] == 1 else val[2] == 2.

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

I am solving problem A: if the test case is n=5,a=4,b=1; what will be the answer :NO but the answer is:YES right? according to the editorial it is giving NO can you review on this and tell me what the thing i went wrong on?

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

Attention!

Your solution 335622185 for the problem 2134A significantly coincides with solutions MASTER_RAFAT/335621768, wwwglll/335622185. Such a coincidence is a clear rules violation. Note that unintentional leakage is also a violation. For example, do not use ideone.com with the default settings (public access to your code). If you have conclusive evidence that a coincidence has occurred due to the use of a common source published before the competition, write a comment to post about the round with all the details. More information can be found at http://mirror.codeforces.com/blog/entry/8790. Such violation of the rules may be the reason for blocking your account or other penalties. In case of repeated violations, your account may be blocked.

First of all, I don't know this person, and the time between his code submission and mine was less than a minute. Secondly, this is a relatively simple problem, and having similar logic in the code is quite common. You can check all my submitted code—it was entirely written by me.

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

how should one start to think when they come at

$$$ a_i + k \cdot c_i \equiv 0 \ (\text{mod} \ g) $$$

I was unfamiliar with modular until i began programming, and its hard even on paper. So I was clueless as $$$ g $$$ and $$$ c_i $$$ were both unavailable

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

For the solution 2 of problem B in the editorial, how to prove $$$c_i$$$ is guaranteed to be less or equal than $$$k$$$?

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

Problem D & E is a bit tricky and ad-hoc, but I like them!

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

Can anyone explain why the idea of choosing g = k+1,helps or any good resources to understand this better with follow up questions.

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

Honestly, the editorial for C was kinda bad. Why is there no proof for the greedy approach?

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

There is a small mistake in the editorial for D.

If $$$p$$$ does not pass through $$$b$$$, or if $$$b$$$ is an endpoint of $$$p$$$, then the length of $$$p$$$ clearly does not change before and after the operation.

If $$$b$$$ is an endpoint of $$$p$$$ and $$$p$$$ does not pass through $$$a$$$ or $$$c$$$, the length of $$$p$$$ will increase by one.

figure

Consider the figure above. Suppose $$$p$$$ is the unique path between nodes $$$3$$$ and $$$2$$$. After applying the operation $$$4$$$, $$$3$$$, $$$2$$$; the length of $$$p$$$ changes from $$$2$$$ to $$$3$$$.

Tagging: henotrix