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

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

I hope you all enjoyed the contest! Special thanks to

  • djm03178 for suggesting the inclusion of C1, and for helping with test writing on all problems, especially F
  • satyam343 for helping me solve H
  • Dominater069 for providing the idea for one of the solutions to E
  • Intellegent for providing one of the proofs for the solution to D, and for providing the idea for one of the solutions to F
Rate the contest!

A — Shizuku Hoshikawa and Farm Legs

Solution
Rate the problem!

B — Yuu Koito and Minimum Absolute Sum

Solution
Rate the problem!

C1/C2 — Renako Amaori and XOR Game

Solution (Easy Version)
Solution (Hard Version)
Bonus
Rate the problem!

D/F — Rae Taylor and Trees

Solution (Easy Version)
Solution (Hard Version)
Bonus
Rate the problem!

E — Anisphia Wynn Palettia and Good Permutations

Solution
Bonus
Rate the problem!

G — Sakura Adachi and Optimal Sequences

Solution
Rate the problem!

H — Shiori Miyagi and Maximum Array Score

Solution
Rate the problem!
Разбор задач Codeforces Round 1065 (Div. 3)
  • Проголосовать: нравится
  • +129
  • Проголосовать: не нравится

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

Very fast editorial :)

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

editorial at the speed of light!

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

Fast editorial.Thanks!)

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

Super fast tutorial!

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

No hacking phase?

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

Nice, that was so fast :v

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

A very beautiful use of prefix and suffix list in D and F

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

Can't wait for ratings to roll out!!

Thanks a lot to reirugan and the testers for the amazing contest

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

For bonus E, i think f(n)=1,code — 349964120,although i didn't prove this.

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

E is an interesting problem.

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

can anyone explain step 2 of Prblem C1 is there any proof for that..?

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

Easy contest expected it to be a little harder.

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

I'm late for this contest QQ

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

Kinda surprised the number of solve in E (including cheaters) is under 1000. Thought chatGPT would be able to solve it easily

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

Yuri is good :) I support Ajisai so I think the solution of C1/C2 is printing "Ajisai" for all tests.()

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

reirugan Really good contest bro, enjoyed the problems. Waiting for your next contest.

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

E another solution:

set p_i+1's mod 12 to {1, 6, 2, 5, 4, 8, 7, 10, 12, 11, 3, 9}'s i (mod 12) element.

https://mirror.codeforces.com/contest/2171/submission/349954650

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

Why couldn't D1 be solved with DSU? Or I'm just bad in implementation...

349949664

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

In problem G, can someone explain why are we multiplying cnt[i]! to ans ?

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

    Maybe it would have been more clear if I had used the variable j instead of i. I've updated the code to use this variable naming, to match the editorial.

    Basically cnt[j] denotes the number of indices such that you need an addition operation before $$$j$$$ double operations. These can be permuted in any way, so you want to multiply by fact[cnt[j]].

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

For bonus C, I think we need to find the players who has the ability to set the final value on each bit. Then, once we get the msb (winner) we can set the diff for each bit (winner->1, loser->0). But, I am not sure. If anyone has a good answer, please comment it.

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

One of the worst div3 contests ever.

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

For bonus E, max f(n) is actually 1. The proof is a bit long though.

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

    do you have proof, if yes can you post it here

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

    I can generate (non-constructive, something similar to simulated annealing) sequence for $$$n=10^7$$$ with $$$f(n) = 0$$$. Provide me your proof please.

    PS: If you want to generate this sequence so that you can verify it, use solve_range(1, n, 0); from 353828654.

    UPD: nevermind, I forgot small cases $$$n=3,n=5$$$.

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

      Construction of a Permutation with At Most 1 Bad Index

      Small Cases (n < 6):

      • n=3: [1, 2, 3] (1 bad index)

      • n=4: [1, 2, 4, 3] (0 bad indices)

      • n=5: [1, 2, 4, 3, 5] (1 bad index)

      General Case (n ≥ 6):

      Let n = 6q + r with q ≥ 1 and 0 ≤ r ≤ 5.

      Core Blocks (covering 1 to 6q):

      • Divide into q blocks of 6: k-th block (k=0 to q-1) is 6k+1 to 6k+6.

      • Order each as: 6k+2, 6k+1, 6k+4, 6k+6, 6k+5, 6k+3.

      • Reverse every odd-indexed block (k odd, 0-based).

      • Concatenate blocks.

      Why 0 bad indices in core:

      • Within blocks: Every triplet has a pair with gcd > 1.

      • Even k blocks start with multiple of 2, end with multiple of 3.

      • Odd k (reversed) start with multiple of 3, end with multiple of 2.

      • Junctions are thus 3-to-3 (gcd ≥ 3) or 2-to-2 (gcd ≥ 2).

      Core starts with 2.

      Remainder r (numbers 6q+1 to n):

      • r=0: Use core (0 bad)

      • r=1: Append 6q+1 → at most 1 bad at junction (1 bad)

      • r=2: Prepend 6q+1, 6q+2 → pattern 6q+1 (odd), 6q+2 (even), 2 (even). Even-even junction (0 bad)

      • r=3: Prepend as r=2 (0 bad). Place 6q+3 (multiple of 3):

      • If q odd: core ends with multiple of 3 → append (gcd ≥ 3)

      • If q even (q ≥ 2): first two blocks end with ...3 then 9... → insert 6q+3 between them (gcd ≥ 3 pairs)

      • r=4: Prepend 6q+1, 6q+4, 6q+2 → pattern 6q+1 (odd), 6q+4 (even), 6q+2 (even), 2 (even) and place 6q+3 as above (0 bad)

      • r=5: As r=4 for first four (0 bad), and append 6q+5 → at most 1 bad at junction (1 bad)

      This yields a permutation with at most 1 bad index for any n.

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

        I guess it is possible to modify your construction to make $$$f(n) = 0$$$ for $$$n \ge 100$$$ (and cases for $$$6 \le n \lt 100$$$ by bruteforce). Replacing cases for $$$r = 1, 5$$$ we can replace the initial $$$5$$$ in the first block with $$$6q + r$$$, and now we have a multiple of five, so we can place it near $$$25 = 6 \cdot 4 + 1$$$, and in this block we were covering $$$25$$$ by its neighbors, so it should not break anything.

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

Can someone explain me why my Dsu solution gives WA in problem D? Submission:349981598

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

My $$$O(M\sqrt{M}log(M))$$$ solution passed for H.

  1. For indices in range $$$[1, 2, ..., \sqrt(M)]$$$, I computed $$$dp[i][j]$$$ as the max score possible on assigning values to $$$A[1], A[2], \dots A[i]$$$ from the values $$$1, 2, \dots j$$$. Basic dp with no data structure optimization

  2. For indices $$$i$$$ s.t. $$$i$$$ > $$$\sqrt(M)$$$, $$$val(i, A[i])$$$ will be atmost 1. Compute $$$dp2[i][j]$$$ as the the maximum possible score possible on assigning values to $$$A[i], A[i+1], \dots, A[n]$$$ from the values $$$j, j+1, \dots, M$$$. For this, the maximum possible score can be $$$N - \sqrt(M)$$$ (since each index contributes atmost 1), then I maintained the minimum $$$j$$$ needed to obtain a given score as I iterated through $$$i$$$ from $$$N$$$ downto $$$\sqrt(M) + 1$$$. (kind of what we do for longest increasing subsequence)

It is trivial to merge these to obtain the final answer.

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

Define DP[i][j] as in the editorial makes everything much easier. I struggled with the definition that DP[i][j] is the answer at position i with value j.

Is there problems solvable with similar tricks?

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

Problem D/F can be easily solved using stack 349987767

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

I solved D/F using scanline + dfs on segments + binary search: 349972666. I saw someone call the DSU overkill. I wonder what he thinks about my solution...

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

An alternative $$$O(m \sqrt{m})$$$ solution on Problem H, which might be more beginner-friendly and easier to understand and implement (hopefully):

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

    i think you can just precompute $$$dp[i][j]$$$ for all the desired $$$i$$$ and $$$j$$$ in $$$O(m \sqrt m)$$$ and just use short int as data type to pass memory limit, and answer $$$n \lt K$$$ case in $$$O(1)$$$.

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

    This solution relies on the claim that an optimal tail ($$$i \gt K$$$) structure is a single contiguous block: $$$a_{K+1}=c(K+1), \cdots, a_{K+f(c)}= c(K+f(c))$$$, but I'm failing to see why this is true.

    1. why is it suboptimal to "give up" $$$K+1$$$ and only consider forcing $$$i=K+2$$$ onwards to be $$$ci$$$? this allows a larger upper bound, e.g. $$$c(K+1)-2$$$, on $$$dp2$$$, which may be potentially better.
    2. why is it suboptimal to "give up" certain intervals? for example, give up $$$K+2$$$ to $$$K+j-1$$$ s.t. $$$a_{K+1}=c(K+1)$$$ and $$$a_{K+j}=(c-1)(K+j)$$$. this allows $$$c$$$ to decrease to $$$c-1$$$, which may potentially allow for more indices $$$ \gt K+j$$$ to have a value of 1.

    Thanks in advance.

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

    any index j>i can contribute to the answer as well by taking aj=c⋅j .

    can you explain why this is always optimal? Like, what if we take $$$a_j = c' \cdot j$$$ and that gives a better answer?

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

Did not get C2, what if the number having highest set bit is present on both odd and even indices ? then how will you proceed

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

    Once you consider the most significant bit, you can follow the solution to C1. In particular, you only need to consider the largest $$$i$$$ such that the highest set bit of the XOR differs in value between $$$a_i$$$ and $$$b_i$$$.

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

For problem D, I took advantage of the fact that if, for any given $$$1\le k\le n - 1$$$, the last $$$k$$$ elements of our permutation $$$p$$$ contains all integers from $$$1$$$ to $$$k$$$, then the answer is $$$\text{No}$$$.

Fairly easy to see why this is a necessary condition, but I couldn’t prove why it’s also sufficient. Can anyone help?

Code: 349979576

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

    Your condition is actually the same as the one in the editorial, just put in a different way.

    Indeed, if the last $$$k$$$ elements are the integers from $$$1$$$ to $$$k$$$, then pre[n-k] = k+1 and suf[n-k+1] = k. Conversely, if pre[n-k] > suf[n-k+1], then we must have that the last $$$k$$$ elements are the integers from $$$1$$$ to $$$k$$$.

    Now, you can simply use the proof in the editorial.

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

wasted so much time in question D. I couldn't able to find the intuition for that. BTW the solution is really beautiful.

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

Some experiences as a tester:

  • Test 12-14 for D/F are added by me, and I see around $$$200$$$ solutions have failed on these tests. These tests aim to hack bruteforce (or cutting) solutions that try to connect each index with whatever possible.
  • Test 15 on G hacks solutions that only precalculate factorial up to $$$10^6$$$ or $$$10^6 + 1$$$, which was added because I told the setter that it would be a very common mistake due to the upper limit of the elements. And you see, there are already 60 solutions that failed because of this mistake.
  • I suggested C1, because everyone was worrying that the gap between B and C2 was too large. It turned out to be a really nice decision to do this, seeing the number of solves on B — C1 — C2.
  • I thought E would be solved much more, because some wacky solutions like 349983985 can pass. Seems like not many people actually tried it, though.
»
6 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Codeforces Round 1065 (Div. 3) in problem 2171H - Shiori Miyagi and Maximum Array Score
in 4th test case 3 500
maximal array would be [_,128,243]
and k will be [_,7,5]
so 7+5 = 12 but why it is 13 and similarly in
3rd test case 6 216
maximal array would be [_,16,27,64,125,216]
and k will be [_,4,3,3,3,3]
so 4+3+3+3+3 = 16
but it is given 19 how?

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

Why was the contest not rated?

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

I was playing with an alternative constructive idea for problem E from this round:
https://mirror.codeforces.com/contest/2171/problem/E

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

I solved E with $$$max\ f(n) = 1$$$. The idea was to print a "base" number immediately followed by its multiples which have this number as their lowest divisor (except 1) sorted in reversed order. All numbers up to $$$\frac{n}{2}$$$ are printed this way, but there are primes in $$$[\frac{n}{2}, n]$$$. So, if at any point we've got a "base" number to print (i.e. we haven't printed it before) and some multiples of it which we also haven't printed before, we print a prime after the first multiple and then after each two non-final multiples: "base" — multiple — prime — multiple — multiple — prime — multiple. Similarly, if the "base" number has already been printed before but there are some multiples to go, we print a prime after each two non-final multiples: multiple — multiple — prime — multiple. It happens to be that for every $$$n$$$, except a few small ones, all primes in $$$[\frac{n}{2}, n]$$$ get printed in between the multiples this way. Submission: https://mirror.codeforces.com/contest/2171/submission/349988810

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

I thought of an easier solution to D/F.

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

E is too hardddddddddd

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

My idea to solve E is to construct a array in that format:

$$$x,2,4,x,6,8,x,\dots,x,3,9,x,15,21,\dots$$$

This is fill two numbers into three blanks.

And we can know the bad index will only in the change of the different qualitative factor.

We will need $$$\frac{2}{3} \times n$$$ numbers for fill.

And the numbers of multiple of 2 or 3 also have $$$\frac{2}{3} \times n$$$,but the number can be odd,which leads to we can't chooose the last one.So we will put some multiple of 5 at the end.

Finally we can construct the array with $$$f(max)=2$$$.

Sorry for my poor English level,if you don't understand you can send post or notifications to me.

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

I solved F by greedily choosing any parent that works, if not, put it inside a queue then try to repeatedly empty the queue in every iteration: 350007901. Typically, finding the parent is $$$O(n)$$$, but I optimized it to $$$O(\log(n))$$$ using segment trees. I think this might not work if there is no such tree that $$$p_1$$$ is the root.

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

very fast edtioral , which make my code spin, love from regenbogen

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

how come may brain just shut donw during this division. i can`t even figure out hwo to solve D untill i woke up this morining.

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

F. Rae Taylor and Trees (hard version)

Can someone proof that $$$p_r$$$ to $$$p_{l-1}$$$ are connected using $$$\text{pre}_{l-1} \lt \text{suf}_l = p_r$$$ on Hint-step 2?

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

    In the beginning of step 1, we say "Suppose that $$$\mathrm{pre}_{i-1} \lt \mathrm{suf}_i$$$ for all $$$i$$$." Indeed, by the result of the easy version, this is a necessary and sufficient condition for an answer to exist.

    Now, using this identity at $$$l$$$, we get that $$$\mathrm{pre}_{l-1} \lt \mathrm{suf}_l$$$. We have that $$$\mathrm{suf}_l = p_r$$$ by definition of $$$l$$$ and $$$r$$$, because $$$l-1$$$ and $$$r$$$ are the indices of consecutive suffix maxes.

    Now, we have that $$$\mathrm{pre}_{l-1} \lt p_r$$$, and $$$\mathrm{pre}_{l-1}$$$ is in the first $$$l-1$$$ elements, so it appears first. So they can be connected, as desired.

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

In problem E, Another Solution (Maybe?).

I want to find a longest WONDERFUL array using number $$$1,\cdots,n$$$, that $$$gcd(a_i, a_{i+1}) \gt 1 || gcd(a_{i+1}, a_{i+2}) $$$ for every $$$i$$$ from $$$1$$$ to $$$n - 2$$$。 So the array can be : $$$2,4,6,(3,9,12,\cdots),8,10,(5,20,25,35,40,50,\cdots), 14, (7, 28, 49, 56, 77, \cdots),16,\cdots。$$$

When we meet a number $$$2 \times P$$$ and P is a prime, we put $$$2P, 3P, \cdots $$$ in this array. After that, the number we didn't use is the prime which bigger than $$$n / 2$$$.

Then we can put this number into our WONDERFUL array. If $$$\gcd(a_i, a_{i+1}) \gt 1, \gcd(a_{i+1}, a_{i+2}) \gt 1$$$, Then we can put one number after $$$a_i$$$。 Maybe this is a solution for $$$max f(n) = 1$$$?

Code: 350012298

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

    I thought of a similar idea to the tutorial by noticing that we have n/2 multiples of 2 and n/6 odd multiples of 3. So you use all of them to make a sequence such that for every i from 1 to n — 2 we have exactly one non coprime pair. For example :-

    2, X, 4, 6, X, 8, 10, X, ...

    Here X denotes "not filled". (Starting with 2 is not optimal but i guess i didn't think of that at the time plus implementation was not easy for me).

    It is not enough because n/2 multiples will only give n/4 X's so we are able to add 3n/4 numbers which still leaves n/4 numbers. So, how can we transition to using 3's multiples from this. We can use a multiple of 6 to achieve this in the following manner : Let x be multiple of 2 , y be odd multiple of 3 and z be multiple of 6, then sequence would look like this:

    ..., x, y, X, z, ...

    So, now we have 3n/4 multiples and should have 3n/8 X's which is more than enough ( n/4 < 3n/8) to use up all the numbers.

    Code: 350172224

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

Those problems were so good

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

cooked by D

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

is there no DP solution for C1/C2 ?

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

    I use a memoization solution for C1/C2.

    First, create a $$$n * 2 * 2$$$ array $$$dp$$$.

    for every bit, $$$dp_{i,u,v}$$$ means if in i-th turn, $$$xor a_j(1\leq j\leq i - 1) = u, xor b_j(1\leq j\leq i - 1) = v$$$, whether the player in i-th turn can win。

    then check the two swap option(swap or not swap). if I can make next people lose, then I can win this game; IF I can make next person tie, Then the game is tie.

    The solution is 349887096

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

I think there can be a similar problem with bonus of C: 2115D - Gellyfish and Forget-Me-Not

Let's our score be $$$s = \bigoplus a_i$$$ in the begining. For each position define $$$c_i = a_i \oplus b_i$$$. If a move is made on index $$$i$$$, the score simply becomes $$$s = s \bigoplus c_i$$$, otherwise it stays same.

The opponent's score can also be written as $$$(\bigoplus a_i) \bigoplus (\bigoplus b_i) \bigoplus s$$$. So can we say our aim is maximizing or minimizing the $$$s$$$ for maximizing the difference?

reirugan

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

The program given in question C cannot pass the example. Is it an error in the example or in the code/ll

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

This is the true Div3!

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

Does someone know any DSU solution for D? Thanks!

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

didn't realise it was that easy for pB :(

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

I have come up with an idea for question E, but I need to sleep in East Asia.

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

What are the expected ratings of all the problems..?

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

If you are struggling to understand problem C (Easy + Hard) then
here is the detailed video editorial (in Hindi) for you : C Video tutorial

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

How someone can think for problem D ? i wasn't even close to this.

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

Anyone used divide and conquer for problem D/F ? (would love to see some similar solutions to improve my implementation of the same.)

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

It's funny that brute-force solution works for E 350059773

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

Thanks for the amazing contest!!!

P.S. Very Fast Editorial ^-^! Thanks for all the effort you put into it

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

can someone please check my tree construction part and tell me where the logic is wrong, preferably with a testcase 349963130

UPD : nvm went with the tutorial way, good enough

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

Another solution for E : 350006163

Basically, we construct a vector v = {2,5,4,6,1,3} and also its reverse , rv = {3,1,6,4,5,2}.

To build the answer, we process the numbers in blocks of 6. For each block, we push back i*6 + v[0] to i*6 + v[5]. After each block, we swap v with rv.

The reason we use this specific pattern {2,5,4,6,1,3} is that, within each block of 6, any three consecutive numbers always contain at least one pair that shares a common factor (either 2 or 3). This ensures that no three consecutive numbers are pairwise coprime.

Last ,we reverse every other block to make sure that sequences across block boundaries also satisfy the rules. If we didn’t, some sequences would violate the constraints.

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

For problem G, it dose not cover edge case Input 1 1 1 5 Output: 3 2 but code with output 3 1 will also pass

it is not considering the case when n is 1 and a[0] = 1, so a[0] can be made 2 using 2 operation either by adding 1 or by doubling it.

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

Finally I write it by myself Actually I didn't understand it a bit Maybe my English is very bad

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

I have a solution for H and used a magic number MA=24 for avoiding TLE, but I can't prove that would never miss correct answer(or it may be hacked?). Does anynoe can help me? https://mirror.codeforces.com/contest/2171/submission/350094661

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

Why in Problem C2 do we only care about the last position where the XOR of a_i with b_i differs and the bit x is active there? And what happens if there are several positions like this? I don’t really understand that part.

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

Another solution for c2/c1 is to greedyly checking the swap for each players.

this is my solution for it

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

Can anyone tell me why this solution is correct for E? solution I am not able to prove this

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

Hello, I understood the logic behind problem G and I tried to submit the following code. But it is giving Out of bounds memory error in Test Case: 3.


/* g++ --std=c++17 a.cpp -o a.out ./a.out */ #include<iostream> #include<string> #include<cmath> #include<algorithm> #include<vector> #include<stack> #include<queue> #include<deque> #include<bitset> #include<iterator> #include<numeric> #include<set> #include<unordered_set> #include<stack> #include<queue> #include<map> #include<unordered_map> #include<tuple> #include <fstream> using namespace std; #define ll long long class MinHeap { public: bool operator() (pair<int, int>& a, pair<int, int>& b) { return a.first > b.first; } }; class MaxHeap { public: bool operator() (pair<int, int>& a, pair<int, int>& b) { return a.first < b.first; } }; bool compare(pair<int, int>& a, pair<int, int>& b) { return a.first < b.first; } #define ll long long const int maxn = 10 * 1e6; const int mod = 1e6+3; vector<ll> perm(maxn); int getDouble(int a, int b) { int count = 0; while (2 * a <= b) { a *= 2; count++; } return count; } ll power(ll x, int y) { if (y==0) return 1; ll temp = power(x, y/2); temp = (temp * temp) % mod; if (y%2==1) temp = (temp * x) % mod; return temp; } void solve() { int n; cin >> n; vector<int> a(n), b(n); for (int i=0; i<n; i++) { cin >> a[i]; } for (int i=0; i<n; i++) { cin >> b[i]; } int k = 1e6; for (int i=0; i<n; i++) { k = min(k, getDouble(a[i], b[i])); } ll x = 0; ll ans = 1; for (int j=1; j<=k; j++) { int count = 0; ll denom = 1; for (int i=0; i<n; i++) { int x = b[i] - 2 * (b[i]/2); denom = (denom * perm[x]) % mod; count += x; b[i] /= 2; } ans *= (perm[count] * power(denom, mod-2)) % mod; ans %= mod; x += count + 1; } int count = 0; ll denom = 1; for (int i=0; i<n; i++) { if (b[i] > a[i]) { count += b[i] - a[i]; denom = (denom * perm[b[i] - a[i]]) % mod; } } ans *= (perm[count] * power(denom, mod-2)) % mod; ans %= mod; x += count; cout << x << " " << ans << "\n"; } int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); perm[0] = 1; for (int i=1; i<=maxn-1; i++) { perm[i] = (perm[i-1] * i) % mod; } int t = 1; cin >> t; while (t--) { solve(); } return 0; }

Now I see the issue is because the count variables value is becoming bigger than the permutation array length I have set. Is there an efficient way to calculate permutation(count)% mod within the limits of permutation array length (in my code, the length is set as 10^7) ?

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

    Nevermind. Please ignore.

    The following change worked.


    ll getPerm(int x) { if (x < mod) return perm[x]; int count = x / mod; int rem = x % mod; ll res = 1ll; while (count--) { res = (res * perm[mod]) % mod; } res = (res * perm[rem]) % mod; return res; }
»
6 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

for D/F — I maintained a monotonic decreasing stack as I iterated. when I got a smaller number, I popped all bigger numbers and then added to same dsu, followed pushing the min element of dsu back to stack. worked good

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

350067977

This is my code for the D , can anybody explain why this is wrong answer on test case 2 , saying it answers "yes" when it must answer "no"

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

Good problems and nice editorial! love!! QwQ

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

for problem d my first idea was to divide the array into three subarrays a,b,c if n appears before one, then a contains the first elements until n, and b contains all before 1, and c contains all from where is 1 until the last element. all elements in a can be connected with themselves and the same for c. then the last step was to find if I can connect the array a and c, and if b can be connected with one or both of them. the idea was correct, sadly, the implementation had many errors.

my ac sol:

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

https://mirror.codeforces.com/contest/2171/submission/350258232

This seems to always give 0 bad indices except for $$$n=3$$$ and $$$n=5$$$.

Let's define a sequence $$$q$$$ like this: start with $$$i=2$$$, add all $$$i^k \leq n$$$; for all $$$j$$$ from $$$\lfloor n/i \rfloor$$$ to $$$3$$$ add all $$$i^k*j \leq n$$$ which haven't yet been added, change $$$i$$$ to the last (the smallest) $$$j$$$ for which we added something.

Any 2 neighbours in $$$q$$$ are not coprime. If the number of integers $$$1 \leq x \leq n$$$ that are not in $$$q$$$ is small enough we can "fit" them between values of $$$q$$$ ($$$[x_1, q_1, q_2, x_2, q_3, q_4, x_3, ...]$$$).

I believe all $$$i$$$ are primes and we stop when $$$i * nextprime(i) \gt n$$$. And when we reach $$$i$$$ we have already added all the multiples of $$$i$$$ that are less than $$$i^2$$$, except $$$i$$$ itself. So the numbers that are not in $$$q$$$ should all be primes (their multiples that are not in $$$q$$$ are too large).

The number of primes $$$\leq n$$$ approaches $$$n/log(n)$$$, which is $$$ \lt n/3$$$ for big enough n, so we should be able to "fit" those values. And for small n it also seems to be working.

Am I missing something?

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

Thank you for the great problems! I learned a lot from the editorial. I'm also a fan of Mikoto ♥️

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

In problem H, how to come up with the the dp definition in the editorial instead of the the definition that dp[i][j] is the answer at position i with value j, or does it have any problems or tutorials to practice?

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

Is there an even simple way?

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

For E problem, I did a greedy approach, making chains by connecting numbers with same Smallest prime factor(SPF) and then keeping 2 elements from a SPF chain with >=2 elts left and then placing an element with an SPF chain left of length=1.I performed a indepth analysis of number of bad indices given by code and by the author's code over a range of values ranging from very small to very large using a generator,validator and a compare python script to generate a plot of no. of bad indices v/s n for both the programs. From it I am concluding that the maxm no. of bad indices possible is atmost 1 which is achieved by my program, which is in coherence with claim in the editorial.

Link:https://mirror.codeforces.com/contest/2171/submission/350520470 Comparison Plot

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

349945988 does this satisfies for the bonus solution of C2?

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

very fast editorial

»
6 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится
Your code here...
#include <bits/stdc++.h>
using namespace std;

int main() {
	// your code goes here
	int t;
	cin >> t;
	while(t--){
	    int n;
	    cin >> n;
	    int a[n];
	    int b[n];
	    int count_a=0;
	    int count_b=0;
	    for(int i=0;i<n;i++){
	        cin >> a[i];
            if(a[i]==1){
                count_a++;
            }
	    }
	    for(int i=0;i<n;i++){
	        cin >> b[i];
            if(b[i]==1){
                count_b++;
            }
	    }
	    int even1=0;
	    int even2=0;
	    int odd1=0;
	    int odd2=0;
	    for(int i=0;i<n;i++){
	        if(a[i]==0&&b[i]==1){
	            if(i%2==0){
	                even1++;
	            }else{
	                odd1++;
	            }
	        }
	        if(a[i]==1&&b[i]==0){
	            if(i%2==0){
	                even2++;
	            }else{
	                odd2++;
	            }
	        }
	    }
	    int even=even1+even2;
	    int odd=odd1+odd2;
	    if(count_a%2==0&&count_b%2==0){
	        cout << "Tie" << "\n";
	    }
	    if(count_a%2==1&&count_b%2==1){
	        cout << "Tie" << "\n";
	    }
	    if(count_a%2==0&&count_b%2==1){
	        if(even>odd){
	            cout << "Ajisai" << "\n";
	        }else{
	            cout << "Mai" << "\n";
	        }
	    }
	    if(count_a%2==1&&count_b%2==0){
	        if(odd>even){
	            cout << "Mai" << "\n";
	        }else{
	            cout << "Ajisai" << "\n";
	        }
	    }
	}
}

352260257 for C1 easy version can anyone explain why my code is failing

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

Hello everyone, I'm not sure why I'm getting a different result on my computer compared to the result in my submission 352466539.

Could someone help me check my code and see what I might be doing wrong? Here is my output: Your result

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

The official explanation for E was not very palpable for me. I wrote my detailed intuition with proof in the solution https://mirror.codeforces.com/contest/2171/submission/353349699 if anyone faced the same as I did. Copying the comment from the code below.

/**
 * Take a prime number say p, and look at the list of multiples of p.
 * {p, 2p, 3p, 4p... kp <= n}. For a moment name each element as "p".
 *
 *  {_, p, p, _ p, p, _, ...}. If we place them in our array of length n
 * in this way the array would be good.
 *
 * Q1. How many places where occupied by "p"s in this array of length n?
 * A. We have the block {_, p, p} repating until floor(N/3) blocks. With
 * each block containing 2 elements of p. So, total places: 2 x (N / 3).
 * Remaining positions: N - 2N/3 = N / 3. However, there is a small issue with
 * this i.e we are omitting the constaint here that a "p" must have a tight
 * upperbound of N. So, we need to constraint our p.
 *
 * For p = 2, it must be true that there must be exactly floor(N/2) "2.i" type
 * of elements. So, the question now becomes how long can we sprinkle the N/2
 * elements in the array, so that the array can be good until the last sprinkled
 * element. So, each 3 element block contains 2 new numbers. So, we have N/2
 * elements to sprinkle, So, taking 2 numbers from N/2 elements each time to
 * create a (3 element) block means creating N/4 blocks, each block contains 3
 * elements. Therefore total length from N covered is 3N/4. Now we still have
 * N/4 elements to think about.
 *
 * Now if we take p = 3 and take only the odd multiples. We can sprinkle that in
 * the remaining N/4 elements like we did with "2" to still have a good array.
 *
 * q> How may odd multiples of 3 are there below N?
 * A> An odd multiples comes every other time {"3", 6, "9", 12, "15"..}.
 * Therefore, it must half of total multiples of 3 below N. floor(N / 3) x (1/2)
 * = O(N/6) elements. Similarly, we now can sprinkle these N/6 elements over the
 * N/4 range. Again, so each time we take 2 new elements from the {N/6} set to
 * create 1 block. So, we would have N/12 blocks in total with 3 elements which
 * would be N/4!. It seems we have covered our whole remaining array without any
 * bad indices? Or did we?
 *
 * For the case of "p = 2", we will have a conflict with the last element in the
 * last block, with the 1st block of 3 i.e {_, 3, 9}. A snapshot would look like
 * [2i, _, 3, 9]. Clearly [2i, _, 3], would be co-primes as 2i is even, and _
 * and 3 are primes. Then, we would have another conlfict at [2(i-1), 2i, _] for
 * the same reason.
 *
 * As we saw, conflict got risen only at the boundary of 2. So, the next
 * potential conflicts can arise at the boundary of 3. How many atmost 2 again
 * by the same line of thought as 2. Therefore total conflicts is at-most 4.
 *
 */
»
5 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

I have a question for C2, why shouldn't we consider the second most significant bits if they got a tie for the most significant bits, and do until they consider the last bits? Thank you!

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

    Because if MSB is bigger, then all bits after it can be 1, still the element with MSB 1 will be greater than element with MSB 0. See by 2^k + 2^(k-1) + .. 1 < 2^(k+1). And tie for MSB is not possible, as we took XOR of both arrays and got 1, so only one of the scores has MSB of XOR as 1.

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

Can F be solved by DSU.

Like I think, if we keep a track of the edges from 0 upto when it reaches N — 1 and then we keep two sets to check for elements to left of a index lesser than it and similarly greater elements to write. Then slide through indices and update the sets.

While making union we obviously check if they are already a part of the MST or tree and proceed. Is it feasible or will it give TLE. I think it wont give TLE but I don't have a formal proof or TC.

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

for the bonus problem F we notice that any set of n-1 edges and those edges should cover each number from 1 to n at least once gives a valid tree so we just find total number of such sets but i see that in n^2 time

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

Did anybody try to do E by constructing a graph? Like we can take edge exists if two numbers have non-1 GCD, find a path in each connected component, and then somehow join those path and put single elements between them to find the full permutation. But I think the graph will be large, and will TLE with the constraints. Thanks!