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

Автор iNNNo, история, 22 месяца назад, По-русски

Спасибо всем за участие!

1979A - Угадай максимум

Решение
Код

1979B - XOR последовательности

Подсказка
Решение
Код

1979C - Заработать на ставках

Подсказка
Решение
Код

1979D - Исправление бинарной строки

Решение
Код

1979E - Манхэттенский треугольник

Подсказка
Решение
Код

1979F - Теорема Костяныча

Решение
Код
Разбор задач Codeforces Round 951 (Div. 2)
  • Проголосовать: нравится
  • +74
  • Проголосовать: не нравится

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

C can be solved with Binary search,in case you have not thought of solution and still solved C using youtube and telegram,then it might help you.

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

An alternate solution for D using hashing: the final string will be of form $$$s_{p+1}\dots s_n s_p\dots s_1$$$ and must either start with a block of $$$k$$$ 0s or $$$k$$$ 1s. Generate the two possible final strings ($$$111\dots000\dots$$$ or $$$000\dots111\dots$$$), then iterate over $$$i$$$ and check if either of the two answer strings match this condition:

  • Prefix of length $$$n-i$$$ is equal to $$$s_{i+1}\dots s_n$$$
  • Suffix of length $$$i$$$ is equal to $$$s_i\dots s_1$$$

Using hashing, each of these checks can be done in $$$O(1)$$$ for every position.

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

finally became green

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

justice for 6k rank for doing 3 problems in div2:(

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

Visual for 1979E

Animation showing valid points for pairs of points (in red and blue) that are $$$d=6$$$ Manhattan distance away from each other. The black dots are points that are both $$$d$$$ Manhattan distance away from both red and blue points. The black line shows how there always exists a pair of points in a triangle such that they are $$$(d/2,d/2)$$$ or $$$(d/2,-d/2)$$$ off.

Here's a Desmos graph with draggable points if you want an interactive version. https://www.desmos.com/calculator/na6auayf25

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

    This is very cool! What did you use to make the animation?

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

      I used the processing.js library on Khan Academy's coding environment with the following code.

      Rendering Code

      Then I recorded screen and exported as gif.

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

      can you explain how one can reach to a conclusion that in manhattan triangle at least one pair lies on line with slope 1 or -1 ???bananasaur

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

        The way I did it is by drawing a lot of cases on paper. One of the three points will always have the minimal or maximal $$$x$$$ value, as well as the minimal or maximal $$$y$$$ value. (To prove this: There are at least 2 points with minimal/maximal $$$x$$$ alone, and 2 with minimal/maximal $$$y$$$ alone. There are only 3 distinct points, so using the pigeonhole principle we can conclude at least one point fits both categories.)

        Now make a rectangle with the other two points as opposite corners. We can split the path from the first point to these other two points as (first point -> rectangle corner) and then (rectangle corner -> second/third point). The path from the point to the corner is the same for both the second and third points. Since we know both points are at a distance $$$d$$$ from the first point, the distances from the rectangle corner to the second and third point must be the same. This means the rectangle is actually a square and hence the points lie on a line with slope 1 or -1 (the diagonal of a square).

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

Any idea how I can improve my logic? some questions just don't click sometimes. I seem to be practicing consistently, but the results are not showing. I don't know why

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

    you're either doing practice with too hard or too easy problems, try changing the difficulty and solve problems on multiple platforms other than codeforces

    However, improvement takes a long time to see and you should not give up

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

https://mirror.codeforces.com/contest/1979/submission/264505456

Hey guys this is a solution for C using binary search but I think this approach is wrong and inconsistent with the problem If you agree Please someone hack the solutions that used this approach. If I am wrong please explain why this works?

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

Does anyone have a proof of why the hint for E is true?

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

    First, draw the graph from $$$(x, y)$$$ to all the points which can be at distance $$$d$$$. It will look like a square rotated by $$$45°$$$. Now, if one of the point of our answer is one of the diagonal points $$$(x \pm d / 2, y \pm d / 2)$$$, then we are done (the condition satisfies). Now, after some observation on the graphs (and drawing pairs on the square which have distance d in them). You can notice that if none of the diagonal points are used then the other $$$2$$$ points are on the same side/line (there are $$$4$$$ sides of the square). And thus, the condition is again satisfied. (since if we take the square from any one of them, the other would be diagonal point).

  • »
    »
    22 месяца назад, скрыть # ^ |
    Rev. 2  
    Проголосовать: нравится 0 Проголосовать: не нравится
    1. The hint's observation is equivalent to the fact that 2 points are on the same diagonal.
    2. Prove by contradiction: Take (x1, y1) and (x2, y2), s.t. distance equals to d and they are not on the same diagonal. The set of all points that are d units away forms a 45°rotated square. Now imagine all points that are exactly d units away from first point — set S1, or the second point — set S2. The third point is one of the points that are in both S1 and S2 (intersection of S1 and S2). But this third point is on the side, that is intersecting either first point, or second point. Thus, it is surely on the same diagonal.
»
22 месяца назад, скрыть # |
Rev. 3  
Проголосовать: нравится +18 Проголосовать: не нравится

F is just mind blowing, very elegant and very nice : )

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

Can someone explain the hint of E? Why/How is it true?

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

    Assume on $$$x$$$ axis sides give projections of $$$n,m,n+m$$$. Then on $$$y$$$ axis we must have $$$d-n,d-m,d-n-m$$$. Two of them sum to the third, so $$$2d-2n-m=d-m$$$, so $$$n=\frac{d}{2}$$$, which is what we wanted.

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

    First, draw the graph from $$$(x, y)$$$ to all the points which can be at distance $$$d$$$. It will look like a square rotated by $$$45°$$$. Now, if one of the point of our answer is one of the diagonal points $$$(x \pm d / 2, y \pm d / 2)$$$, then we are done (the condition satisfies). Now, after some observation on the graphs (and drawing pairs on the square which have distance d in them). You can notice that if none of the diagonal points are used then the other $$$2$$$ points are on the same side/line (there are $$$4$$$ sides of the square). And thus, the condition is again satisfied. (since if we take the square from any one of them, the other would be diagonal point).

  • »
    »
    22 месяца назад, скрыть # ^ |
     
    Проголосовать: нравится 0 Проголосовать: не нравится
    1. The hint's observation is equivalent to the fact that 2 points are on the same diagonal.
    2. Prove by contradiction: Take (x1, y1) and (x2, y2), s.t. distance equals to d and they are not on the same diagonal. The set of all points that are d units away forms a 45°rotated square. Now imagine all points that are exactly d units away from first point — set S1, or the second point — set S2. The third point is one of the points that are in both S1 and S2 (intersection of S1 and S2). But this third point is on the side, that is intersecting either first point, or second point. Thus, it is surely on the same diagonal.
»
22 месяца назад, скрыть # |
Rev. 4  
Проголосовать: нравится +9 Проголосовать: не нравится

Another approach in problem E, which reduces the amount of code to write: 264470284

Solution

Let's observe that all the points on the distance d(in Manhattan metrics) from a fixed point make up a square with a diagonal of length 2d. With this knowledge we can rotate the plain by 45° and scale it, so that the sides of those squares are parallel to the axises and have integer lengths.

After that the solution is easy: we have to find two points on a vertical or horizontal line, the distance between which is d. Let's call those points A and B. The third point has to lie on CD, where ABCD is a square.

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

can anyone explain D using bitmask ??

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

Can anyone explain me problem D using bitmask

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

just checking sum=10^9 gives AC in problem C.

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

Can anyone explain why for D in the following sample case

4 2
1110

the verdict is -1.

Can't we take p = 1, the transformation would then be 1101 which is 2-proper as s1 = s2 = '1' and s1 != s3

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

264505361. My sol to B.

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

D can be solved with FFT:

(note that polynomials are $$$0$$$-indexed while arrays are $$$1$$$-indexed and this is a somewhat overengineered solution)

first the non-fft part: if a p is "ok", then first_k($$$a[p + 1; n] + rev(a[1; p])$$$) (i.e. the first k elements in the new array) must be equal;

we can simply count it in an array $$$e$$$ with $$$e_i = \text{maximum number}$$$ s.t. $$$a[i; i + e_i]$$$ are all equal

for every i it must hold that $$$new_a[i] \ne new_a[i + k]$$$. this can be precomputed for all indices except for the indices in $$$[i - k; i)$$$ with $$$rev((p - k; p])$$$ (since $$$new_a = a_{p+1} a_{p+2} ... a_n a_p a_{p - 1} ...$$$, we need to check that $$$a_n \ne a_{p - k}, a_{n - 1} \ne a_{(p - k) - 1}$$$) Note that while the lhs is decreasing, the rhs is increasing.

now we can use fft to check whether that conditions holds for all indices: Let $$$P_1 = c_1 * x^k + c_2 * x^{k + 1} * ... * c_n * x^{k + n}$$$ be a polynomial of degree $$$n + k$$$ and $$$P_2 = c_{n - k + 1} * x^0 + c_{n - k + 2} * x^1 + ... + c_n * x^k$$$ a polynomial of degree $$$k$$$.

If we multiply both polynomials we get the following polynomial:

$$$P_{res} = ... + (c_1 * c_{n - k + 1}) * x^k + (c_1 * c_{n - k + 2} + c_2 * c_{n - k + 1}) * x^{k + 1}$$$
$$$+ ... + (c_1 * c_n + c_2 * c_{n - 1} + c_3 * c_{n - 2} + ... + c_k * c_{n - k + 1}) * x^{2k}$$$
$$$+ ... + (c_{n - k + 1} * c_n + c_{n - k + 2} * c_{n - 1} + ... + c_n * c_{n - k + 1}) * x^{n + k} + ...$$$

Each coefficient should represent "how different" $P_1$ and $$$P_2$$$ are (at that position), so we can choose $$$c_i = 1$$$ if $$$a_i = 1$$$, $$$c_i = -1$$$ otherwise. If we multiply two equal numbers, i.e. $$$1 * 1$$$ or $$$-1 * -1$$$, we both get the result $$$1$$$, while the result of two different numbers is $$$-1 * 1 = -1$$$. So a "more negative" result means a bigger difference in the strings. In the "middle" of the string ($$$k \le p \le n - k$$$), it is enough to check whether $$$[x^{k + i - 1}] P_{res} = -k$$$ ($$$[x^{k + i}]$$$ is the coefficient of $$$x^{k + i}$$$), since that means that all values in a are different.

If e.g. $$$k = 2$$$ and $$$p = 2$$$, the resulting bitstring is: $$$a_3 a_4 a_5 ... a_n a_2 a_1$$$, i.e. we only need to check whether $$$a_n \ne a_1$$$. Luckily $$$P_1$$$ "starts with" $$$x^k$$$, i.e. $$$[x^k] P_{res}$$$ is $$$c_1 * c_n$$$, which is the check of "is $$$a_n \ne a_1$$$"; exactly what we need! So in that case we only have to check whether $$$[x^{k + i - 1}] P_{res} == i$$$

But what about $$$p \in (n - k; n]$$$? Similar to the case where $$$p$$$ is small, we have to consider less than k values; e.g. for $$$p = n - 1, k = 2: a_n a_{n - 1} a_{n - 2} ....$$$

Here we have to compare $$$a_n$$$ and $$$a_{n - 2}$$$, but $$$[x^{k + (n - 2) - 1}] P_{res} = c_{n - 2} * c_n + c_{n - 1} * c_{n - 1}$$$. Since we are now additionally comparing $$$a_{n - 1}$$$ and $$$a_n$$$ (and for other $$$p/k$$$ the last $$$k - (n - p)$$$ values are compared "within the array itself"), we have to "correct" this by "undoing" the fft ops (add $$$-1/+1$$$ depending on whether two of these duplicate comparisons match).

With this information it is enough to iterate over all possible $$$p$$$ and check in $$$O(1)$$$ if all conditions hold. (we also have to exit early if we encounter some $$$a[p] \ne a[p - k]$$$ since some $$$p$$$ is only "ok" if all indices after it in the new sequence still "match" (and reversing $$$a_1 a_2 ... a_p$$$ doesn't really change that condition, so $$$a[p] \ne a[p - k]$$$ is enough)

since fft runs in $$$O(n \log n)$$$ and the rest is $$$O(n)$$$ the total runtime is $$$O(n \log n)$$$

Proof by AC: https://mirror.codeforces.com/contest/1979/submission/264505623

Edit: Formatting

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

For problem C :

I used Binary Search.

I guessed total number of coins. For every mid, I go through all bets and calculated minimum coins are needed to be bet on i-th position. Then if total number of required coins is less or equal than my mid then it’s okay to bet that amount of coins.

If no valid mid found then simply it’s impossible.

Using this strategy, I calculated the minimum possible coins that satisfies the conditions.

After that I distributed the coins for every i-th bet such a way that if I win i-th bet I get at least tootal coins. If some coins stays unused, then I distributed the remaining coins among all bets almost equilibrium way.

Finally I checked wheather any position I bet more than 1e9 or not. If yes, then I said it’s impossible otherwise this is the answer. (I don't know is it required to check, it may not affect the solution but I remained in safety).

I think this binary search approach is more easy to understand with less mathmatical calculation .

My submission : 264454935

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

E: https://usaco.org/current/data/sol_triangles_platinum_feb20.html

D: Suppose we split s into a+b where a has p characters. Then, the end result is b+rev(a). I find it helpful to take note that if s is proper where k is a factor of n (in other words the string ends with a block of length k), then so rev(s), so we just need rev(b+rev(a))=a+rev(b) to be proper.

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

Guessforces on problem B. The fourth test case was a huge giveaway when I saw it was a power of two.

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

very good contest,adds me 200 points

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

Can someone explain more intuitively why checking for 1e9 and lcm works in problem C?

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

    1e9 --> simply if this does not work for max number of coins then it will never work, Probability of the condition working increases with increase in number of coins as Multiplication function rises faster than addition.

    LCM --> just use basic algebra on ki*xi > Sum(xi), you eventually reach 1 > Sum(1/ki). Common thing between 1/ki and LCM is that in both cases you ignore common factors or take their frequency as 1.

    I can only explain both mathematically because I am used to doing everything this way, maybe writing it out will help you, write the equation down and use a rough graph in 1e9 case if you are comfortable with basic algebra and drawing rough graphs, hope this helps.

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

      Still the 1e9 condition does not guarantee that if there is a sum>=1e9 then there will always be a sum for numbers <1e9(let's consider the number to be x) for whom sum>x. There might be numbers<1e9 for which there exist a solution even though there does not exist a solution for 1e9.

      For example let's take {2,3,7} as the given array and let's take our value of x as 43. so for 43 the bet array will be{(43/2)+1,(43/3)+1,(43/7)+1}={22,15,7} and their sum is 22+15+7 which is greater than 43. So there exist no solution according to the 1e9 logic it means. But if we take 42 there exist an answer.

      So I think the testcases are so designed that this logic works but it will not work for more precise testcases I guess.

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

I have some intuition for E I would like to share including one way you could have proved the hint.

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

Can someone explain C to me again? I mean, why the condition SUM(S/ki) < S ??

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

    we have to find x1,x2,...,xn such that

    x1 + x2 + ... + xn = S

    x1*k1 > S -> x1 > S/k1

    x2*k2 > S -> x2 > S/k2

    ....

    xn*kn > S -> xn > S/kn

    thus S = x1 + x2 + ... + xn > S/k1 + S/k2 + ... + S/kn (or SUM(S/ki) < S)

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

I guessed B and C. in B answer was 2^lowestbiton(a xor b) in C numbers just turned out to be lcmofwholearray/arr[i] (and if it does not work print-1 )

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

How I see problem E, is that if there is a Manhattan triangle, it can always be seen as having a first point $$$(x, y)$$$ and two other points having in a certain common relative direction to that first point — one of the two is on diag1, the other is on diag2 (just the segment, not the infinite line), and the two diagonals intersect at, WLOG, assuming the common direction is to the right, $$$(x+d, y)$$$. The image looks something like this:

I actually managed to forget that without an anchor at either $$$(x + \frac{d}{2}, y + \frac{d}{2})$$$ or $$$(x + \frac{d}{2}, y - \frac{d}{2})$$$, the two on-diagonal points may not have the distance to each other at $$$d$$$. Silly me, this costed my chance for a quick jump to 1950-2000ish given that I solved ABCD absurdly quickly, and I AC'd E in like 3 minutes after figuring out the mistake. :(

Well, another lesson to take anyway.

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

Some $$$O(n^2)$$$ Solutions(264481866) passed problem D easily.

Why $$$n \le 10^5$$$?

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

Could someone please explain how the condition given in solution of C is sufficient? We have not taken into account that the bet placed on any outcome needs to be an integer right?

But if we do take that into account, the necessary and sufficient condition then looks like (sigma 1/ki)+(n/S) <= 1, where we don't know S.

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

    If the condition is met, you can always choose an S that is multiple of any of the k's by picking S = LCM(k_1, k_2, ... k_n). Thus any S/k_i will result in an integer making the equation trivial.

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

It was quite a nice contest! Altough it would've been better if some losers didnt cheat problem C. Very good contest!

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

Earning on bets detailed video editorial

https://youtu.be/tipb5tYyHAQ?feature=shared

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

F is a good problem, but there are a few issues in the solution!

"at least (n−2) edges missing" should be "at most".

$$$\dfrac{n(n - 1)}{2} - (n - 2) - (n - 1) - (n - 3) + 1$$$ should be $$$\dfrac{(n - 2)(n - 3)}{2} - (n - 4)$$$ (not $$$n - 3$$$), thus the invariant is keeped!

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

    Thanks!

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

      in problem F, imagine the following case that 5 vertices have degree = n — 1. And when solving the problem recursively say we needed to query "? d" {d <= n — 3} and imagine no vertices have degree between [d , n — 2]. Clearly the answer to any such query will be the same as answer of "? n — 1" . How will we proceed in such a case , as we have no way to know which vertex had degree >=d ? {There will be uncertainty}

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

Если что есть конвертор c++ в Perl или Python

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

Guessforces!!

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

can any one give me a proof about this fact from tutorial

Note this fact: in every Manhattan triangle there are two points such that |x1−x2|=|y1−y2|.

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

a lot of users solved B using:

d = x ^ y
ans = d & -d

how does that work?

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

    A computer sees negative numbers using the 2's complement method. Basically, it flips all the bits, then adds one to the result. For example:

    001 becomes 110, then 111 after adding one.

    You can observe that this operation preserves the state of all zeros until the first one, then flips all the other bits. Because of this, the result will have a shared one in the least significant bits only. If you perform a bitwise AND operation on these two numbers, you will get the least significant bit

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

    d & -d computes the least significant (set) bit, i.e. the "right-most (least significant)" bit set to one. this is also used in fenwick trees: see here (wikipedia article)

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

I did D by finding the first index( dentoed by j in my solution) where the string is not k-proper. Shifting it to the left if the condition in the last test case happens ( I am not able to explain it properly. Sorry for that.)

{In this test case -- 110001100110. I check if there are k 0's from j so that it forms a valid if I perform the operation.}

But My solution is not working on 2010 test case in 2nd Test. I have hit a roadblock here. Can anybody help

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

For the C why the all possible winnings outcome must be the same. Is there any logic behind that assertion?

Edit : got it, have not read well the editorial.

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

For problem C, I made a deadly mistake. The lcm of a and b equals a*b/gcd(a,b), so I think the lcm of a,b,c and d is a*b*c*d/gcd(a,b,c,d).In fact, it only works in two nums.

e.g.:

4 5 8

lcm: 40

而 gcd(8,5,4) == 1

8*5*4 == 160[尴尬]

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

-

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

For some reason, I guessed the solution for B and C and they were right! Here's how I did it:

B: I noticed that the last testcase's answer is 33554432, which i remembered as a power of two (2^25), and so are the other testcases' answers. After this exploration, I tried to find how were the last testcase were related to 2^25, and finally found that the difference between x and y was divisible by 2^25, but not 2^26. So I concluded that the answer must be the largest power of two that is a divisor of abs(x — y). I then submitted the solution and got an AC. The entire process took 8 minutes.

C: What had catched my attention was the really weird constraints on n and k. My immediate thought was that it was related to the answer of the problem not surpassing 1e9 (x limit) somehow. After that, I think it must be somehow related to the LCM of the array, and it was right, after me testing my theory on the example testcases. I submitted and got AC without proving that my solution was right.

I did D afterwards, really enjoyed the problems, good contest!

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

For people who did not understood editorial of problem C maybe this will help

Essentially what the editorial is this for Problem C

let coins we place in bet be c1,c2,c3,c4, ... ,cn and c1 + c2 + c3 +...+ cn = S

then the following inequalities are formed based on conditions proposed by the question

S<c1*k1
S<c2*k2
S<c3*k3
.
.
.
S<cn*kn

divide by k on both sides

S/k1<c1
S/k2<c2
S/k3<c3
.
.
.
S/kn<cn

add them all up the ineqality still holds

S*(1/k1 + 1/k2 + 1/k3 + ... + 1/kn)  <  c1+c2+c3+c4+ .... + cn

S*(1/k1 + 1/k2 + 1/k3 + ... + 1/kn)  < S

(1/k1 + 1/k2 + 1/k3 + ... + 1/kn)  <  1

fraction addition

let lcm = lcm(k1,k2,k3,...,kn) then (lcm/k1 + lcm/k2 + lcm/k3 + ... + lcm/kn) / lcm < 1

multiply by lcm on both sides

(lcm/k1 + lcm/k2 + lcm/k3 + ... + lcm/kn) < lcm

and this is your final condition for answer

please correct me if my calculations are wrong

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

A short straight forward implementation using 2 pointers for D : 264776035

  • Logic : basically if you notice carefully then you will find that in the final string there should be alternate blocks of 0s and 1s of each of length 'k'. so the working is that whenever we find any block of len != k then we have to forcefully take p = this index(otherwise we always take p = n), then we create two prefix and suffix strings and check (suffix string + reverse of prefix string) to ensure that this will have alternate blocks of 0s and 1s simply otherwise p = -1
  • Don't forget to check first condition -> first k digits are same
»
22 месяца назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Can someone please explain intuition and proof for hint of problem E?

In every Manhattan triangle there are two points such that |x1-x2| = |y1-y2|

  • »
    »
    22 месяца назад, скрыть # ^ |
     
    Проголосовать: нравится 0 Проголосовать: не нравится
    1. The hint's observation is equivalent to the fact that 2 points are on the same diagonal.
    2. Prove by contradiction: Take (x1, y1) and (x2, y2), s.t. distance equals to d and they are not on the same diagonal. The set of all points that are d units away forms a 45°rotated square. Now imagine all points that are exactly d units away from first point — set S1, or the second point — set S2. The third point is one of the points that are in both S1 and S2 (intersection of S1 and S2). But this third point is on the side, that is intersecting either first point, or second point. Thus, it is surely on the same diagonal.
»
22 месяца назад, скрыть # |
Rev. 2  
Проголосовать: нравится 0 Проголосовать: не нравится

Thanks for Editorial very much! But can u see my code for C, i think it's also a good way for this problem: 264471661

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

ok

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

Ok

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

Can someone explain me the diagonal part of Problem E. Why we are distributing with their x + y value?

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

A simpler approach for D

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

in problem D for test case 6 why is it -1? can't we use p=4? I found out. The first k elements should be same. My bad.

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

I just want to share my solution to D real quick. The idea is to use PSA to determine the whether a full interval is all 1's or 0's to match to the last character of the string. Other than that, we precompute the positions at which the array would be considered k-proper up to i from left to right (in the array goodl), and right to left (in goodr). Admittedly, the solution is somewhat weird and case-workish, but the idea in general is intuitive and is for kicks :)

Submission: https://mirror.codeforces.com/contest/1979/submission/276454385

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

I just want to quickly share a weird little solution for D. It uses PSA to determine whether a certain interval can complete the k-long block of 1's or 0's depending on the last character of the string. We also use a right and left sweep to determine cut off positions that would leave the array from left to right and right to left as k-proper. These are stored as true values for the corresponding positions in the arrays goodr and goodl. resr and resl represent the "residue" to be completed by further 1's or 0's on the left and right ends of the string. Admittedly, the solution is case-workish and weird but the intuition is quite simple and the solution is nice for kicks :)

Submission: https://mirror.codeforces.com/contest/1979/submission/276454385

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

I solved problem E using the fact that $$$\ell_1$$$ norm and $$$\ell_\infty$$$ norm are dual norms; e.g.

$$$\|x\|_1 = \max_y \{x^\top y : |y|_\infty \le 1\}$$$

Given this, the $$$\ell_1$$$ dist. between two points $$$(x_i, y_i)$$$ and $$$(x_j, y_j)$$$ would be:

$$$ \begin{align} \|(x_i-x_j, y_i-y_j)\|_1 &=\max(|x_i-x_j+y_i-y_j|, |x_i-x_j-y_i+y_j|) \\ &= \max(|(x_i+y_i) - (x_j + y_j)|, |(x_i-y_i) - (x_j - x_j)|) \end{align} $$$

I think this is a well-known fact in CP community. Knowing this, we can transform the given points with $$$\phi:(x, y)\rightarrow (x+y, x-y)$$$. The problem is now reduced to checking if there exists two points $$$(i, j)$$$ with $$$x_i = x_j$$$ and $$$y_i + d = y_j$$$, and if there exists another point $$$k$$$ such that $$$x_k=x_i \pm d$$$ and $$$y_i \le y_k \le y_j$$$. Also we can swap the coordinate $$$(x, y)$$$ and do the same checking. Here is my implementation: 280227760

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

Can anyone explain binary search approach for C ?

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

Nice DP solution for D:

343197938

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

C is a kind of problem that can ruin your whole day