Скоро Codeforces Round 1133 (Div. 1, Div. 2)! Регистрация здесь. ×

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

Автор BledDest, история, 3 месяца назад, По-русски

2253A - Лучшая карта

Идея: BledDest

Разбор
Решение (BledDest)

2253B - Гиперкарп и панель управления

Идея: FelixArg

Разбор
Решение (FelixArg)

2253C - Сумма различных в матрице

Идея: BledDest

Разбор
Решение (BledDest)

2253D - Гиперкарп и межпространственные прыжки

Идея: FelixArg

Разбор
Решение (FelixArg)

2253E - Пересечение диаметров

Идея: BledDest

Разбор
Решение (BledDest)

2253F - 4-красота

Идея: BledDest

Разбор
Решение (BledDest)
  • Проголосовать: нравится
  • +55
  • Проголосовать: не нравится

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

without good sampleset i would have been cooked

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

first

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

But D just needed a simple greedy 386119523

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

Yeaah, finally )))

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

Alternative solution of D:

Let $$$k$$$ be the largest integer with $$$\frac{k \cdot (k + 1)}{2} \le x + y$$$. Consider two bag with capacity $$$x, y$$$ respectively. For $$$w = k, k - 1, \ldots, 1$$$ in this order, put the item with weight $$$w$$$ into the bag with larger capacity remain. Let $$$x', y'$$$ denote the final capacity remain for two bags. We claim this process minimize $$$\max(x', y')$$$.

Proof.

W.L.O.G. assume $$$x \ge y$$$, call the bag with $$$x$$$ initial capacity the first bag, and the other be the second bag.

case 1 ($$$x \ge y + \frac{k\cdot (k + 1)}{2}$$$): trivial

case 2: items would be add into the first bag until its capacity is no more than the second bag, let $$$m$$$ be the item added to make this happen. then at this point, the difference of capacity between two bag would be no more than $$$m$$$, and in the subsequent item addition, the difference would be no more than the item added last, thus $$$|x' - y'| \le 1$$$ holds at the end, which achieve the lower bound of $$$\max(x', y')$$$.

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

In Problem E (2253E), how would i know number of distinct LCAs would be O($$$\sqrt{n}$$$)? I was stuck with thinking it was O($$$n^2$$$) solution and won't pass.

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

    We have $$$n-1$$$ edges, and each edge either part of diameter or not, and each node of diameter can form just a single distinct number, and sum of nodes limited on $$$n$$$, so you wont have more than $$$sqrt(n)$$$ distinct numbers. We can prove that by summing the first k small values such that sum won't exceed $$$n$$$.

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

    Firstly discard all nodes who's subtree does NOT have a descendant of maximal depth, as these can never be valid LCA's. For the remaining nodes, define $$$cnt[d]$$$ as the number of nodes at depth $$$d$$$.

    Since each path is guaranteed to continue down until the maximal depth, we know that $$$cnt[d + 1] \geq cnt[d]$$$. Furthermore, when depth $$$d$$$ contains a valid LCA (i.e. some node has two or more children with max depth descendants), then $$$cnt[d + 1] \geq cnt[d] + 1$$$.

    If there are $$$r$$$ distinct achievable depths, then the width increases at least $$$r$$$ times. After the i-th increase, the width is at least $$$i+1$$$. Therefore, among the levels containing these increases and the level immediately after each one, there are at least $$$1 + 2 + \ldots + (r + 1)$$$ nodes. Since the number of nodes per valid LCA depth grows quadratically, the number of valid LCA depths per node grows at a rate of $$$O(\sqrt{n})$$$.

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

I believe there's a typo in F. I think it should be x mod 2 != 0 and x mod 3 != 0 whereas it says the opposite now.

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

I think F > C > E > D > B > A.

E is a very simple property about trees whose diameter length is odd, you just need to replace the middle edge of the diameter with a new vertex, and the problem becomes trivial (it turns into a tree with even diameter, where the center of the diameter has only two subtrees).

D is a straightforward "brute-force and find the pattern" problem; you can easily spot the relation between the number of operations and the landing position, and then it's just a simple contribution‑splitting construction.

As for C, my two-pointer got WA on test 2, which really annoyed me and cost me a lot of time.

For F, I never expected it could be solved with that kind of bitmask DP, so I won't comment much, but once you think of it, it's indeed not hard.

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

I was able to write this much shorter solution for D. The idea is the same as the editorial's, but I didn't have to do any math to find the optimal ending point (from $$$(x,y)$$$, I just brute forced the walk back).

By the way, was anyone particularly troubled by C? For me, it took nearly an hour to find the correct greedy.

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

Alternative $$$O(n)$$$ solution for B.

First, ignore the swap.

Since we can delete elements, from every maximal block of equal values we only need to keep one element. Therefore, the best answer without using the swap is just the number of blocks:

$$$ base = 1 + \sum_{i=1}^{n-1} [a_i \ne a_{i-1}] $$$

Now consider the swap.

It is enough to try swapping two elements that are already adjacent in the original array. If we choose two non-adjacent elements, we have to delete everything between them to make them adjacent, but those intermediate different blocks were already useful since we could keep one element from each of them.

So we only try swapping $$$a_i$$$ and $$$a_{i+1}$$$.

Locally, we have

... L | a[i] | a[i+1] | R ...

and after the swap

... L | a[i+1] | a[i] | R ...

The middle boundary does not change, since

$$$ [a_i \ne a_{i+1}] = [a_{i+1} \ne a_i]. $$$

Therefore, only the two outer boundaries can change. The change for this swap is

$$$ \Delta = -[a_{i-1} \ne a_i] -[a_{i+1} \ne a_{i+2}] +[a_{i-1} \ne a_{i+1}] +[a_i \ne a_{i+2}], $$$

ignoring terms that are outside the array.

Finally,

$$$ answer = base + \max(0, \max_i \Delta_i). $$$

Both base and the best delta can be calculated in the same loop.

Complexity: $$$O(n)$$$ time and $$$O(1)$$$ extra space.

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

I loved C, D & E, Good Contest!

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

Hi, can anyone explain me this case in problem B... I was looking at the solution provided in the tutorial

1 , 1, 1, 2, 2, 2 ...... if i exchange middle 2 and middle 1 ..... I can keep all 6 but now answer is m+4 contrary to the answer provided in the tutorial ..... according to it i can only keep at max 4?

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

thanks for the editorial

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

Superb Editorial + very nice problems__