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

Автор Nezzar, история, 5 лет назад, По-английски

Thanks for joining us today! Here is the editorial for today's problems:

1478A - Nezzar and Colorful Balls

Tutorial
Solution

1478B - Nezzar and Lucky Number

Tutorial
Solution

1478C - Nezzar and Symmetric Array

Tutorial
Solution

1477A - Nezzar and Board

Tutorial
Solution

1477B - Nezzar and Binary String

Tutorial
Solution

1477C - Nezzar and Nice Beatmap

Tutorial
Solution

1477D - Nezzar and Hidden Permutations

Tutorial
Solution

1477E - Nezzar and Tournaments

Tutorial
Solution

1477F - Nezzar and Chocolate Bars

Tutorial
Solution
Разбор задач Codeforces Round 698 (Div. 1)
Разбор задач Codeforces Round 698 (Div. 2)
  • Проголосовать: нравится
  • +214
  • Проголосовать: не нравится

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

Please add comments in code solutions of editorials to make it more readable

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

I thought that the problems were really nice. Kudos to all the authors! :)

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

div1C Furthest Points

Pick an arbitrary point, and in each iteration, select the furthest point from previously chosen point among all available points. Indeed, we can prove the correctness by contradiction.

what the f**k How did I miss that

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

Extremely nice contest! Thank u for your work!

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

Let $$$g_0 = \gcd(x_2,x_3,\dots, x_n)$$$.

Should it be "let $$$g_0 = \gcd(x_2,x_3,\dots,x_{n-1})$$$"?

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

    Thanks! We will fix it later.

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

    How can we write $$$g$$$ using $$$g_0$$$ and $$$x_n$$$. And another question is even if we are able to write $$$g$$$, how can we generate all multiples of $$$g$$$ ?

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

      (0,g) — > (0,g,2g)

      2*(2g)-g = 3g -> (0,g,2g,3g) 2*(2g)-0 = 4g -> (0,g,2g,3g,4g) ....

      But with (0,g0,xn) I can't generate g = xn-g0 for example where s=1, t=1

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

        It's said that $$$g=sg_0+tx_n$$$, and there are multiple pairs $$$(s,t)$$$. An even $$$s$$$ is absolutely existed, so let's regard $$$s$$$ as an even one. With $$$0$$$, $$$x_n$$$, and $$$g_0$$$,it's easy to get $$$\frac{s}{2}g_0$$$ and $$$tx_n$$$, then $$$g=2\times \frac{s}{2}g_0+tx_n$$$.

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

          Can you please explain why there always exits s that is even? By the way why we can substract x1 for every xi and does not Affect the answer?

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

            I'm so sorry! I made a big mistake in my previous replication, $$$s$$$ can be odd! Fortunately, I've already got the true proof. Firstly, it's easily to get $$$pg_0$$$ and $$$qx_n$$$, $$$p,q\in\mathbb Z$$$. If $$$s$$$ is even, we can get $$$g$$$ with $$$\frac{s}{2}g_0$$$ and $$$tx_n$$$. If $$$t$$$ is even, we can get $$$g$$$ with $$$-\frac{t}{2}x_n$$$ and $$$-sg_0$$$. If $$$s$$$ and $$$t$$$ are both odd, there must exist $$$s'=s-\frac{x_n}{g}$$$ and $$$t'=t+\frac{g_0}{g}$$$ also satisfy $$$g_0s'-x_nt'=g$$$ by Bézout's Theorem; $$$s'$$$ and $$$t'$$$ mustn't be both odd since $$$\frac{x_n}{g}$$$ and $$$\frac{g_0}{g}$$$ are coprime and they mustn't be both even; the problem to construct $$$g_0s'-x_nt'$$$ is mentioned before.

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

              if $$$\frac{x_n}{g}$$$ and $$$\frac{g_0}{g}$$$ are coprime then how can you say that $$$s'$$$ and $$$t'$$$ will be of different parity. For example, if $$$\frac{x_n}{g} = 3$$$ and $$$\frac{g_0}{g} = 5$$$ then $$$s'$$$ and $$$t'$$$ will be both $$$even$$$ provided $$$s$$$ and $$$t$$$ were both $$$odd$$$. But thanks for your explanation, as at least one of them must be $$$even$$$.

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

            basically if we have: g = gcd(a,b), with some s0*a — t0*b = g by bezouts theorem, we can get any of the infinite solutions of (s,t) to bezouts theorem s*a — t*b = g with the following: s = s0 + k*(b/g), t = t0 + k*(a/g) because a corresponds with the s coefficient, what we're adding to the "s*a" term is: a * k * (b/g) and to the "t*b" term we're adding: b * k * (a/g) notice that the two terms we're adding are equivalent (by construction, i assume): k * a * (b/g) = k * b * (a/g) k * ab/g = k * ab/g if we take two numbers with difference g (the base equation s0*a — t0*b = g) adding the same thing to each term will preserve the difference g. now back to the original problem: our goal is just to get one of the coefficients to be even: if s0 is even or t0 is even, we're done, else they are both odd: we now want to see if there always exists a new pair (s,t) from one of the infinite bezouts theorem solutions s.t. either s or t is even (so we can construct our formula with the 2x — y operation) s = s0 + k * (b/g) since s0 is odd, we need k * (b/g) to be odd because odd + odd = even. only odd * odd = odd, so we need k to be odd and (b/g) to be odd. If (b/g) is odd just choose some odd k and we have an even s, otherwise try t: t = t0 + k * (a/g) following same reasoning, we need (a/g) odd. Notice that we cannot have both (b/g) and (a/g) to be even, otherwise g != gcd(a, b) because 2*g thus divides both b and a (since b/g and a/g are even). Therefore atleast one of (a/g) or (b/g) must be odd. so if (b/g) is even, then (a/g) must be odd and we can just choose k to be odd and get t0 (an odd) + k(odd) * (a/g)(odd) = t(even) -- (odd + odd = even) therefore, it is always possible to construct an equation s*a — t*b = g s.t. one of s or t is even. back to our problem: we have s*g0 — t*xn = g. we have g0 and xn on the board, and know that there exists a solution (s,t) to the above equation with one coefficient being even. WLOG suppose s is even, we just need to get s/2*(g0) on the board (by using x1 = 0 and doing 2*g0 — 0) we can get any multiple of g0 on the board including s/2*g0. by same logic we can get t*xn on the board. then, we just pick x = s/2*g0 and y = t*xn, then 2x — y is just 2*(s/2*g0) — t*xn = s*g0 — t*xn = g, therefore we have g on the board. and we know that if we can get a number x on the board, we can get any c*x on the board, where c in Z. therefore, anything divisible by g can be written on the board, and k must be divisible by g, therefore we return yes if and only if k is divisible by g.

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

        How can we write 0 on board?

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

          Dont think of it as zero. Note {a+nb,a+(n+1)b} can be used to make a+(n+2)b as follows

          $$$ x_{1}+(n+2)g = 2*(x_{1}+(n+1)g) - (x_{1}+ng) $$$
          $$$ \Rightarrow \space we \space have \space all \{ x_{1}+ng \forall n \in Z\} \space using \space \{x_{1}, x_{1}+g \}$$$

          Now, if we have g divides k and

          $$$ \{x_{1},x_{1}+g\} \space generates \space (x_{1}+(k-x_{1})) $$$

          thus all we need to do is check if x1+g can be written. Now this x1 does not really matters as it will disappear in most eqations,you can write down yourself and see .

          In the problem we can write for any x :

          $$$ x_{i} = x_{1}+(x_{i}-x_{1}) \space and \space operation \space on \space x_{1}+(x_{i}-x_{1}) \space and \space x_{1}+(x_{j}-x_{1}) \space will \space give \space : $$$
          $$$ \\(x_{1}+(V)) , V \space is \space some \space constant$$$
          $$$so \space just \space remove \space x_{1} \space and \space find \space if \space (x_{2}-x_{1}),(x_{3}-x_{1}),... \space can \space generate \space g$$$
»
5 лет назад, скрыть # |
 
Проголосовать: нравится +6 Проголосовать: не нравится

Can someone point out a mistake in this code? It gives WA on 10021st token. How is that even possible if total queries are 10000? https://mirror.codeforces.com/contest/1478/submission/105762283

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

An alternative solution for Problem Div 2 B — 1478B - Nezzar and Lucky Number

For given d, construct a sequence of elements of length s, that looks like d, d + 10, d + 20, ..., d + (s — 1) * 10 such that d + (s — 1) * 10 is strictly less than d * 10.

Observation 1: For a[i] >= d * 10, it's always possible to construct a[i] as sum of lucky numbers.
Observation 2: For a[i] < d * 10, it's feasible to brute-force any possibilities of representing a[i] as sum of lucky numbers.

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

good but all problem are ad-hoc

plz in next contests add algorithmic problems

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

how to avoid getting stuck on A and B in contests ?

UPD : It's genuine question.Do you people get stuck on those problems often and what are the reasons behind that ?

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

    solve them.

    if you feel like you are not making enough progress on a problem then you can try to solve some other problem and come back to that problem after some time.

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

    Start from C

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

    Yes, I too get stuck in critical observation type problems. Any help on how to improve on problems like that(B of today's contest for example) is appreciated.

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

    I used to brick my B quite often a few weeks back. I think you're talking about you are expecting yourself to do those questions quickly but you end up doing it wrong or can't get the idea at all. This is what I did, out of contest, I started practicing two problems from easier ranges(one 800-1200 the other 1300-1500 based on comfort level) and noted the time to solve(try to do it right) whenever I was averaging less than 10 mins in the easier range I increased the rating by 100 for those, same for the harder(1300-1500) ones when the avg. is less than 15. In contest, focus on doing it correctly and don't rush it for the next few contests. You will have a good idea of when you're rushing it as now you know very well how much time you take normally in those problems. It took me 4 to 5 more contests after I started practicing this way to eliminate those bad contests and get to a higher rating range.

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

Really nice problems!Though I miss the final time to submit div2F , which leads to a big loss //(ㄒoㄒ)//

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

I used bubble sort instead of insertion sorting in Div1C, but it seems that only when I sorted the points by their x-positions could I get accepted. Could you please help me find it out?

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

Div1 C was quite beautiful, however it was the same as this problem

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

Randomized approach for D1C(D2F):

There is three points, $$$A,B$$$ and $$$C$$$ on the plane.
Of course, the three points form a triangle.(this triangle's area can be $$$0$$$)
Then, two of $$$\{A \rightarrow B \rightarrow C\ ,\ A \rightarrow C \rightarrow B\ ,\ B \rightarrow A \rightarrow C\}$$$ are nice beatmaps.

For this reason, the following algorithm will work.

  • $$$p={p[1],p[2],...,p[N]}$$$ is a permutation of $$${1,2,...,N}$$$.
  • Shuffle $$$p$$$.
  • for i = 3 to N
  •  for j = i to N
  •   swap($$$p[i]$$$,$$$p[j]$$$)
  •   if($$$p[i-2] \rightarrow p[i-1] \rightarrow p[i]$$$ is a nice beatmap){break;}

Then, What is the probability of find a solution with this algorithm?
The answer is $$$(2/3) \times (8/9) \times (26/27) \times ...$$$
It seems that this value goes $$$\simeq 0.56$$$ (at least $$$n \le 5000$$$).
So, try this algorithm about $$$\frac{1}{0.56} \simeq 2$$$ times, then we can find a solution.

code : 105753764

If there is a hack case, please tell me.
As a music gamer, I like this problem!

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

I thought that the problems were really nice. Kudos to all the authors!

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

In the problem Nezzar and Board, can anyone prove that if we have $$$[0, x, y]$$$ written on board, then we can construct $$$a*x+b*y$$$? What I was able to prove that we can construct $$$a*x$$$ and $$$b*y$$$ individually.

Thanks

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

A kind of stupid question, but in the editorial code for D1C:

if (1ll*(x[perm[j]]-x[perm[j-1]])*(x[perm[j-1]]-x[perm[j-2]])+1ll*(y[perm[j]]-y[perm[j-1]])*(y[perm[j-1]]-y[perm[j-2]])>=0)

What exactly is that checking?

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

Check out my explanation of problem C — solution

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

Thanks for the good contest -_-

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

Congratz, maroonrk!

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

We know there are many weird solutions for Div.1C/Div.2F can get AC when their correctness can't be proved. We had tried our best to construct tests already, but some of them are extremely hard to hack. If you come up with an excellent hack, welcome to share it!

UPD:

For example, 105780521, created by kzyKT and developed by us.

Pick a new base point $$$O'$$$ and sort all points by polar angle, then try to check point sequence $$$[1, \frac n2 + 1, 2, \frac n2 + 2, \dots]$$$ (and those permutations can be derived by shifting) or something similar if they can be valid answers. This pattern will make acute angels appear frequently.

if you can't find answer with the current $$$O'$$$, you can try many other $$$O'$$$. Some specially chosen $$$O'$$$ perform literally excellent, like:

  • $$$( \frac {\sum x} {n}, \frac {\sum y} {n})$$$
  • $$$(inf, inf)$$$
  • $$$(inf, -inf)$$$
  • $$$(-inf, inf)$$$
  • $$$(-inf, -inf)$$$

So you will have a high chance to get a valid answer sequence if you check each of these $$$O'$$$.

We spend a long time hacking this solution, but it seems impossible. :(

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

Alternative Solution for Div2B without DP 1478B - Nezzar and Lucky Number

If ai >= 10d then it is always achievable. Because it is possible to subtract a number with d on the ten's place and any number on the one's place. It is possible to choose the one's place number so that the subtracted result is divisible by d (meaning it can be obtained by the sum of d's).

If ai < 10d, it is only possible to subtract d from it. So after each subtraction of d, check if ai is divisible by d or ai is divisible by 10 (meaning k*10 + d can be subtracted).

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

105777562 For Div2C I solved it by getting back the original array a. Basically the same idea as tutorial except one more observation is that d[2n] = 2n*a[n]

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

I like how D had such a clean solution.

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

Why k % gcd(x_1, x_2,.., x_n) == 0 won't work in DIV2D/1A? Can someone please explain.

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

How to prove that it's possible in Div1C to take farthest available point on each step?

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

Otherwise, we could subtract x1 for x1,x2,…,xn and k

why? :(

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

    OK, I guess it's because if we have an initial set {a, b, c} and we want to build k, by subtracting a from everything, nothing changes since every number we can build is also shifted by a. Namely:

    {a, b, c} with target k, e.g. we can build 2b-c.

    is equivalent to

    {a-a, b-a, c-a} with target k-a, e.g. we can build 2(b-a)-(c-a) = (2b-c)-a.

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

Can someone sketch a proof at Div1C for injection sort?

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

In problem D editorial , how subtracting $$$x_1$$$ from all other $$$x_i$$$ won't effect the answer i.e how to prove that if $$$k$$$ can be formed from $$$x_1,x_2,x_3$$$ then $$$k-x_1$$$ can also be formed from $$$0,x_2-x_1,x_3-x_1$$$?

Also can some one explain how we can write down $$$g$$$ by applying operation recursively ?

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

    For an arbitrary interger $$$d$$$, $$$(2x-y)-d=2(x-d)-(y-d)$$$. That's why we can subtract $$$d$$$ from all the elements (including $$$k$$$).

    From the proof of the editorial, we can get $$$g_0$$$ and $$$x_n$$$. Let we prove one fact that if we get $$$x$$$, we can also get $$$qx$$$ for all the intergers $$$q$$$. In fact, we can use $$$x$$$ and $$$0$$$ to make $$$2*0-x=-x$$$, so that we can add $$$2x$$$ and $$$-2x$$$ any times to any one element. (i.e. we can get $$$2*x-(-z)=z+2x$$$ and $$$2*(-x)-(-z)=z-2x$$$ with $$$z$$$) So the fact has already been proved.

    Then we need to discuss about the parity of $$$s$$$ and $$$t$$$ such that $$$g_0s-x_nt=g$$$. If $$$s$$$ and $$$t$$$ are both even, we can just add $$$\pm 2g_0$$$ and $$$\pm 2x_n$$$ to $$$0$$$ some times. If one of $$$s$$$ and $$$t$$$ is odd, suppose that $$$s$$$ is odd, we can just add $$$\pm 2g_0$$$ and $$$\pm 2x_n$$$ to $$$g_0$$$ some times. If both of them are odd, we can just change $$$s$$$ and $$$t$$$ into $$$s+\frac{x_n}{\gcd(g_0,x_n)}$$$ and $$$t-\frac{g_0}{\gcd(g_0,x_n)}$$$. Because $$$\gcd(\frac{x_n}{\gcd(g_0,x_n)},\frac{g_0}{\gcd(g_0,x_n)})=1$$$, they can't be both even and it has already been changed into the situation we have talked about.

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

      Given $$$g_0$$$ and $$$x_n$$$, then we can get $$$g_0 * s$$$ and $$$x_n * t$$$.

      Now $$$x_1 = x_n * t$$$, $$$x_2 = g_0 * s$$$, we can subtract $$$x_1$$$ from all x. We get $$$0, g_0 * s - x_n * t = g$$$. And by induction, we can get $$$q * g$$$. Now we add $$$x_1$$$ back. Because $$$x_1$$$ is divide by $$$g$$$, suppose $$$x_1 = t * g$$$, so we can get $$$q * g + t * g$$$ for all $$$q$$$, that is equal to $$$q * g$$$.

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

      So you proved that $$$g_0s$$$ and $$$-x_nt$$$ can be made individually using the operations . But how to prove that $$$g_0s - x_nt$$$ i.e $$$g$$$ can be made ?

      My major doubt is how Bezout's Theorem used here ? In the editorial it's mentioned that we can make $$$g_0s$$$ snd $$$-x_nt$$$ but how does that proves that any number divisible by $$$g$$$ can be constructed ?

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

Nezzar Can you please give more mathematical proof for DIV1-C, how can we prove this with contradiction like it feels natural but how to prove this first method you suggested.

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

    Consider three points $$$A$$$, $$$B$$$, $$$C$$$.

    You are in $$$A$$$ currently. Assume that the furthest point is $$$B$$$, then $$$C$$$ is between $$$A$$$ and $$$B$$$ so $$$\angle ABC$$$ is acute; if $$$\angle ABC$$$ is not acute, the furthest point from $$$A$$$ should be $$$C$$$ instead of $$$B$$$.

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

I didn't understand the editorial of 1477A — Nezzar and Board Can someone please explain the editorial?

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

    I also struggled to understand it. Here's my detailed understanding:

    (1) Note that if you had zero available and another number $$$a$$$, then you can build every multiple (positive and negative) of $$$a$$$. For example, from $$$(0, a)$$$ you can get $$$-a$$$ and from $$$(-a, a)$$$ you can get $$$3a$$$ and so on.

    (2) Note that shifting all numbers $$$x_i$$$ and $$$k$$$ by the same amount, does not change the answer. If you had numbers $$$x_0$$$, $$$x_1$$$ and $$$x_2$$$ and you wanted to obtain $$$k$$$, you could subtract $$$x_0$$$ from everything and every number obtained from this new process is also shifted by $$$x_0$$$. For example, you would get $$$x_0-x_0=0$$$, $$$x_1-x_0$$$, $$$x_2-x_0$$$ and $$$k-x_0$$$ and if you combined $$$x_1-x_0$$$ and $$$x_2-x_0$$$, you would end up with $$$2(x_1-x_0) - (x_2-x_0) = (2x_1-x_2)-x_0$$$.

    (3) Note that since you can get 0 by shifting the input and you can get the multiples of all the remaining numbers, you can basically get every number of the form $$$u(x_i-x_0) + v(x_j-x_0)$$$, which is another way of saying that you can get every multiple of $$$gcd(x_1-x_0, x_2-x_0, ...)$$$, and nothing else. (See Bézout's identity).

    (4) Finally, using the previous observations, if $$$k-x_0$$$ is a multiple of $$$gcd(x_1-x_0, x_2-x_0, ...)$$$ then the answer is "YES". Otherwise, it is "NO".

    Sample Solution: 105781653

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

      Can you prove point (3)? Given [0, x, y], try to construct x+y.

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

      ok, we can write down $$$g_0, g_0s, x_nt$$$. Explain please, how we can write down $$$g_0s-x_nt$$$? if s is even, i understand, but if not

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

        Let's say we want to get $$$x_{n}t$$$ and we have $$$t = 13$$$. Our operation is $$$2a - b$$$. We can set $$$a = 4x_n, b = x_n$$$, so it becomes $$$8x_n - x_n = 7x_n$$$. And then we set $$$a = 7x_n$$$ which we got before, and $$$b = x_n$$$, and it becomes $$$14x_n - x_n = 13x_n$$$. And of course, we can get any $$$kx$$$ being $$$k = (2^{exp})$$$ if we set $$$a = \frac{k}{2}x$$$ and $$$b = x_1$$$ (remember $$$x_1 = 0$$$ because of the shifting). That is to say, we can get $$$2x$$$ with $$$x$$$ and $$$0$$$, $$$4x$$$ with $$$2x$$$ and $$$0$$$, and so on.

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

          i understand how to get $$$kx$$$ from $$$(0, x)$$$, if we have ((k-2)x, (k-1)x) then $$$2*(k-1)x - (k-2)x = kx$$$. Ok we got $$$g_0s, x_nt$$$, what we should do to get $$$g_0s - x_nt$$$?

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

            Bézout's theorem states that there exists $$$x$$$ and $$$y$$$ so that $$$ax + by = gcd(a,b)$$$. So you can say having $$$g_0s-x_nt$$$ that there exists $$$s$$$ and $$$t$$$ such that it equals $$$gcd(g_0,x_n)$$$. Note that you only need to say if it's possible, not how would you get the number on the board. So once you get $$$g = gcd(g_0,x_n)$$$ (I call it $$$g$$$ to be consistent with the naming in the editorial, as $$$g_0 = gcd(x_2,x_3,x_4,\dots,x_{n-1})$$$) by some amount of operations on the board, it means $$$k$$$ has to be a multiple of $$$g$$$ to be possible to write in the board, and you would do it the same way you got all other gcds before. So that's why at the end we check if $$$k \equiv 0 \pmod{g}$$$.

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

              Note that you only need to say if it's possible, not how would you get the number on the board.

              we need prove it. By induction we got $$$g_0$$$,now we need get $$$g$$$. by Bézout's theorem states there're exist $$$s, t$$$ such that $$$g_0s - x_nt = g$$$, but why we can get $$$g$$$, using operatin $$$2x-y$$$ and some numbers already written down on board like $$$0, x_2, \dots , x_n-1,x_n, g$$$, previosly found gcd's and something else.

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

                The editorial describes the process where you get to $$$g_0$$$ as "recursive". And as I far as I understand and was mentioned in the comments, it means first you had to get $$$x_2s-x_3t = gcd(x_2,x_3)$$$ on the board first, let's call it $$$v_1$$$. Then you got $$$v_2 = v_1s - x_4t = gcd(v_1,x_4)$$$, then $$$v_3 = v_2s - x_5t = gcd(v_2,x_5)$$$ and so on. With that method you got to the last step where in the same way you get to write $$$g$$$ on the board. Therefore, if $$$k$$$ is equal to $$$g$$$ or some multiple of it, it can be written on the board.

                Also, thinking it logically, it makes sense. If all numbers previously written are multiple of some number, multiplying them by two and subtracting another of the numbers in an operation, means you'll never have a way to write some number which is not multiple of it. That's even what's in part described in the first direction of the proof in the editorial.

                About making a really formal proof, I'm not used to making them, so unfortunately I'm unable to come up with one. But based on what's said in the editorial, what was commented by other people and with my logic, seems to work for me. If you still feel unconvinced of the correctness of the solution, you can try to prove it by yourself, try solving as many cases as you want to get to a conclusion. After all, I think it's pretty rare to be proving some solution during a contest, and it always depends more if you are convinced of a solution. Of course I'm also trusting that the authors have made all the possible things they could to be sure of the correctness of the solution. But nevertheless if you find some way it doesn't work, you can always point it out.

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

                  omg, it's common words about why this solution correct. I believe that it's correct, but me need a prove of correctness, only one part of it i don't understand. In induction we need to strictly prove base case and jump from $$$n$$$ to $$$n+1$$$, it does not matter that we assumed until $$$n$$$ we wrote down other gcd's not clear how.

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

              $$$g$$$ should be written down on the board, then we can write down k

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

      Great explanation thank you.

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

      This is so much better than the editorial's explanation.

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

Nezzar For F, it looks like the coefficient of $$$x^{k-1}$$$ in $$$Q_j$$$ should have $$$1/(k-1)!$$$ instead of $$$1/k!$$$.

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

Missed the part in DIV2C that integers of the array will be distinct. smh.

Can it be solved if elements of the array were not distinct?

Like, $$$d[] = 16, 16, 16, 18, 20, 22, 22, 26$$$

here, $$$a[] = 1, -1, -1, 2, -2, 3, 3, -3$$$

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

Div2D, what is the meaning of sentence "(Otherwise, we could subtract x1 for x1,x2,…,xn and k)"?

We can somehow transform x1 to 0, if yes, how?

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

    You can imagine that he moves base point $$$O$$$ from $$$x = 0$$$ to $$$x = x_1$$$ in $$$x$$$-axis.

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

        The answer depends on the relative positions of $$$x[]$$$ and $$$k$$$ instead of the absolute positions, so substracting $$$x_1$$$ from all elements at the same time won't change the answer, then we get $$$x_1=0$$$.

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

          can you please explain the last line of editorial of Div2 D ,

          Therefore, we could write down $$$g$$$ applying operation recursively.

          I didn't understood how to do that.

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

            According to the editorial you can write down gcd of two numbers. "recursively" means then you can write down gcd of three numbers (by using the previous gcd and another number), and then gcd of more numbers, until gcd of $$$n$$$ numbers.

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

              Isn't that saying that because we can make $$$g_0$$$ and $$$x_nt$$$ and thus we can some how make $$$g_0s-x_nt = g$$$ by applying the operations ?

              In second part of proof we need to show that any number divisible by $$$g$$$ can be written down . If we show that $$$g$$$ can be written down then it's obvious that anything divisible by $$$g$$$ can written down by taking $$$y=0$$$ .

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

                I think it means the same if you understand how to write down gcd of two numbers. The difference is, my explanation is from gcd of two numbers to gcd of n numbers, editorial is from gcd of n numbers to gcd of two numbers (cuz it's induction).

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

                  Ok , so you mean that because for $$$n=2$$$ our statement holds , thus we can say that $$$g$$$ can be created out of $$$g_0$$$ and $$$x_nt$$$ . And thus we can say that all number divisible by $$$g$$$ can be created .

                  So in last part of proof , we are using the fact for $$$n=2$$$.

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

                  Editorial derive $$$g$$$ from $$$g_0$$$ and $$$x_n$$$, and you can also imagine, before that, you derive $$$g_0$$$ from $$${g_0}_0=\gcd(x_2,\dots,x_{n-2})$$$ and $$$x_{n-1}$$$. Keep similar operation then you will realize the whole process is all correct.

                  I can't really get what makes you confused. Maybe learning "What is Induction" would help you.

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

    "substract x1 from x1,x2,...,xn and k"

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

    You can see that any solution in the transformed set is a solution in the original set because $$$2x - y$$$ is the reflection of $$$y$$$ over $$$x$$$, and these reflections are invariant to shifts such as in the transformed set.

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

      omg, I thank you all for trying to explain ;) But such sentence with another 3 or 5 new terms is not helpful.

      I understood that for some reason we can shift all numbers by any amount, and for another reason we do shift by x1, so we transform that element to 0.

      Then, for some reason, we can directly use the gcd() of the remaining numbers to check if k is a multiple of it, which determines ans.

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

        Try picking a couple $$$x$$$ and $$$y$$$ pairs and draw them in the number line, along with $$$2x−y$$$. Try to find a pattern there, it might be useful to get an intuition to why we can find a solution using the numbers with a fixed offset.

        The reason we want one element to be $$$0$$$ is because then we can use it allows us to construct some more predictable and useful numbers. For example if we do the operation $$$2x−y$$$ with $$$x=0$$$, the result is $$$−y$$$, and if we do it with $$$y=0$$$ the result is $$$2x$$$, see some discussions above to more details on why this will help solve the problem. Also we can shift by any other number, not necessarily $$$x_1$$$.

        The argument for the gcd I still have not figured it out. This editorial is pretty obscure (not surprising, sadly).

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

        Operation we apply : $$$2x - y$$$ . Suppose we subtract $$$x_1$$$ from $$$x$$$ and $$$y$$$. Then $$$2*(x-x_1) - (y-x_1) = 2*x-y-x_1$$$ . So you can see that final answer is subtracted by $$$x_1$$$.

        Thus converting to $$$k$$$ from $$$x$$$ and $$$y$$$ is same as converting to $$$k-x_1$$$ from $$$x-x_1$$$ and $$$y-y_1$$$.

        I showed for only one operation but it's not hard to see for multiple operations.

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

1477B - Nezzar and Binary String can be solved without a segment tree. The idea is to keep subarrays with equal digits in a set. The complexity of the operations for each move is $$$O(\log(n))$$$ amortized.

AC submission: 105757658

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

105785851 Why does this brute force sol work for div2 B? Shouldn't it give a TLE in the worst case?

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

problem D editorial proves the solution but doesn't gives any intuition behind coming up with the solution . Can some one tell their lane of thought which brought them to the solution ?

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

    I can offer my thinking process in this problem.

    Noticed that $$$2x-y=x+(x-y)$$$, so actually for a $$$x$$$ we can move it to $$$x + k \cdot dis(x, y)$$$ for any $$$k$$$ and available $$$y$$$. Then according to Bézout's Theorem, I found that $$$x$$$ can be moved to any $$$x + k \cdot \gcd(dis(x, others))$$$.

    A fun observation is, in $$$2x-y$$$, coefficients are $$$2,-1$$$ and the sum of them is $$$1$$$. Actually, I think it seems impossiable to solve if we change it to $$$3x-y$$$, but $$$3x-2y$$$ or $$$3x-y-z$$$ or something seems much more solvable. I can't explain it well because my English suck, sorry.

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

      Hey Nanako

      I found that X can be moved to any X+K*gcd(dis(X,others)).

      how you found that!?

      What if the k*gcd is smaller than the diffs we can add !?
      Example:
      K=52
      arr=[7, 27, 42] so the gcd(diffs)=gcd(20, 15)=5
      42 + 2*5 = 52
      to get 52 we need to add 2*5 to 42, but we can't do that using the real diffs (20, 15) I know we can get it using some (subtractions , additions) of these diffs but I'm not sure how I can think about it intuitively.

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

        Sorry for replying lately. I guess it will become more and more intuitive after you solve more and more problems about Bézout's Theorem and ex-gcd (Chinese nickname of Extended Euclidean algorithm? lol) and other number theories. :)

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

    Given x and y, we can get $$$x + t * (y - x)$$$ for all t. So this is an arithmetic sequence. We draw it on an axis.

    Now given another number z. We find a closest point on the axis and draw the new arithmetic sequence produced by z and the closest point. If the distance of z and the closest point divides $$$y - x$$$, then all points is just one arithmetic sequence which is $$$z + t * distance(z, closest point)$$$. Otherwise, we can find another two more close points and produce more points. You can see that only when the distance of two closest points divides both $$$y - x$$$ and $$$z - x$$$ and $$$z - y$$$, the process will stop. So $$$z + t * gcd(y - x, z - y)$$$ can be produced.

    You can draw it on a paper and get the intuition.

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

1477A — Nezzar and Board

Explain me how we can write down $$$g_0s-x_nt$$$ which is equal $$$g$$$?

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

video editorial for problem D, if theres anyone whos stuck! https://www.youtube.com/watch?v=yYxQ9_EL69Q

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

for 1478B, here is my solution https://mirror.codeforces.com/contest/1478/submission/105779176 in a bit different style than author ;) , although I fucked up during the contst!:(

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

For problem B I assume that $$$x$$$ can be represented as $$$ x = y + w.d $$$. Then, $$$ y = x - w.d $$$ and just check that $$$y$$$ has at least one digit equal to $$$d$$$. By brute force I concluded that $$$w$$$ is at most $$$9$$$ because for $$$x \gt = 10.d $$$ the answer is always YES.

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

The system test of problem C is weak! Some people use double and sqrt to calculate distance, it can be hacked, like this, but it passed the system test.

I noticed this and resubmitted my code, after the contest, I know that the original code could pass, if I didn't resubmit, I'll be International Master! ):

update: This seems to work only for GNU C++17 (64).

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

Could anyone help me about this https://mirror.codeforces.com/blog/entry/87299 ? Thanks!

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

In problem D of div2, why always subtracting x1 from all other numbers works? Means the cases can't be there such that we need to subtract x2 from all the numbers and take gcd after that?

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

For anyone not knowing what WLOG means in editorial for Div.2 C,
WLOG = Without Loss Of Generality.

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

Very nice problems!

I like div.1C very much.

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

For Div2 B how can N=21 and D=2 gives answer yes?

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

Can someone tell the mistake in the following code of mine for Div2B: 105802694 For each integer i from 1 to 9 I stored the smallest integer 1<=j<=10, that give the unit digit (i*j)%10 when multiplied with as a[i][(i*j)%10] = j So if the number in query (say c) had a unit digit l that can be found in a multiple of d, I check if c is greater than or equal to the minimum multiple of d that gives that unit place. If yes, then I output YES as I think all such numbers can be represented using lucky numbers. Else, I output NO as d in unit places has minimum effect, so if we have even one d in tens place, then it becomes greater than c. Now if the units place l in c cannot be found in a multiple of d, then I check if c/10 is greater or equal to d. If yes then I print YES else no, as d cannot even come in tens place then. Can I get a testcase where this fails?

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

Problem B :

say d = 7, so 70->79 already lucky, we can generate 80->89 as follows

72 + 17 = 89
71 + 17 = 88
70 + 17 = 87
79 + 7 = 86
78 + 7 = 85
77 + 7 = 84
76 + 7 = 83
75 + 7 = 82
74 + 7 = 81
73 + 7 = 80

similarly, we can generate 90-99 from 80-89 and so on ......

so, any number >= 10*d is lucky

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

Nezzar please explain DIV2C

Why in you solution following code gives $$$a_1$$$ in $$$b[n-1]$$$?

for (int i=1;i<n;++i) {
    b[n-1]-=2*i*d[i];
}

And why are you checking this condition b[n-1]%(2*n) in the end?

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

Nanako Can you please explain the relation in the editorial of Div2 C ? This one.. "More importantly, we have the following relation:".

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

    Main observation is, when there are $$$n - x$$$ elements smaller than the current position and $$$n + x$$$ elements bigger than the current position, if you move left for 1 unit length, $$$\sum |curpos - a_i|$$$ will increase $$$2x$$$.

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

I found this contest really nice (especially div1 D). Thanks for the contest :)

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

Chinese round! Unfortunately I still can't take part in due to the time (.

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

On div2 D,

if((arr[0]%gcd) == (k%gcd)) printf("YES\n"); ... => WA

if((k-arr[0])%gcd == 0) printf("YES\n"); ... => AC

I really wonder why this thing happens.

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

div2C symmetric array

I tried another approach:

Assume that the "d" array (the sum array) and the "a" array (initial array) are sorted. I redefined the "a" array so that it would only contains positive numbers.

Since the two arrays are sorted $$$a[n - 1]$$$ and $$$d[n - 1]$$$ would become the largest element of respective array. I observed that if we choose any index i (0 <= i < n), then the sum $$$|a[n - 1] - a[i]| + |a[n - 1] - (-a[i])|$$$ would become $$$|a[n - 1] - a[i]| + |a[n - 1] + a[i]| = a[n - 1] - a[i] + a[n - 1] + a[i] = 2a[n - 1]$$$ (since a[n — 1] is the largest element). This applies to every other index 0 <= j < n — 1.

Then a[n — 1], or the largest element of the "a" array (initial array) can be calculated using this formula: $$$d[n - 1] = a[n - 1] * 2(n - 1). $$$ By expanding more, I could also prove that: $$$d[n - 2] = 2a[n - 1] + 2(n - 2) * a[n - 2].$$$

Hence I could restore the initial array with following formula: $$$d[j] = \sum\limits_{i=j+1}^{n - 1}{2a[i]} + 2j * a[j]$$$, with j being the index in the sorted array. Furthermore, since all d[j] % 2 == 0 from above formula, I could throw away any cases that had any d[i] that is odd.

The problem is I can't make sure if the array constructed was right or wrong. So I tried calculating everything again from the constructed array, and also noticed if any element in that array was 0 it was wrong. Can anybody pls check it out lol

105799882

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

In Div2 C how are we checking that whether a[0] can be made form d[0]. The a and d I am refering to are problem statement a and d.

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

Div1 D is awesome . Thank you!

It took me about 4 hour to come up with the solution . A very nice problem !

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

In Div1.A why can we assume $$$x_1=0$$$? I can't understand.

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

For Div1B (Nezzar and Binary String), could someone explain how the 3rd sample input test is possible? I've been thinking a while but I'm quite confused.

10 6
1111111111
0110001110
1 10
5 9
7 10
1 7
3 5
6 10

If we follow the editorial, we should work backwards starting at 0110001110, we need 6-10 to be the same before the last night's inspection so it becomes 0110011111. Then we need 3-5 to be the same so it becomes 0100011111. Then we need 1-7 to be the same so it becomes 0000000111. Then we need 5-9 to be the same and it becomes 0000000001. Finally we need 1-10 to be the same so it becomes 0000000000, but this is not 1111111111, so it doesn't seem to be possible?

Edit: Thanks Nezzar, I wrote the math for this out like 5 times on notebook paper and kept getting the same result, I have no idea how I missed that query every time..

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

I'm confused by some of the implementation in Div1 D. I think the dfs function creates the spanning tree of the complement graph, is this right? The loop with while(d.size()) seems to do the decomposition into stars, but if I'm not mistaken it doesn't use the same method described in the editorial. What I get from this is that you choose an unassigned node from d in idx, then choose one of it's neighbours f to be the center of your star graph? Why this particular ordering of vertices in d?

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

    Sorry if it causes any inconvenience. Codes were written by me while tutorial for d1D was written by Nezzar.

    Approach to decomposite spanning trees into stars in the code was to choose an arbitrary leaf in the tree, find its neighbor vertice $$$u$$$, and choose all neighbor vertices of $$$u$$$ with degree $$$1$$$ to form a star. It can be shown that the remaining graph after deletion of this chosen star is still a tree with more than $$$1$$$ vertices or empty.(Therefore, we could decompose tree into stars applying this method recursively.)

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

For div1F, the $$$m$$$-th coefficient of $$$Q_j$$$ should be $$$\frac{1}{m!}(1 - q_{m,j})\left(\frac{L_j}{L}\right)^m$$$

and the OGF of $$$k! \sum_{n \geq 0} \binom{n + k}{k}C^nx^{n+k} = k! \frac{x^k}{(1-Cx)^{k+1}}$$$

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

A much better solution for div2 B than DP is that if the number is $$$ \geq 10*d$$$ then it is always possible, otherwise we can observe that the only numbers less than $$$10*d$$$ that contain $$$d$$$ are, $$$10 + d, 20 + d, 30 + d, \dots$$$ Hence, if a number is feasible then it can be represented as: $$$10*x + d*y$$$ where $$$x$$$ and $$$y$$$ are variables.

I'm livid I didn't come up with this during the contest lol.

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

In Problem C : Can anyone explain why the biggest element in array d is always 2*n*(biggest element in d) supposing arrays d and a are sorted then a[n]*2*n=d[n] why?

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

    Each element has a positive and negative value. Supposing the positive value is $$$ x $$$, and the absolute difference to $$$(y, -y)$$$ would be $$$| x - y | + | x + y | $$$. Similarly, for $$$ -x $$$, that would be $$$ |-x - y | + |-x + y |$$$, which is also $$$|x - y| + |x + y|$$$.

    For $$$|x - y| + |x + y|$$$, we have two different cases. For $$$x \gt y$$$, $$$|x - y| + |x + y|$$$ would be $$$ 2 * x $$$. For $$$x \gt y$$$, $$$|x - y| + |x + y|$$$ would be $$$ 2 * y $$$. Now we know that $$$|x - y| + |x + y|$$$ = $$$2 * max(x, y)$$$.

    For each $$$ d[i] $$$, it is the sum of each absolute differences from $$$a[i]$$$ to all integers. Combined with the previous finding, we got

    $$$ d[i] = \sum_{j=1}^{2n} max(abs(a[i]), abs(a[j])) $$$

    Supposing the max element is $$$a[n]$$$. As $$$a[n]$$$ is greater than other elements, Then, we have

    $$$ d[n] = \sum_{j=1}^{2n} a[n] $$$

    Therefore, you got $$$d[n] = a[n] * 2 * n $$$.

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

Can anyone please elaborately explain me B ( Lucky number one ) I'm struggling to understand the solution by Dp, I am a newbie so please be considerate, CF is extremely harsh and often hostile to beginners.

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

    Try thinking about it like this: Suppose the number you are trying to check is $$$x$$$, If $$$x$$$ is achievable then it can be represented as $$$x = a + b$$$, where $$$a$$$ is a number with $$$d$$$ as one of it's digits and $$$b$$$ is a number that is also achievable.

    The only possible values for $$$a$$$ are: $$$d, 10+d, 20+d, 30+d, \dots$$$

    The line: dp[10*i+d+j]|=dp[j]; is checking just that! $$$10*i + d$$$ represents all possible values of $$$a$$$ and $$$j$$$ represents any number that is achievable. Hence, if $$$j$$$ is possible then $$$10*i + d + j$$$ is also achievable.

    Hope it helps!

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

Div2D was a very nice task, but i miss a more detailed editorial's explanation.

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

For 1478D - Nezzar and Board, suppose we have the numbers 0, a, b, c. Then how can we generate 3a — b + 5c? Since we are using Bezout's Identity, then ax + by + cz = d must exist $$${\forall}$$$ x,y,z $$${\epsilon}$$$ $$$\mathbb{Z}$$$

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

In the Nezzar and Board problem, I find it difficult to understand why "If g = GCD(x1,x2,x3,....,xn) divides k, then YES, else NO" doesn't work, but the given logic in the Editorial does. Also, I am not able to comprehend the proof given. Can someone explain? Thanks in advance!

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

Unable to parse markup [type=CF_MATHJAX]

$

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

There is a more elegant (imo) way of finding stars in D1D: greedily remove an edge $$$(u, v)$$$ from the spanning tree, as long as both $$$u$$$ and $$$v$$$ have degrees strictly larger than 1. It can be proven that the remaining graph consists of stars. Great problem though!