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

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

We will hold AtCoder Regular Contest 159.

The point values will be 300-400-500-600-900-900.

We are looking forward to your participation!

  • Проголосовать: нравится
  • +149
  • Проголосовать: не нравится

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

Scoring distribution looks friendly! I'll surely participate. GLHF!

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

    Nice round! I can get a large positive delta this time.

    Wrote a strange solution of B and it passed quickly. Idk whether it's right or weak data.

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

C++20 support when

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

Good luck! Scoring distribution DOES look friendly! Wish everyone's rating increases!

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

Great problem D, awesome generalization of the classic LIS (and hence a very natural problem statement).

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

Got TLE again and again on B problem (36/41). This 2sec time limit sucks :(
Can someone tell me how I can optimize this further..

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

can anyone explain how to solve B? The editorial is slightly confusing.

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

    My code is giving TLE after some test cases, could you please look once and optimize it?

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

    Let $$$g = \text{gcd}(a, b)$$$. Suppose $$$a < b$$$.

    • $$$(a, b)$$$ is equivalent to $$$(a / g, b / g)$$$. Then, you can assume $$$a, b$$$ coprime.
    • Goal: get a $$$g > 1$$$ (it's enough to find it $$$O(\log b)$$$ times, because you are halving $$$b$$$ every time).
    • Let $$$(a, b) = (a, a+d)$$$. While $$$(a, a+d)$$$ are coprime, you subtract $$$1$$$ from both, so you get $$$(c, c+d)$$$ ($$$c = a, a-1, \dots$$$). Recall that, when $$$c, c+d$$$ are not coprime, $$$g > 1$$$.
    • So, you have to find the maximum $$$c \leq a$$$ such that $$$\text{gcd}(c, c+d) = \text{gcd}(c, d) > 1$$$. So, $$$c$$$ must be multiple of some prime $$$p$$$ that divides $$$d$$$. Find such primes in $$$O(\sqrt{d})$$$. Then, the candidate $$$c$$$ are the $$$p \cdot \lfloor \frac{d}{p} \rfloor$$$.
    • »
      »
      »
      14 месяцев назад, # ^ |
        Проголосовать: нравится 0 Проголосовать: не нравится

      For some reason I still can't understand the idea behind B? I don't get why you can take a, b and perform a//g and b//g, when g != 1 for starters. How can that be the same thing?

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

        Try to simulate operations starting from $$$(a, b)$$$ and from $$$(a/g, b/g)$$$. You will notice that all the partial results in the first case are the same as in the second case, multiplied by $$$g$$$ (and it should be easy to prove). So, you will reach $$$0$$$ at the same moment.

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

Another round with 3200perf+unr_reg

wtf.png

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

Why my D code always Runtime Error and Wrong Answer? Can anyone help me? Code Link

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

Actually, we can find the minimum number of operations required for problem C (code). Though it was much harder to implement than simply constructing one, and I couldn't manage to finish it during contest time :(

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

    Do you mind explaining the idea?

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

      First we iterate through all $$$s$$$, and check whether we can make all elements equal using exactly $$$s$$$ steps. We can easily get rid of the case where the sum doesn't fit and some other trivial cases, so now we try to find a way to make every element $$$V$$$ in $$$s$$$ steps.

      Note that if we construct a $$$n\times n$$$ matrix $$$M$$$ where $$$0\le m_{i,j}\le s$$$ denotes the number of permutations where $$$p_i=j$$$, if the matrix satisfy the constraint that every row and every column sum up to $$$s$$$, we can always find $$$s$$$ permutations that corresponds to this matrix. This can be done using bipartite matching in $$$O(sn\sqrt n)$$$ time, which is obviously enough since $$$s\le 10^4$$$. Thus we try to find this matrix with the additional condition that for all $$$i$$$ , $$$\sum_{j=1}^n j\times m_{i,j}=V-a_i$$$.

      Instead of the original matrix, we try to construct the suffix sum matrix $$$A$$$, such that $$$A_{i,j}=\sum_{k=j}^n m_{i,j}$$$, now we re-write the constraints on $$$A$$$: row sum equals $$$V-a_i$$$, column sum equals $$$(n-i+1)s$$$, $$$A_{i,1}=s$$$, and $$$A_{i,j}\ge A_{i,j+1}$$$.

      Since the constraint on row sum is annoying, we first construct any such matrix without this condition. This can be done easily by greedy or whatever method. Then we try to adjust this matrix so that every row satisfy the constraint without breaking the other ones. Let $$$b_i=V-a_i-\sum_{j=1}^n A_{i,j}$$$, then if all $$$b_i=0$$$, we are finished. Otherwise, WLOG, suppose $$$b_1$$$ is the smallest one, then we need to move some other elements to this row to make this row good. To do this, we simply iterate through all $$$i$$$ such that $$$b_i\ge 0$$$, and for every $$$j$$$, we can calculate the maximum value that can be subtracted from $$$A_{i,j}$$$ and can be added to $$$A_{1,j}$$$ without violating other constraints (we can only care about whether $$$A_{i,j}\ge A_{i,j+1}$$$ here because the other conditions are always ok). We keep doing this until all $$$b_i=0$$$, in which case we have constructed the matrix succesfully, or we can't make the smallest value bigger, which results in a failure.

      Now we analyse the complexity. Let $$$v$$$ be the number of $$$i,j$$$ such that $$$A_{i,j}\ne A_{i,j+1}$$$. Since when we move every time, we make at least one $$$A_{i,j}=A_{i,j+1}$$$ or we make at least one $$$b_i=0$$$. Though it is possible that previously $$$A_{i,j}=A_{i,j+1}$$$, and later we make $$$A_{i,j+1}=A_{i,j+2}$$$, when we iterate through all $$$j$$$, $$$v$$$ decreases by at least $$$1$$$ every time we move from an $$$i$$$, and $$$v$$$ never increases. Since $$$v$$$ is at most $$$O(n^2)$$$, and it takes $$$O(n)$$$ time to move from $$$i$$$, the complexity for checking is $$$O(n^3)$$$. Since the answer is always less than $$$O(n^2)$$$, the total complexity is $$$O(n^5)$$$. However, we can never actually reach this upper bound since 1. the minimum number of operations is far fewer than $$$n^2$$$, and 2. the number of operations needed to adjust the matrix is far fewer than $$$n^3$$$ since it is just a theoretical bound.

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

        Note: if it's possible in $$$s$$$ steps, it's also possible in $$$s+2$$$ steps. So, you can binary search odd and even $$$s$$$, and the complexity becomes $$$O(n^3 \log n)$$$.

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

Can anyone explain the O(n) solution of the F problem (official editorial)? Even though I've gotten AC, I still can't understand the official editorial.