AVdovin's blog

By AVdovin, history, 17 months ago, In Russian

2050A - Line Breaks

Идея: kbats183

Решение
Код

2050B - Transfusion

Идея: AVdovin

Решение
Код

2050C - Uninteresting Number

Идея: DanGolov

Решение
Код

2050D - Digital string maximization

Идея: AVdovin

Решение
Код

2050E - Three Strings

Идея: pskobx, Vladosiya

Решение
Код

2050F - Maximum modulo equality

Идея: AVdovin

Решение
Код

2050G - Tree Destruction

Идея: AVdovin

Решение
Код
  • Vote: I like it
  • +41
  • Vote: I do not like it

| Write comment?
»
17 months ago, hide # |
Rev. 2  
Vote: I like it +11 Vote: I do not like it

Task G is almost identical to a task from the Polish Olympiad in Informatics called Parade. The only difference is in the POI task, you can not choose $$$a = b$$$.

»
17 months ago, hide # |
 
Vote: I like it +5 Vote: I do not like it
evc = n / 2;
if (n & 1) evc++;

is the same as

evc = (n + 1) / 2 ; 
»
17 months ago, hide # |
Rev. 2  
Vote: I like it +2 Vote: I do not like it

Where is the formal proof of correctness to the editorial solution of D?

I was hoping to see the cleanest solution and proof to the problem, now the editorial for this problem is very unhelpful.

  • »
    »
    17 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    Maximum digit can be 9. After each operation digit will decrease by 1, so we can do at most 9 operations. What is unclear?

  • »
    »
    17 months ago, hide # ^ |
     
    Vote: I like it +3 Vote: I do not like it

    Why isn't the editorial's solution clean?

    My understanding of the editorial’s argument is as follows:

    First, we aim to maximize the digit at index $$$0$$$, and it’s clear that we need to choose a digit from the first 10 indices. The goal is to find the maximum value of $$$S_i−(i−j)​$$$, where $$$j$$$ is the index we are currently maximizing (starting with zero). In case of ties, we select the smallest $$$i$$$. We swap $$$i$$$ and $$$j$$$, and then repeat from the next index. This ensures that $$$s$$$ is maximized.

    Is this reasoning incorrect, or is it just informal?

    • »
      »
      »
      17 months ago, hide # ^ |
       
      Vote: I like it 0 Vote: I do not like it

      The editorial solution is clean. However, I cannot see a potential clean proof.

      Baiscally, the first step is defintiely correct, but the tie breaking is hard. You must show that among all future paths, you can select one to commit to, and it gives the best result (due to one reason or another).

      This cannot be done without any statements about the future situations, what you can do/comparing future situations.

      That said, the proof given by _Kee below is correct and clean enough. Thanks.

  • »
    »
    17 months ago, hide # ^ |
    Rev. 4  
    Vote: I like it 0 Vote: I do not like it

    I think the hard part is how to handle tiebreaking.

    Let's say we have an array $$$[a, b, 6, c, d, 9, \ldots]$$$ where $$$a \lt 4$$$, $$$b \lt 5$$$, $$$c \lt 7$$$ and $$$d \lt 8$$$, that is, $$$6$$$ and $$$9$$$ are the only digits that we can bring to the front. If we bring $$$6$$$ to the front, we get $$$A = [4, a, b, c, d, 9, \ldots]$$$. If we move $$$9$$$, we have $$$B = [4, a, b, 6, c, d, \ldots]$$$. So the problem here is: which is better?

    Let's think about the selection of later digits. First of all, the parts $$$[a, b]$$$ and $$$[\ldots]$$$ are shared in the same place between $$$A$$$ and $$$B$$$, so they equally affect the final result. Next, regarding the part $$$[c, d]$$$, $$$A$$$ has that part earlier than $$$B$$$, so $$$A$$$ will give a better result. Finally, about the parts $$$[9]$$$ and $$$[6]$$$, if we move $$$9$$$ back to the digit where $$$6$$$ resides, it will become $$$7$$$, so $$$A$$$ will give a better result, too. Therefore, taking $$$A$$$ is always advantageous for us overall.

    I think we can get a general proof out of this sketch, though it can be very tedious to do.

»
17 months ago, hide # |
 
Vote: I like it +1 Vote: I do not like it

I have a question about how to arrive at the correct conclusion for a problem, for example, Problem B. That is, how to reach that solution—what was the clue in the problem that led to solving it in that way? I find it difficult to arrive at such a conclusion.

What I mean is, how should I study to improve this? Is it just about practicing problems, or does it require a more mathematical way of thinking? If anyone reads this, I would appreciate it if they could recommend a book or any resource. :(

  • »
    »
    17 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    Well, when I first came up with this problem, I thought about what will happen, if I will aim to make all the elements = 0, then I found out, that we can transfuse all the values to the first and the second elements, so after that we need to transfuse from these two elements back to othe elements and also now aim to make them all equal. Maybe it was a little bit messy idea, but it helped to solve this one out

»
17 months ago, hide # |
Rev. 2  
Vote: I like it 0 Vote: I do not like it

I am unable to understand the language of E and cant think of any approach i thought may be 3 loops as time is 2.5S but still dont understood minimum number of characters of C w.r.t to all strings we can make ? how can i know there can be many string can be formed. Anyone pls just point me in right direction. thanks

  • »
    »
    17 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    I feel that his code is totally messy, and this code could help you understand that. 295017055

    A fact we know is that $$$\vert C \vert = \vert A \vert + \vert B \vert$$$, so for every character of $$$C$$$, you can know it must come from $$$A$$$ or $$$B$$$. Then we only need to use state $$$A$$$ and $$$B$$$ to calculate the answer.

    Let $$$dp[i][j]$$$ denote the minimum times of transforming with used first $$$i$$$ characters of $$$A$$$ and first $$$j$$$ characters of $$$B$$$. If $$$C[i + j]$$$ could be $$$A[i]$$$ or $$$B[j]$$$, we don't need to transform. Otherwise, raise $$$1$$$ by transforming a letter.

    So the main idea is to represent more states with fewer state measures. Hope this will help.

»
17 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Who can help me why I had a WA2, problem E? https://mirror.codeforces.com/contest/2050/submission/295355937

»
17 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

For problem D, I used insert() and erase() functions to modify the string and it gave me TLE on testcase 7, later, I changed my solution to keep track of what characters from the original string are moved to their left using an array and kept adding such characters to an empty string. I think my current solution is O(n) but it got a TLE on testcase 8. Can someone tell why I got TLE? Submission link

  • »
    »
    17 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    We can use __gnu_cxx::rope<char> instead of std::string and it passes: 295422598. Rope is a non-standart string implementation based on the treap with implicit keys. For std::string, insert() and erase() work in $$$O(n)$$$ in the worst case, where $$$n$$$ is a length of string. For __gnu_cxx::rope<char>, insert() and erase() work in $$$O(\log n)$$$ in the worst case, where $$$n$$$ is a length of string.

»
17 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

For C, will not be time complexity O(x*x) in the worst-case scenario where x is the length of the number? When the count of both 2s and 3s becomes equal to x/2. How is it getting accepted for a constraint of 10^5 on number length?

Can anyone clarify?

  • »
    »
    17 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    You don't have to consider nine or more $$$2$$$s or $$$3$$$s because the effect of those digits loop after the ninth one (because we calculate numbers modulo $$$9$$$). So you only need to consider $$$9^2 = 81$$$ cases at most.

»
17 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Could you guys help me with question G? I got the wrong answer for test case 17. https://mirror.codeforces.com/contest/2050/submission/295318789

»
17 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

template contest.

»
17 months ago, hide # |
 
Vote: I like it +2 Vote: I do not like it

Problem C: The only extra piece of proof that I wish should be added is that, after calculating the num2s and num3s in the string. We can loop at most 9 times for each of twos, threes. As anything after this would be rudimentary as it would be divisible by 9 directly, so the loop should run from i = [1 to min(num2, 10LL)), j = [1 to min(num3, 10LL)). As, someone might think why running loop (num2*num3) times per test case doesn't add up to TLE, this is cause we would be checking for atmost 81 different states, which is of constant time complexity, and breaking out after it.

Hence, This works!
  • »
    »
    16 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    Hi, thanks for this proof. one follow up doubt- how did we determine after 9 times it would be pointless to check? Also in the editorial it says it is useless to check after 8 times i.e replacing both 2 and 3 eight times. Am i missing something? would also kindly provide a small example for that, it would be easier to understand. Thanks!

    • »
      »
      »
      16 months ago, hide # ^ |
       
      Vote: I like it 0 Vote: I do not like it

      After 9, it would be a multiple of 9, so further that it's pointless like say you determined the numbers to be (10,11) but you would have crossed (9,9) on some point where it would be 9*(some factor), so it's like the dead end!

»
17 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

can someone hack me please Problem G 296473359

I Solved It greedly by picking node lca(a,b) which called root which have max number of edges

After that I Picked greedly node a which the node that have max number of connected components with lca(a,b)

After that I pick node b which have max number of connected components with node b

  • »
    »
    16 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    That's also one of the correct solutions. In the editorial it is said, that this problem is kinda similar to finding the diameter of the tree, so your solution is just another way to find a diameter.

»
15 months ago, hide # |
Rev. 2  
Vote: I like it 0 Vote: I do not like it

Editorial for G is too complicated. Dp on trees wasn't needed and was too advanced for this. Rather just root the tree at the node with max degree, reduce the degree of each node by 2 except for the root and find the max degree sum path for all the children of the root and add the top 2 max Paths.

My submission — 304341864

»
14 months ago, hide # |
Rev. 2  
Vote: I like it 0 Vote: I do not like it

Why in the problem F we just take gcd(abs(a[l] — a[l + 1]), abs(a[l + 1] — a[l + 2])...), but we just checked not all pairs, cause m must be the divisor for all abs(a[i] — a[j]) l <= i <= r and l <= j <= r, so that i != j,

»
5 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

We need not iterate the count of 3 8 times but rather 3 times at max. Greater than 3 resets the number modulo 9.