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

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

Hello everyone!

I invite you to the contest where I authored all the problems. There are tasks that couldn't make it to the Official Codeforces Round. But they are still not that bad :)

I hope you enjoy the problems. Thanks for participating!

If you have any feedback or suggestions, please feel free to leave them in the comments. Your feedback will help improve my future contests.

UPD: My apologies! The author's idea for problem D was incorrect. I hope that the solution is now correct. All the submissions for this problem were rejudged, and three samples were added.

UPD2: Problem D has been hopefully fixed. Many thanks to Yam for detecting and correcting the problem.

Анонс SashaT9 Contest 1
  • Проголосовать: нравится
  • +61
  • Проголосовать: не нравится

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

It's interesting how awful problems like B, F and H are in the same set as D and G. Were they rejected for CF round? Why? And why did you decide to just post them instead of keeping them for some other contest?

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

    Firstly I was preparing these problems for CF. However, I received a proposal to create a contest for Algotester, and some of these problems were used there (but not all). I then decided to also post them on CF to make them accessible beyond Ukraine.

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

    Just curious, why do you think that B and H are awful?

    Here are my opinions on the problems (I didn't read D because I probably won't be able to solve, or it would take too long):

    F
    H
    B
    G
    • »
      »
      »
      15 месяцев назад, # ^ |
        Проголосовать: нравится 0 Проголосовать: не нравится

      Thank you for the feedback!

      I fixed the statement in problem B.

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

      They are very boring and standard. I'm sorry if it's offensive. From the announcement I got the impression that the contest is constructed from problems that were rejected for the round, and most of the problems look like it. I would reject everything but D and G, and for B/F/H I wouldn't feel like I need to explain the reason. But G seems like a decent problem for div2 round (maybe even for div1), and D is actually very nice. So that seemed weird and like a waste of good problems, that's why I asked.

      Actually, D seemed so out of place that I had a suspicion that the author's solution might be incorrect since I certainly wouldn't waste a problem with such a nice solution. But I might have missed some simpler solution, so it didn't seem fair to suggest this. Looks like I was correct though.

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

It's funny that when we were making a round, we thought independently of task F and tried to make it D2B)))

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

Just amazing SashaT9, Good Going Buddy!! Just contacted you when I was specialist & you were Expert & now we both are one step ahead!!! Lets hope for the best and very best of us both...

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

If possible provide tutorial as well. It will be helpful for people who are new to competitive programming like me.

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

enjoyed the contest, however felt like there was a big difficulty gap between DG and rest. Thanks anyways

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

problem F is reversed of an ABC problem, where author asked to maximized diameter.

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

How to solve G?

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

    $$$gcd(a_i + j, a_j + i) = (i+j)$$$ means that

    • $$$a_i + j$$$ can be written as $$$(i+j) \cdot k$$$
    • $$$a_j + i$$$ can be written as $$$(i+j) \cdot y$$$
    • $$$(k,y)=1$$$

    Thus we know that $$$a_i = i \cdot k + j \cdot (k-1)$$$ for some $$$k$$$. Let's itterate through all possible pairs of $$$(i,k)$$$, if $$$k > 1$$$ we already know $$$j$$$ so we can test if the found pair works indeed.

    Now, if we save all pairs that work in a set, we can note that pairs that are never counted are the ones in which both $$$k=1$$$ and $$$y=1$$$, which means $$$a_i = i$$$ and $$$a_j = j$$$, so just count all pairs of fixed points.

    Complexity is $$$O(vmax \cdot \sqrt{vmax} \cdot log)$$$, but magically, it runs in < 100ms ( probably testcases are not very strong ). You can view my code here.

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

      Nice solution! I have another approach:

      $$$\gcd(a_i+j, a_j+i) = i+j \leftrightarrow \gcd((a_i-i)+i+j, (a_j-j)+i+j) = i+j$$$

      Now, if we assign a new array $$$b_i = a_i - i$$$, the equation becomes $$$\gcd(b_i + i + j, b_j + i + j) = i + j$$$

      Here, we notice that $$$i+j$$$ may be a divisor of $$$b_i$$$, so we can iterate through all the divisors of $$$b_i$$$. If the divisor is $$$d$$$, we get $$$i+j=d \leftrightarrow j=d-i$$$, and all we need to do is check if such $$$j$$$ satisfies the equation. Complexity is $$$O(n\sqrt{maxA}\log n)$$$.

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

How to solve E?

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

    Declare a new array $$$c$$$ of length $$$2 \cdot n$$$, where $$$c_{2i} = \max(a_i, b_i)$$$ and $$$c_{2i+1} = \min(a_i, b_i)$$$. After that, you can find LIS on this array and obtain the answer to the problem.

    This algorithm works because in such constructions, we can't take both $$$a_i$$$ and $$$b_i$$$ simultaneously (since $$$\max(a_i, b_i) \geq \min(a_i, b_i)$$$).

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

How to solve problem D. SashaT9 can you give me some hints/solution idea thanks in advance :)

  • »
    »
    14 месяцев назад, # ^ |
    Rev. 3   Проголосовать: нравится +5 Проголосовать: не нравится
    Hint 1
    Hint 2
    Hint 3
    Solution
    Code
    • »
      »
      »
      14 месяцев назад, # ^ |
      Rev. 2   Проголосовать: нравится +18 Проголосовать: не нравится

      It won't really make any difference in practice since the domitaing part of the code is reading input, but we can optimize the dp to $$$O(A^3)$$$. Instead of calculating the dp separately for each starting point, we can calculate the dp once for a cyclic array.

      My dp is similar to the one you explained, but possibly slightly different.

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

can somebody provide solution for problem A and B

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

    Sure : So I have observed a pattern by writing bruteforce solution and running for 1-100

    Bruteforce Code
    Optimised Code
»
14 месяцев назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Can somebody explain how to solve problem C.

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

    Let's find the subsequence with maximal length for which the greatest common divisor is equal to $$$d$$$. We can use numbers $$$d, 2d, \dots, sd$$$, and their GCD is guaranteed to be at least $$$d$$$.

    Now, the observation is that if there exists a subsequence of length $$$k$$$ with GCD $$$d$$$, then there is also a subsequence with a length of $$$k-1$$$ and a GCD of $$$d$$$ (since we may choose not to include one of the elements from the set $$$d, 2d, \dots, sd$$$).

    The algorithm is as follows:

    1. Create an array $$$c_x$$$ to store the number of occurrences of $$$x$$$ in the array.
    2. Iterate through all values of $$$d$$$ and find the maximum $$$k$$$ for which the GCD equals $$$d$$$. For each value of $$$k$$$, update the corresponding entry with value $$$d$$$ in an array called $$$mx$$$.
    3. Iterate through the array $$$mx$$$ from the end, and for each index $$$i$$$, update $$$mx_i$$$ to be the maximum value between $$$mx_i$$$ and $$$mx_{i+1}$$$.
    4. Output the array $$$mx$$$.

    Complexity is $$$O(n+A\log A)$$$.

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

I know the solution to problem A

solution

Can anyone help me why this is the solution?

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

    maybe you cant find it with condradiction

    if x <= n, then after xor-ing every permutation, there is always 0 in the end

    if x > n, then exist at the end of operation, exist 1 ⊕ x, which equal to x+1, if x is even, or x- 1, if x is odd. of course we cannot use x even, because it will produce x+1, which more than n, therefore, the array after operation wont be a permutation

    so the only possible x is n+1.

    Now, why the only possible solution for x is (2^n — 1, a.k.a 111...111₍₂₎). If x is not 2^n — 1, then x contain 0 in its biner representation, therefore, you can pick a number "i" that's reversal of x in its biner representation. i <= n < x

    Example

    x = 111110₍₂₎, then pick i = 000001₍₂₎, i ⊕ x = 111111₍₂₎, therefore i ⊕ x is bigger than n

    So, the only solution is where x = n+1, and x = 111...111₍₂₎

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

How to solve problem F ?

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

    let a = diameter of first tree, and b = diameter of second tree

    ans = max(max(a, b), ceil(a/2) + ceil(b/2) + 1)

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

Any hint to solve F? My idea got WA. My idea is that we find node in both tree where the longest path starting from that node. After that, we can add an edge between both node and start doing dfs to find the diameter of the merged tree.

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

    You should use dsu to solve this problem

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

      Care to give me more hint about it? hehe

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

        When you merge two trees it is enough to know diameter of each tree to find the minimum diameter

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

          Sorry. I thought that there was queries. So you don't need dsu. You only need to know the diameters of each tree to find result

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

          Why is it simply enough to know the two diameters? What is the intuition behind this?

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

how do you manage to solve more than 5k problems within 3 years?

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

    It was so exciting that I didn't even notice the number of tasks I solved:)