eugenechka.boyko.2_0-0's blog

By eugenechka.boyko.2_0-0, 12 months ago, translation, In English

2108A - Permutation Warm-Up

Author: eugenechka.boyko.2_0-0

Solution
Code

2108B - SUMdamental Decomposition

Author: eugenechka.boyko.2_0-0

Solution
Code

2108C - Neo's Escape

Author: suprend

Solution
Code

2108D - Needle in a Numstack

Author: m3tr0

Solution
Code

2108E - Spruce Dispute

Author: eugenechka.boyko.2_0-0

Solution
Code

2108F - Fallen Towers

Author: m3tr0

Solution
Formal proof
Code
»
12 months ago, hide # |
 
Vote: I like it +4 Vote: I do not like it

Auto comment: topic has been updated by eugenechka.boyko.2_0-0 (previous revision, new revision, compare).

»
12 months ago, hide # |
 
Vote: I like it +86 Vote: I do not like it

Problem F is awesome, thanks for the contest!

»
12 months ago, hide # |
 
Vote: I like it +24 Vote: I do not like it

As A participant I reeally enjoy thanks for your contest.

»
12 months ago, hide # |
 
Vote: I like it +72 Vote: I do not like it

The solution for problem F is poetic

»
12 months ago, hide # |
 
Vote: I like it +20 Vote: I do not like it

Problem A is an easier version of this.

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

    Can you please tell me how you found this problem, or did you remember it from previous experience?

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

      The funny thing is that if you look at my submissions I reviewed this problem very recently before the contest. I literally chuckled when I saw the problem in the contest.

»
12 months ago, hide # |
Rev. 2  
Vote: I like it +1 Vote: I do not like it

Can someone explain why this test case is -1?

n=12 k=4,

1 3 2 4 1 1 3 4 2 1 3 4

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

Can someone explain how we "normalize" the permutation in D? I thought to use binary search to find the segment where A ends similar to the editorial in contest, but I got stuck on the fact that the last k elements are not necessarily $$$B_1, B_2, ..., B_k$$$

  • »
    »
    12 months ago, hide # ^ |
    Rev. 2  
    Vote: I like it +10 Vote: I do not like it

    we are only interested in comparing elements whose indexes are modulo $$$k$$$. Therefore, for the last $$$k$$$ elements (they necessarily belong to the right array), we can take their values and indexes modulo $$$k$$$ and substitute them into a normalized permutation. That is, if $$$b'$$$ is the normalized permutation underlying the array $$$B$$$, then $$$\forall i \in \overline{n - k, n - 1} : b'[i~\%~k] = C[i]$$$. Indexing from $$$0$$$

»
12 months ago, hide # |
Rev. 3  
Vote: I like it +14 Vote: I do not like it

I like sample in D

E is very good, thx for the contest

»
12 months ago, hide # |
 
Vote: I like it +11 Vote: I do not like it

Can you make the problem titles clickable such that they go to the problems, much like other editorials?

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

I feel so bad when I read "it is easy to see" for Problem A because my dumb ass didnt see T__T

»
12 months ago, hide # |
 
Vote: I like it +36 Vote: I do not like it

Loved the images in Problem D! I hope the other Authors take inspiration from you

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

317996659 Can you please tell me why this algorithm failed?

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

    Your code fails for the following input:

    1
    3
    100 1 1
    

    Essentially, what's happening is that due to the greater<> in your sorter, if two indices are equal, then the one on the right appears before the one on the left, which is easy to break (it sees the 1 at the 3rd position and says "Well no robot is to the left or right, so we need to place a robot here."). There is a "small" fix to your code that makes it AC though.

    Hint
»
12 months ago, hide # |
 
Vote: I like it +6 Vote: I do not like it

D-F were amazing!

»
12 months ago, hide # |
Rev. 3  
Vote: I like it +8 Vote: I do not like it

I became a pupil!

Why I think B is more difficult than C?

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

Just my opinion:

$$$ C\lt A\lt B $$$

UPD: After an hour's thinking, I think $$$A\lt C$$$ now.

»
12 months ago, hide # |
Rev. 6  
Vote: I like it +10 Vote: I do not like it

I really like the contest (in particular D and E, but finished E 5 min after the end ://).

My ($$$\mathcal O(n)$$$) solution for E (We don't need a centroid decomposition):

  • By the observation we know that for an edge $$$uv$$$, we can't use it more than $$$\texttt{sz}(u)$$$ times if $$$u$$$ is the lower vertex. This means that if we can make sure that the same colors are only used in the subtree of $$$u$$$ if $$$\texttt(u) \ge \frac{n-1}{2}$$$, the coloring is optimal. We can do this easily by writing out all $$$\frac{n - 1}{2}$$$ colors twice in a row (i.e. $$$1 2 3 ... \frac{n-1}{2} 1 2 ...$$$). Then we do a DFS and every vertex takes the first available color. Note that this is optimal since for all edges with $$$\texttt{sz}(u) \le \frac{n - 1}{2}$$$, the colors used in that subtree will be less than the number of colors and by construction of that array these will be distinct. If $$$\texttt{sz}(u) \ge \frac{n - 1}{2}$$$, the remaining $$$\frac{n - 1}{2} - \texttt{sz}$$$ colors will be distinct, i.e. the contribution of $$$uv$$$ is maximal.
  • As observed earlier, the contribution $$$\mathcal X$$$ of an edge is:
$$$ \mathcal X(\{u, v\}) = \min \{\texttt{sz}(u), n - 1 - \texttt{sz}(u)\} $$$

Removing one edge will always reduce the total score, but we want to minimize the reduction. If we remove an edge to a leaf, the "lost contribution" of that edge is $$$1$$$. The change of contribution of the other edges $$$w_1w_2$$$ is $$$-1$$$ if:

  1. $$$\texttt{sz}(w_2) \le \frac{n - 1}{2}$$$ and $$$u \in \texttt{subtree}(w_2)$$$
  2. $$$\texttt{sz}(w_2) \gt \frac{n - 1}{2}$$$ and $$$u \not\in \texttt{subtree}(w_2)$$$ (if the size is exactly $$$\frac{n - 1}{2}$$$, the new contribution doesn't change)

This means that we can do a simple DFS and pass the following values:

  1. $$$s_1$$$, the score reduced because $$$\texttt{sz}(u) \le \frac{n - 1}{2}$$$ for some parent $$$u$$$
  2. $$$s_2$$$, the score reduced from the other case. Note that initially, $$$s_2$$$ is the number of subtrees with size $$$ \gt \frac{n - 1}{2}$$$ minus one (the root is in none of these subtrees except for the subtree of the root itself); then decrease $$$s_2$$$ if the current vertex has a large subtree size.

The score change can then be calculated as:

$$$ s_\text{old} - s_\text{new} = \underbrace{1}_\text{removing edge to leaf} + s_1 + s_2 $$$

Note: This can be reduced to one score since $$$s_2 = t - 1 - s_3$$$, where $$$t$$$ is the total number of subtrees of size $$$ \gt \frac{n - 1}{2}$$$ while $$$s_3$$$ is the number of vertices with a subtree of size $$$ \gt \frac{n - 1}{2}$$$ on the path to the root, so we decrease $$$s_1$$$ if the subtree size is $$$\le \frac{n - 1}{2}$$$ and increase it if $$$ \gt \frac{n - 1}{2}$$$.

Since we are only running DFSs, the total runtime is $$$\mathcal O(n)$$$.

Submission with $$$s_1, s_2$$$ (Proof by AC)

Edit: Submission/Fixes

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

Thank you for the good contest.Yeah I got orange.

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

My idea of E may be wrong.

First I thought of what if we don't need to delete an edge.I will find the centroid of the tree,let the centroid be root.Then just dfs to confirm there are no same color in each subtree.

And in this problem,I found the centroid,let it be root and dfs,then find the leaf with minimum height,delete the edge linking the leaf and its parent.Then just dfs to confirm there are no same color in each subtree.

I passed the sample and some tests,but was wrong on pretest 8,Could anybody explain where is wrong

318013026

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

I've tried first three problems.Lovely Problemset.truly!

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

Problem B was a good challenge for me. Thanks for this problem

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

2108A — Permutation Warm-Up

How to prove that max value of f(p) = floor((n^2) / 2).

From the editorial I can only understand that it is possible, but how to prove that it is max ?

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

    For getting maximum answer we need to keep the values so that we git maximum manhattan distance between them. and for that you can see that its to put it in reverse order. thus the summation would result in maximum which is the answer.

    if you want you can try all other ways for a small n .

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

    I posted a proof lower =)

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

after started recently only I was given advice to attempt contests all contests, EDU, DIV2. i don't think i am even ready for that, 2 contest — was able to solve only 1 A that also from EDU, nothing from here . so, can anyone provide another advice?

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

    Don't be disheartened—I felt this Div2A was much more difficult than the recent ones I've solved; I myself could not prove that my solution was optimal during contest time. You can try the recent Div2A's first to see if you could constantly solve them and ready for future Div2A's. Div. 3 & 4's are few and far between, so if you decide to wait for them you'll likely have to do problems entirely in practice mode.

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

Can some one tell me where am i wrong in D, here is my Solution

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

Editorial for A is so bad...

"For this p, f(p)=⌊n22⌋." Proof ?

"since we were adding +2 at each step" -> Wrong. Some steps do not change the value.

"Let’s prove that we can’t get any other values [...] it’s easy to see that" -> Is this a joke ?! Repeating your premise and claiming it's easy is no proof. This is actually the main difficulty of the problem.

"Second, we can only obtain even values, because each swap changes the answer by an odd number." Is the "odd" a typo for "even" ? Also, Proof ?

What's the point of pretending to prove anything, if what you'll say explicitely will be more trivial than what you dont bother to prove ? Just say one can guess this perm is optimal and prove by AC.

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

    The value for the permutation given is sum(n-1-2k) with k from 0 to ceil(n-1/2)==floor(n/2)

    Either you know the sum 0..N of odd numbers is N^2 or you can split the sum and use sum 0..N is N*(N+1)/2. Sure it's basic but not especially trivial for a div2A.

    An optimal perm cannot have a number smaller than half in the first half and bigger than half in the second otherwise swapping them would give a higher answer. Let's consider the first half if there was a number lower than an other placed before this higher number we could increase the answer by swapping them. Same thing applies to the second half. We have proven the decreasing perm is optimal for n even. For n odd swapping the middle number doesnt change the answer if the above properties are respected (the displaced middle compensates exactly for the score lost)

    I cant see anything elegant to prove that the answer is always even. We can take a permutation do a swap on it, and study each case if i and j are both greater or smaller than both pi and pj the answer is the same, if pi<=i<j<=pj or i<=pi<pj<=j we contribute to the opposite of what we used to the difference is twice the contribution. Lastly for i<=pi<=j<=pj the difference in contribution is 2pi-2j by just writing it out we can do similarly for pi<=i<=pj<=j. Since all permutations can be reached through a series of swaps for the 1..N perm, we have a proof.

    Anyone has something simpler ?

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

      We can use the fact that $$$|x| \equiv x \pmod{2}$$$ (it is either $$$x$$$ or $$$-x$$$, both of which satisfy the congruence). This gives that $$$|p_1 - 1| + |p_2 - 2| + \dots + |p_n - n| \equiv (p_1 + p_2 + \dots + p_n) - (1 + 2 + \dots + n) \equiv 0 \pmod{2}$$$.

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

      This might be what Hashman was saying, but we know that if we got rid of the absolute values, then the total sum would always be 0 (we'd just be subtracting the sum of a non-permuted array from the sum of a permuted array). So, if we categorize the value of each difference (in the non-absolute value case) as either "positive," "negative," or "zero," we know that the positive and negative equal each other in magnitude. Thus, when we throw the abs-vals back in to get the problem statement, we know that the total sum must be even.

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

can any one explain me the "no mans land" condition given in the editorial for Problem D ?

  • »
    »
    12 months ago, hide # ^ |
    Rev. 2  
    Vote: I like it +9 Vote: I do not like it

    It means that the elements between the boundaries do not definitively belong to the left nor the right array (no array claims it), because it matches the patterns for both arrays. An example is the last test case in the problem statement:

    1 3 2 4 ] 1 3 [ 4 2 1 3 4 2
    

    The pattern for A is 1 3 2 4, and for B is 1 3 4 2. Neither array can claim the elements between the boundaries (1 3), because they match the pattern for the other array as well, and thus any split is valid.

»
12 months ago, hide # |
 
Vote: I like it +4 Vote: I do not like it

thx for this awesome contest fr like it yea i didnt Register but e is so haaaaaaaaaard-_____-

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

A and D are interesting.

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

Could any tell me why D need binary twice

after we binary first we ' ll get an answer range which its len less 50

then we just find it straight isn t it?

i think that will be 3k + log(n / k), could anyone proof it ? or why its not right?

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

For interactive problems like Problem D, how to design and test cases?

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

Can anyone provide a DSU implementation for C?

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

eugenechka.boyko.2_0-0 why the below code is running.I have no proof for this and i did brute-force for 1<=N<=10 and noticed this 1 2 3 5 7 10 13 17 21 26

arr=[1]
current=1
for i in range(2,501,2):
  arr.append(arr[-1]+current)
  arr.append(arr[-1]+current)
  current+=1
 
 
for i in range(int(input())):
  print(arr[int(input())-1])
»
12 months ago, hide # |
 
Vote: I like it +8 Vote: I do not like it

respect for authors for amazing tutorial and notes. I hope such notes and tutorial will be in every round.

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

In Problem C,I used dp and binary search to solve it.

submission #317966737

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

Nice editorial.

Before this contest, I didn't even know that popcount existed, so I made a literal function to count the number of 1 bits in x

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

What is the proof of optimality in taking a reverse permutation in problem A? It could be a local maximma. Why can there not a be a configuration from a different algorithm of construction that achieves higher? Can someone provide a proper proof of this?

(I tried asking ChatGPT, it failed to prove it.)

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

problem F is insane

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

why was B substantially harder than C

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

Can anyone help me to findout mistake in my code in Problem D of this round . It is failing on some test case where answer should be -1 but my code is printing some number. Submission Id:323253380

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

324755461 Can anyone tell why this code is failing?

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

Does there exist a Graph approach for C , if yes then please comment down your approach with your accepted code.I am just curious because one of the tag of this question is showing graph.

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

const int N = 2e5 + 10; int n, a[N]; PII b[N]; bool st[N]; **** int main(){ ** IOS; ** ** int _ = 1;** ** cin >> ;** ** while(--)** ** {** ** cin >> n;** ** for(int i = 1; i <= n; ++ i)** ** cin >> a[i], b[i] = {a[i], i}, st[i] = false;** ** sort(b + 1, b + 1 + n);** ** int cnt = 0;** ** for(int i = n; i >= 1; -- i)** ** {** ** int x = b[i].second;** ** if(!st[x])** ** st[x] = true, cnt++;** ** st[x — 1] = true, st[x + 1] = true;** ** }** ** cout << cnt << endl;** ** }** **** ** return 0;** } why C this way was wrong?

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

2108C - Neo's Escape I got scared after seeing the topics written in the problem tags of this question, but this is the easiest question of 1500 rating i have ever solved 368354382