Блог пользователя eugenechka.boyko.2_0-0

Автор eugenechka.boyko.2_0-0, 16 месяцев назад, По-русски

2108A - Перестановочный прогрев

Автор: eugenechka.boyko.2_0-0

Разбор
Решение

2108B - Разложение в сумму

Автор: eugenechka.boyko.2_0-0

Разбор
Решение

2108C - Побег Нео

Автор: suprend

Разбор
Решение

2108D - Найти склейку в стоге чисел

Автор: m3tr0

Разбор
Решение

2108E - Разборки с ёлкой

Автор: eugenechka.boyko.2_0-0

Разбор
Решение

2108F - Падшие башни

Автор: m3tr0

Разбор
Формальное доказательство
Решение
Разбор задач Codeforces Round 1022 (Div. 2)
  • Проголосовать: нравится
  • +241
  • Проголосовать: не нравится

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

Автокомментарий: текст был обновлен пользователем eugenechka.boyko.2_0-0 (предыдущая версия, новая версия, сравнить).

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

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

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

Problem F is awesome, thanks for the contest!

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

As A participant I reeally enjoy thanks for your contest.

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

The solution for problem F is poetic

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

Problem A is an easier version of this.

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

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

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

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$$$

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

    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$$$

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

I like sample in D

E is very good, thx for the contest

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

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

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

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

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

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

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

317996659 Can you please tell me why this algorithm failed?

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

D-F were amazing!

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

I became a pupil!

Why I think B is more difficult than C?

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

Just my opinion:

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

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

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

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

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

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

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

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

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

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 ?

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

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

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

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

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

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.

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

    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 ?

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

Can any one explain me the no mans land condition given in the editorial ?

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

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

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

    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.

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

thx for contest<3 :((((((((((

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

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

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

A and D are interesting.

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

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?

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

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

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

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

submission #317966737

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

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

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

problem F is insane

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

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

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

324755461 Can anyone tell why this code is failing?

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

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.

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

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 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

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