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

Автор Supermagzzz, история, 6 лет назад, перевод, По-русски

Привет Codeforces!

Мы, Supermagzzz, Stepavly, AdvancerMan, unreal.eugene, студенты ИТМО, желая внести свой вклад в развитие сообщества Codeforces, обратились к MikeMirzayanov с предложением помочь с тестированием новых раундов. Но MikeMirzayanov предложил нам свою помощь в разработке собственного раунда. Поэтому...

Мы рады пригласить вас на Codeforces Round #603 (Div. 2), который пройдет в Nov/29/2019 17:35 (Moscow time). Он будет рейтинговым для всех участников, чей рейтинг ниже 2100. Вам будет предложено шесть задач и два часа на их решение.

Задачи были придуманы и подготовлены Supermagzzz, Stepavly, AdvancerMan, unreal.eugene, MikeMirzayanov.

Особую благодарность выражаем:

  • MikeMirzayanov за замечательные системы Codeforces и Polygon, а также за координирование нашего раунда.

UPD: Разбалловка: 500 — 1250 — 1250 — 1750 — 2500 — 3000

Надеемся, вам понравятся задачи. Удачи и высокого рейтинга!

UPD1.5: Спасибо за участие! Поздравляем победителей!

Top 5 Div. 2:

  1. Lazyeval
  2. twitch.tv_wookje
  3. Byzantium
  4. rainboy
  5. Fuyuki

Top 5 Div. 2 + unoffical:

  1. Lazyeval
  2. twitch.tv_wookje
  3. saketh
  4. KrK
  5. Byzantium

UPD2: Разбор выложен!

  • Проголосовать: нравится
  • +325
  • Проголосовать: не нравится

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

Are there any subtasks?

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

Please share the score distribution.

»
6 лет назад, скрыть # |
Rev. 2  
Проголосовать: нравится -31 Проголосовать: не нравится

I hope tomorrow I will be able to reach 2100 :)

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

This time no copy-pasted part ! ;)

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

hope to become specialist in this contest.

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

good luck for all

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

Score distribution?

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

There is a bug. I see some yellow coders in the official standings!

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

How to solve A?Am not sure of my solution :(

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

Non-dp solution for F:

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

    Your solution is so overcomplicated, but still very cool.

    Linear solution to F
  • »
    »
    6 лет назад, скрыть # ^ |
     
    Проголосовать: нравится 0 Проголосовать: не нравится

    Hi! That's a nice solution. I just tried your approach. But, I believe that the case of deleting all edges from one of the trees is also covered as a special case in the minimum cut algorithm. Instead of outputting $$$max(a-1, b-1, a+b-maxflow)$$$, I just outputted $$$(a+b-maxflow)$$$, and it got AC.

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

A-E all classical problems

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

The problems were great! Who can tell me how to solve C?

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

I'm sad I didn't see D solution is it graphs or something

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

Is pD really that easy ?? I tried to do it with a bitmask-things but I couldn't. Can somebody help?

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

In F, wires between nodes do not intersect. shouldn't it be bolded?

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

    Hmmm, my bad. I didn't see the condition It is guaranteed that each grid is a tree, which has exactly n leaves and each leaf is connected with one device. Also, it is guaranteed, that for each tree exists a depth-first search from the node 1, that visits leaves in order of connection to devices.

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

I don't understand why such a tight time limit was put in E. It cost me multiple TLEs when writing output using cout, however with printf it passed.

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

How to do first if there are n piles.

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

Is intended solution for E Segment Trees w/ Range Propagation and then leveraging min/max/sum?

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

In Problem E.

How to update number of different color need to use if text is correct

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

    I found that we can use the maximum prefix value(by assigning openings as 1 and closings at -1) that one can get as answer, because answer is longest opening sequence(it may have some complete brackets within) and any closing would just decrease the answer

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

I'm so confused where do I wrong on E. I was so close to an AK.

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

Anyone got the wrong answer on pretest 2 of A and then got correct?

Or any possible testcase where this could get wrong?

Thanks in advance :)

My solution — https://mirror.codeforces.com/contest/1263/submission/65990422 (I stresstyped every possible case because I was getting the wrong answer :( )

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

strange round. D is just — "oh my, write DSU". E is just "oh my, write segtree with mass updates".

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

    No DSU was needed in D. Create N+26 nodes (N nodes for each string, 26 nodes for each character). Connect node of string and character, if the string contains this character. Answer = number of connected components among nodes corresponding to strings.

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

I think ideas of CD are quite standard. E is just a boring version of this.

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

Вопрос к авторам: зачем в раунд добавили Е? Кажется, что это просто задача на реализацию, которая не может оставить положительных впечатлений.

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

Very easy div2 contest.

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

For probB ,My solution passed pretest 2 . But failed on test 2 , is'nt it amazing .

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

So, I tried to solve E using a Segment Tree with lazy propagation. I wrote the bracket series as a prefix sum, for example like [1,2,3,2,1,0,-1,0,1]. Then, to process 'L' and 'R' moves I just shifted an index variable. To process '(' and ')' updates I simply lazily updated all the numbers in the prefix after the index i. Then, to find if it was valid or not, I simply used Segment Tree range min and range max query.

In total, my algorithm was Nlog(N). And yet it TLED. Any reason why? (I used Java)

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

A is quite beautiful if you prove things by construction and the triangle inequaltiy.

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

How to solve B..?

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

    For repeating pins, replace their first digit with the digit that is not present in other pins first digit. Since maximum value of n is 10, we can be sure that all digits will be distinct after the process.

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

    I thought it like this : Say I iterate over the input values(as strings) and if I have more than 2 strings of current type, I can change it to a whole other string just by changing 1 character because if I just change a single character, I can get 40 strings or nearabout that number of strings, so I just find such a string by brute force, trying changing each character so 4*10 combinations are there, and changing string value to the one which is not present in my set of strings, and incrementing the count of moves by 1.Finally I print all the new strings(or old ones in case of unchanged....)!

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

The problemset is nice although i performed badly this time :(

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

"L — move the cursor one character to the left (remains in place if it already points to the first character);"

"It is guaranteed that all characters in a string are valid commands."

Somehow I thought the second line meant that there can't be an input where you go left from the first position...... (and it doesn't seem to even be in the pretests?)

(Also trying to fail $$$O(n\log n)$$$ segtree solutions with $$$n \le 10^{6}$$$ and 1s TL is not really cool as many such implementations actually would pass. I think this has been said by many people in different contests, but either give up on failing these solutions or increase the constraints so that it would clearly fail all (or at least those without extremely heavy constant optimizations attempts) "bad solutions" (in this case it's hard to increase because of I/O size though, so maybe some input/output compression would work))

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

MikeMirzayanov Did you just banned Ashishgup only because he wrote "A-E are classical".

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

    He is not banned, he is temporarily in the read-only mode. I believe that the rules should be the same for everyone. And any discussion of problems during the contest is unacceptable. We cannot predict how this or that opinion about the problems will affect the participants. I am pleased to discuss the problems, but this can only be done after the end of the round.

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

Too much easy problem set!

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

Can anybody tell me if this solution is correct for problem E? My solution use segment tree without lazy propagation. For each node in the segment tree I know v[nod].left = number or '(' without a pair (basically open) , v[nod].right = same but for ')' and v[nod].depth = how many colors do I need. How to find v[nod].depth if we know every information for its children? v[nod].depth = max ( v[ 2*nod ].depth, v[ 2*nod+1 ].depth) maximum depth of its children + min ( v[2*nod].left, v[2*nod+1].right) this if for: '(' CONFIGURATION + CONFIGURATION '))' so in this case I increase the depth with 1 because I make new pairs. I had a bug in implementation so I couldn't submit it, but does anybody have the same approach?

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

Maybe I am the only one who solved B using mincost-maxflow.

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

My first submission to D got accepted but it doesn't pass

4 
a 
ac 
b 
cb
»
6 лет назад, скрыть # |
 
Проголосовать: нравится +22 Проголосовать: не нравится

Good contest!

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

I think the problems were much easy and this should've been a div 3... anyways... thanks to the setters.

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

MikeMirzayanov Supermagzzz My solution for E passed the pre-tests, but after system testing gave TLE on test case 5 which was part of the pretests.65979337

Moreover changing language from c++17 to C++14 got accepted 65994359.

Can you look into it.

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

    See, your solution is on the edge between OK and TL. It is just a random it fits in TL or not. Just try to improve your solution a bit. Also, it is a good practice to verify that your solution fits in TL with some gap on pretests.

    As I see this problem can be solved even on Python, so I don't think the TL is too tight.

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

I Got AC in problem D, I think it shouldn't pass. Consider the following test case: 3 asd qwe aq

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

I used a O(n) algorithm to solve Problem F.

It can be proved easily that when each of the electrical devices is covered by just one grid, the answer will be the best. And the problem guarantees that every nodes x in the grids will cover a range [l, r]. That means we can disconnect the electrical devices with the gird if we erase the edges connecting to the nodes in the subtree of x. We can get it by doing a dfs/bfs. Then the problem is transfromed to an easier problem: There are some ranges, each range has a value. we need use them to cover the range [1, n] and maximize the sum of these values. dp[i] means the maximum sum of value when the range [1, i] is be coverd. For dp[i], we just need to check the ranges beginning at i + 1 to transform it. So every range will be used just one time. It also solves in O(n).

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

F can be easily done in $$$O(n)$$$

https://paste.ubuntu.com/p/8SJHkS5w6d/

I'm very confused about range of $$$n$$$ in contest....

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

It is the first time I reach Purple, thanks to this interesting contest.

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

I can't understand why my submission for B got WA.

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

The templet of segment tree used in Problem E. can be found at https://github.com/HeRaNO/OI-ICPC-Codes/blob/master/UESTC/2156.cpp

But someone else used that templet in E and our codes are almost the same. So I was blocked, but I promise that we didn't communicate with each other during the contest.

I wonder how to solve the misunderstanding.

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

MikeMirzayanov, why has my 65968043 to 1263A - Sweet Problem been "Skipped"? It's the first time when i see this. By the way, I didn't cheat. At the round verdict was all pretests passed and I leave round with happy thought that I 'll become green. Now I am very disappointed.

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

What is the answer for this input of problem D?

4
a
b
ab
acd

EDIT: How about this?

3
abc
abd
abe
»
6 лет назад, скрыть # |
 
Проголосовать: нравится +5 Проголосовать: не нравится

Test case for 1263D - Secret Passwords was weak.

This submission 65988894 gives output 2 for input 3 ab bc ca, but output should be 1.

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

    yeah, I got accepted with the false solution(naive one), after the contest, you can check 66023526 which fails for a simple test case like this: 7 a b c d ab cd abcd

    Here the correct answer is 1, but the program outputs 0.

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

So, I am done with the comments, would like to read the editorial now. Thanks!

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

in the rating changes the rating predictor rating is not same as the changed rating for this contest has codeforces changed their rating algorithm and forgot to update the predictor????

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

I don't understand what hacking is. Does anyone explain it to me? And when I get hacked?

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

Well at least I found out about how editors color the brackets in code today! XD

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

Can anyone please tell me how to hack a submission after the contest ? I am getting this message "You cannot hack the submission"

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

This was a very interesting contest !

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

There seems to be a problem with the C compiler for problem C. My solution 66003014 submitted in GNU C11 TLEd on test 4 but the exact same solution submitted in GNU C++17 66003340 passed comfortably MikeMirzayanov Supermagzzz

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

WDYT about solving 1263F - Economic Difficulties with min-cost-max-flow? Let every edge have flow one and cost one. The sink is connected to the two root nodes, and the n devices have a single outgoing edge to a sink node; each with flow 1. The min-cost flow will then use as few edges as possible. MCMF can be solved in $$$O(E^2)$$$, which should be small enough since $$$E\approx 2000$$$.

If I'm right, then the whole of the problemset could be solved pretty easily with standard copy-pastable algorithms.

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

when the editorial will be posted?

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

Is Problem A solvable with binary search? If yes, can anyone explain a bit :)

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

I can't find the tutorial. I saw someone solved problem A with the following idea. sum <- r+g+b if the smallest two of r,g,b is smaller than the largest one ans = the sum of the smallest two else ans= (r+g+b)/2

Can anyone prove the correctness of it mathematically?

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

    Assume that the values are sorted $$$a \leq b \leq c$$$

    If $$$a + b \lt c$$$, then the optimal strategy is to take $$$a$$$ with $$$c$$$ until $$$a$$$ is gone, then take $$$b$$$ with $$$c$$$ until $$$b$$$ is gone. It is impossible to access the rest of the candies in $$$c$$$. Total number of moves = $$$a + b$$$.

    Otherwise, the optimal strategy is to take $$$a$$$ with $$$c$$$ until $$$c = b$$$, at which point $$$a := a - (c - b)$$$, then take $$$b$$$ with $$$c$$$ until $$$a = b = c$$$. Then, there are three sub-scenarios:

    • $$$\geq 2$$$, in which case you can take $$$ab$$$, $$$bc$$$, $$$ac$$$ and decrease all of them by two, then repeat

    • $$$= 1$$$, in which case you just take any two and leave a single piece,

    • $$$= 0$$$, in which case you obviously stop

    Since the strategy for this scenario always leaves $$$0$$$ or $$$1$$$ candies, the number of steps is $$$\lfloor \dfrac {a + b + c} {2} \rfloor$$$.

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

I'm pretty new to Codeforces and competitive programming in general. Where do I find the editorials to the problems?

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

When will Editorials be updated ?

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

Why MCMF is wrong for F ? see some MCMF solution with same wrong answer on test 5. code

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

I solved problem E in O(n) by six stacks.

As we can see, for a regular bracket sequence, we can calculate depth of it by simply calculating the max prefix sum of bracket sequence by assume '(' for -1 and ')' for 1,else for 0.

e.g

"((0)())" can convert to 1 1 0 -1 1 -1 -1,and the prefix of it is 1 2 0 1 2 1 0,which the max value is 2 for the answer.

However,we have to deal with the irregular bracket squence like ")(",because it should be output -1(for irregular) instead of 0,this can be solved by calculating the min value of ths prefix sum array.If it is a negative number, it must be a irregular sequence.

Now we just need to deal with the problem by what we said before.

We maintain two stacks for prefix sum,stack A for restoring from begin to current cursor,stack B for current cursor's next position to the end of the prefix array.We can see the each operation will only happen in the curosr's postion,so if the cursor move to the left,we just need to pop the top value of stack B to stack A,moving to right is same.

e.g

"((0) ())", space for separating. For stack A,it is [1,2,0,1]. For stack B, it is [1,2,1]**(looking from right to left,it is '))(')**.

In the same way,we maintain two stacks for max prefix sum and two stacks for min prefix sum.

Thus we can calculate the answer by these stacks just check the top value of prefix sum stack A and prefix sum stack B are the same and sure two min stacks's top value is >=0,if all the condition is true,the answer is the max of two max prefix stacks

The code is here 66020705

Sorry for my poor English >_<

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

This contest is so great!!!

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

For me, A is still harder than B,C and D... It required more time than any other task for me... What's the idea behind solving it in one line?

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

How to solve problem E using lazy segment tree? :)

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

The problem with problem D is still not fixed? There are still WA solutions out there having AC verdict. :/

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

Thanks for the contest!