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

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

Thank you all for participating in the round!

We apologize for the wrong checker in problem E at the beginning of the contest, as well as the weak tests in problem B. To be honest, all the hacked submissions have similar logic and codes in B, which made me suspicious. Anyway, we are sorry for the inconvenience! >_<

Rating Predictions

2029A - Set

Author: Otomachi_Una
First Blood: Benq at 00:00:51

Hint
Solution
Code (C++)
Code (Python 3)
Rate the Problem

2029B - Replacement

Author: _istil
First Blood: Benq at 00:02:30

Hint
Solution
Code (C++)
Code (Python 3)
Rate the Problem

2029C - New Rating

Author: Error_Yuan
First Blood: ksun48 at 00:05:34

Solution 1 (with hints)
Solution 2 (with hints)
Code (Solution 1, C++)
Code (Solution 2, Python 3)
Rate the Problem

2029D - Cool Graph

Author: Error_Yuan
First Blood: ksun48 at 00:13:24

There are many different approaches to this problem. Only the easiest one (at least I think so) is shared here.

Hint 1
Hint 2
Solution
Code (C++)
Rate the Problem

2029E - Common Generator

Author: Error_Yuan, _istil
First Blood: ksun48 at 00:23:50

Hint 1
Hint 2
Hint 3
Solution
Code (C++)
Rate the Problem

2029F - Palindrome Everywhere

Author: sszcdjr
First Blood: taeyeon_ss at 00:16:50

Hint 1
Hint 2
Hint 3
Hint 4
Hint 5
Hint 6
Solution
Code (C++)
Bonus 1
Bonus 2
Rate the Problem

2029G - Balanced Problem

Author: _istil, Error_Yuan
First Blood: taeyeon_ss at 00:56:22

This problem has two approaches. The first one is the authors' solution, and the second one was found during testing.

Solution 1 (with hints)
Solution 2 (with hints)
Code (Solution 1, C++)
Code (Solution 2, C++)
Rate the Problem
Bonus

2029H - Message Spread

Author: sszcdjr
First Blood: Benq at 02:04:40 (though unintended brute force), jiangly at 02:55:12 (intended, orz!)

Hint 1
Hint 2
Hint 3
Hint 4
Solution
Code (C++)
Rate the Problem

2029I - Variance Challenge

Author: Error_Yuan
First Blood: rainboy at 01:33:40 (intended, the only solve in contest, orz!)

Hint 1
Hint 2
Hint 3
Hint 4
Hint 5
Solution
Code (C++)
Rate the Problem
  • Проголосовать: нравится
  • +136
  • Проголосовать: не нравится

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

fast edi yay!

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

I do C with binary search. It's really crazy to see the binary search in this problem.

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

I screwed up the 3rd claim for E I thought only primes less than equal to $$$\frac{A}{MinDiv[A]}$$$ will work (for composite A)

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

I had a slightly different approach for D: for each edge (u,v) with u!=1,v!=1, do operation (1,u,v). then you have a star-tree centered at 1, and a bunch of lone-nodes, then do as in the editorial to connect the lone-nodes

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

In B, if(count of 1 in s — count of 0 in r(don't check for last element in r)==1) cout<<"YES";

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

I thought of C as dp but screwed up because for some reason my mind didn't tell me that it's enough to store the maximum rating in the dp

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

rainboy is like just so cool ! is he indian ( i saw some grp photo ) ?

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

H: Thanks for setting the time limit just above my solution's runtime! :)

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

for c can any one show there recursive dp solution ?

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

O(n+m) solution for problem D 290751143

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

in problem E,why are we only considering lowest divisor of x i.e mind(x) for checking if x can be obtained from any generator?

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

    Because for any x, the minimum divisor is either an odd prime or 2, if it's 2 then it can easily be obtained, if it's not 2 then x — mind(x) is even which reduces the problem to checking even numbers only, and for a prime generator p not equal to 2, we can generate all even numbers >= p * 2

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

      why is it necessary that we get x from x-mind(x) only,its just written as a statement,why cant we get x from (x-y)+y where y is some other divisor other than the minimum one?

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

        We can always get x from another x — y. mind(x) is taken for proof's sake.

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

        Because, we can generate all even numbers from a certain point. x — mind(x) basically gives you the largest even number smaller than x that can produce x, let's call it y. That is because if mind(x) | x then mind(x) | x — mind(x). It's kind of like the euclid algorithm for gcd. If you subtract a divisor of a number from the said number, the result will still be divisible by the said number. Basically, you can use larger divisors but there is no point because the difference will always be even, and if we can generate an even number n then we can generate any larger even number. So if any divisor works, then any smaller one does too

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

      why are we sure that x-mind(x) can generate x?

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

Actually for problem E it turned out that it's possible to get AC with time complexity $$$\mathcal{O}(\sum n + tV)$$$, though it required me to use bitsets, fast input/output template and some number of identical submissions till i got the lucky one 290762920.

Also one of my TL'ed submissions during the contest passes with 1.3s after the system testing. Is there any reason? 290772979 and 290758813

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

I had a simpler DP approach for problem C:

Let $$$ \text{dp}[i] $$$ represent the maximum rating that can be achieved such that $$$ r \leq i $$$.

The base case is $$$ \text{dp}[1] = 0 $$$.

Either $$$ r \lt i $$$ or $$$ r = i $$$. Hence,

$$$ \text{dp}[i] = \max\left( f(\text{dp}[i-1], \, a[i]), \, \underset{1 \leq j \lt i}{\max} (f[j]) \right) $$$

The definitions of $$$ f(a, \, x) $$$ and $$$ f[i] $$$ are the same as given in the editorial.

The final answer is simply $$$ \text{dp}[n] $$$.

Code: 290775108

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

I feel like the problem statement of B could have been better

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

There's an $$$O(V^2)$$$ solution in G, see here: 290755809

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

My solution for D is a bit different:

First I try to remove all cycles, I do so by erasing all edges (u,v) with u != 1 and v != 1, so that all the remaining edges are in the form (1,u), we can achieve this by making moves of the type (1,u,v).
You keep track of the edges being added and removed using a set, this is useful because you keep track of which nodes are connected to 1 or are isolated.
Now all that remains are some isolated nodes and a tree with root 1: all I do is choose a random node A different from 1 in the tree, and for each isolated node B I make the move (1,A,B), as to add B to the tree, then I assign B to A and continue adding isolated nodes to the tree.
Of course, if the tree only consists of 1 and A doesn't exist, you stop there.

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

Thanks for the contest! About Problem H:

For the $$$\Theta(3^n)$$$ passing, I received too much bonus :) && :(

The problem itself is interesting, and upsolving in $$$O(2^n n^2)$$$ was a nice practice to me. Perhaps "to optimize it." in the editorial hides a tough detail — something like semi-relaxed convolution is unavoidable, right?

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

    I'm afraid your $$$\Theta (3^n)$$$ is way too fast, sad as one of the setters, but anyway congrats!

    On "hiding a tough detail", here is sszcdjr's opinion: nearly every Chinese knows it.

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

      Can you provide more details? I feel that there's a lot of room for improvement in the editorial quality for this problem. I'm stuck on $$$\Theta(2^nn^3)$$$ right now which is slightly too slow.

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

        I'm sorry but the editorial is written by sszcdjr... Judging from your time complexity, I guess you are having difficulty with the so-called subset convolution technique. (idk if my explanation is correct and clear but I hope so, so plz correct me if there is any mistake)

        We are given $$$f_{0\dots (2^n-1)}$$$ and $$$g_{0\dots (2^n-1)}$$$. We want to calculate

        $$$h_k = \sum_{i \operatorname{or} j = k, i \operatorname{and} j = 0} f_ig_j$$$

        Assume you know how to perform FWT. Then one can see $0$ (why I have to add a random LaTeX here to make the following LaTeX showing properly), $$$i \operatorname{and} j = 0 \iff \operatorname{popcount}(i) + \operatorname{popcount}(j) = \operatorname{popcount}(i \operatorname{or} j)$$$, so let's denote

        $$$F_{i,j} = \begin{cases} f_j, & \operatorname{popcount}(j) = i \\ 0, & \text{Otherwise.} \end{cases}$$$

        (the same for $G_{i,j}$), thus for each $$$s = \operatorname{popcount}(k) \in [0, n]$$$, we can calculate $$$H_s = \operatorname{IFWT}\left( \sum_{j=0}^{s} \operatorname{FWT}(F_j)_i \cdot \operatorname{FWT}(G_{s-j})_i \right)$$$ (it works because it's a linear transform), then $$$h_k = H_{\operatorname{popcount}(k), k}$$$.

        This would work in $$$\mathcal O(2^nn^2)$$$.

        Naturally we can do no adaptation to make it "online", because we calculate $$$h_k$$$ in the ascending order of $$$\operatorname{popcount}(k)$$$ so it still works in the same time complexity when $$$f, g$$$ turn out to have something to do with $$$h$$$ (but for NTT, the case is somehow different).

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

          Thanks. I understand how subset convolution works but the part that I don't get is the "online" part that you mentioned in the last paragraph.

          Edit: I think I might understand now... will try to implement later.

          Edit 2: Here's a sort of high-level explanation in case anyone has the same issue as I did.

          Like the editorial says, we have some formula where $$$f(S\cup T)$$$ depends on $$$f(S)$$$, $$$g(T)$$$, $$$h(S\cup T)$$$ where $$$g$$$ and $$$h$$$ are precomputed functions. I was calculating $$$f(S)$$$ in layers based on $$$|S|$$$, and at each step I did one subset convolution to get the contributions to $$$f(S\cup T)$$$. This involves doing one SOS transform on $$$f(S)$$$, multiplying with the SOS transforms for $$$g$$$ (precomputed), and then doing the reverse SOS transform afterward. The last step of doing the reverse SOS transform takes $$$O(n\times 2^n)$$$ time, and furthermore iterated over $$$|S|$$$ and $$$|S\cup T|$$$ for $$$O(2^nn^3)$$$ time complexity. The solution is to defer the reverse SOS transform step until you are on the relevant value of $$$|S|$$$, so it's only done once per size for $$$O(2^nn^2)$$$ time complexity.

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

        If you came to this time complexity, you definitely understand the editorial much better than I am. I am basically stuck on the first line. What does "Let $$$dp_S$$$ be the probability such that exactly the points in $$$S$$$ have the message" even mean? Probability at what point in time? And then the formula following about $$$\sum_S dp_S \cdot tr_S$$$ I also don't understand the meaning of. Could you please help me a bit here?

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

I ENJOYED ALL PROBLEMS, KUDOS to the authors

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

In solution 1 of problem G, the notations are not clear at all. Can anyone can explain what does "saved" s pairs of LR mean? Also, what is preL and preR?

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

am I the only one who thought C was easier than B

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

Conclusion Forces

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

Amazing problem C. I had thought about binary searching the answer but didn't come up with the solution, but I managed to solve it using dp. It's really cool to see that both approach work.

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

D problem's solution is short and useful.My solution is find the rings and delete them, but I can't realize it.

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

Problem D is very similar to 104770D - Redrawn graph

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

C — Kevin's hacking shouldn't go in vain so he must choose at least one element to skip even it reduces his rating.

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

can anyone explain my tle in problem E 290847100 I think my time complexity is

nlogn + √mx*loglog(mx)*logn + n where mx=max of all ai, i varies from 1 to n and n<=10^5

how do it in my way? can we do it?

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

why I *3400, is this rainboy's opinion?

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

In Problem C, can someone explain something lies in this line .

if (a[i] < curg) curg++;
else curg--;

I'm confused about the case when $$$a_i=curg$$$, I understand both cases when $$$a_i \gt curg$$$ and $$$a_i \lt curg$$$, but I can't understand $$$a_i=curg$$$, why doing $$$curg$$$-- works just fine?

I'm assuming that when $$$a_i \lt curg$$$ that means when we take this number it will decrease our rating, so will increase $$$curg$$$ so we can try to get the point we just lost, and when $$$a_i \gt curg$$$ that means when we take this number our rating will increase so now we need to try to get $$$curg-1$$$ instead of $$$curg$$$, because we just got a new point.

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

The solution to D is very well explained.

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

Why does "the minimum x equals # of L-s+# of R-s−# of adjacent LR-s" and what means adjacent LR-s. Is it like if we have L at number i and R and number i+1. Can somebody explain? Thanks in advance!

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

This is a bit late, but I solved the problem I in $$$O(NM(N+M))$$$ time, so I'll explain it.

Let's consider the following problem.

You have a sequence $$$a=(a_1,\dots,a_n)$$$ and a fixed value $$$x$$$.
Perform $$$m$$$ operations to minimize the sum $$$\sum (a_i-x)^2$$$.

The model solution solves this in $$$O(nm)$$$ time using a greedy approach, but I did something different.

Let $$$f_i(j) = (a_i + (j+1) \times K - x)^2 - (a_i + j \times K - x)^2$$$.
This represents the cost of performing an operation on the "layer" $$$j$$$ of the element $$$i$$$.

In the original setting, when we perform an operation on layer $$$j$$$, we must have already performed an operation on layer $$$j-1$$$.
However, we can drop this constraint because $$$f_i(j)$$$ is increasing for each element $$$i$$$.

Therefore, for each layer $$$j$$$, we can calculate the value
$$$c_j[\text{cnt}] =$$$ "the minimum cost of applying $$$\text{cnt}$$$ operations on layer $$$j$$$," and then we can "merge" $$$c_1, c_2, \dots$$$ to get the answer.
Note that each $$$c_j$$$ is a convex sequence, so merging can be done in linear time.

To calculate $$$c_j[\text{cnt}]$$$ efficiently, we need to calculate $$$w[\text{cnt}][\text{len}]$$$, which is defined as follows:

  • Let's consider selecting $$$\text{cnt}$$$ disjoint segments such that the sum of the lengths of the segments is $$$\text{len}$$$.
    Then let $$$w[\text{cnt}][\text{len}]$$$ be the minimum sum of $$$a_i$$$'s in those ranges.

We can calculate all $$$w[\text{cnt}][\text{len}]$$$ in $$$O(NM \min(N, M))$$$ time.
By using the convex hull trick, we can calculate $$$c_j[\text{cnt}]$$$ from $$$w[\text{cnt}][\text{len}]$$$.

Now let's get back to the original problem.
We need to find the minimum of $$$\sum (a_i-x)^2$$$ for many $$$x$$$'s.
The key observation is that, if you have a cost sequence for some $$$x$$$, you can calculate the cost sequence for $$$x-K$$$ by adding just one layer.
Adding a layer takes $$$O(m)$$$ time, so calculating costs for all $$$x$$$ can be done in $$$O(NM^2)$$$ time.

The overall complexity is $$$O(NM(N+M))$$$ time.

293429392

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

for Problem E, please can anyone explain to me how is this valid? (331 * 1009 = 333979)

Input

1

2

2137 333979

Output

2137