Codeforces celebrates 10 years! We are pleased to announce the crowdfunding-campaign. Congratulate us by the link https://codeforces.com/10years. ×

### Nickolas's blog

By Nickolas, 2 years ago, translation, ,

Codeforces Round #455 for Div 2 competitors will be held on December 27 at 19:35 MSK. As usual, Div 1 competitors can join out of competition.

The round will be rated.

This round is based on tasks for summer contest for interns algO(1). If you have seen the problems from that contest before, please don't participate in the round. The problems were prepared by Maxim Kalinin (slycelote), Alexander Milanin (Milanin), Ibragim Ismailov (ibra) and me (Nickolas).

The competitors will be given six problems and two hours to solve them. The scoring distribution will be 500-1000-1500-1750-2000-2500.

We hope you'll like the problems. Good luck!

UPD: thanks to HellKitsune, gritukan, gainullin.ildar, Arpa and Livace for testing the problems!

UPD: The contest is over. Editorial can be found here.

Congratulations to winners!

Div. 2:

Div. 1:

• +334

 » 2 years ago, # |   0 I'm looking forward to this contest
 » 2 years ago, # |   +17 May I know how many people participated in summer contest for interns algO(1)?
•  » » 2 years ago, # ^ |   +33 We had 33 teams, each team had up to 3 people, so about 60 people.
•  » » » 2 years ago, # ^ |   -37 33*3 , how this is going to be 60 ?
•  » » » » 2 years ago, # ^ |   +23 up to 3
•  » » » » 2 years ago, # ^ |   +34 ... up to 3 people...Obviously, not all teams had three members :-)
•  » » » » » 2 years ago, # ^ |   +12 got it.
 » 2 years ago, # |   +41 3 consecutive contests? I think this is a perfect end of year.
 » 2 years ago, # |   +37 is it the boxing day of problem solving ?
 » 2 years ago, # |   +33 "summer contest for interns algO(1).....". It seems to me some problems will be solvable in O(1).
•  » » 2 years ago, # ^ |   0 I hope for the same
 » 2 years ago, # |   +18 Why always scoring distribution is announced later ?
 » 2 years ago, # | ← Rev. 2 →   +10 She sets only contests like April Fools Contest 2017, Surprise Language Round #7 etc,Seeing this one is already based on previous contest,Get ready for Boxing Day.
 » 2 years ago, # |   -47 a girl announces the round, hope it's a nice contest :D
•  » » 2 years ago, # ^ |   +56 Don't be sexist in 2018?
•  » » » 2 years ago, # ^ |   -30 he isn't sexist he is just a nerdy fag like u
•  » » » 2 years ago, # ^ |   +39 I don't see how this is sexist. He said he hoped it would be a nice contest. The fact that he mentioned a girl announcing a round might as well just be because he is surprised because of the low ratio of females in competitive programming.What if I said "a guy announces the round, hope it's a nice contest :D?"How many comments of yours would I see? (Hint: Zero)I don't see how people can get along if every little thing is scrutinized as some type subversive sexism, when it really isn't.
•  » » » » 2 years ago, # ^ |   -29 don't waste your time with children, have a nice day!
•  » » » » 2 years ago, # ^ |   +11 If a guy had announced no one would have commented that in the first place.
 » 2 years ago, # |   +28 Glad to see the scoring distribution one day before contest...:)
 » 2 years ago, # | ← Rev. 2 →   +38
 » 2 years ago, # |   +40 Three contests at the end of the year. A great gift by Codeforces! :)
 » 2 years ago, # |   +19 The scoring distribution will be 500-1000-1500-1750-2000-2500.thinking if I could solve 5 problems for the first time
•  » » 2 years ago, # ^ |   +9 Good luck
•  » » » 2 years ago, # ^ |   0 Sadly I can't make it :(Still thanks ;)
 » 2 years ago, # |   +35 Why don't you thank Mike?
•  » » 2 years ago, # ^ | ← Rev. 2 →   0 good rating and easy problems will come to youbut only if you thank MikeMirzayanov for the platforms
 » 2 years ago, # | ← Rev. 2 →   -20 It will be fun :)
• »
»
2 years ago, # ^ |
-30

# are bhai bhai bhai

 » 2 years ago, # |   +61 Mike say "Two consecutive contests without thanking me, and this one even not say 'hi codeforces'."
 » 2 years ago, # |   +2 Again no one thanked to mike. ..it means :( Your text to link here...
 » 2 years ago, # |   0 hahahaha
 » 2 years ago, # |   +25
 » 2 years ago, # |   0 Thanks Mike Mirzayanov for the platform and for awesome contests!!!
 » 2 years ago, # | ← Rev. 3 →   +13 Dreaming of purple after these 3 contests!! Good luck everyone!
•  » » 2 years ago, # ^ |   +6 gl hf
 » 2 years ago, # |   -33 Why does the tourist not attend?
•  » » 2 years ago, # ^ |   +2 Because he is busy traveling and contests for div 2 nine for div 1.
•  » » 2 years ago, # ^ |   0 Did you assume he was not attending? He might even be attending on a fake account, kinda like how you are posting on a fake account.
•  » » 2 years ago, # ^ |   0 because it's a div.2 contest...
 » 2 years ago, # | ← Rev. 2 →   0 So the problems are known to many people? *I don't know the "summer contest for interns algO(1)" Is it very popular?? Or just few people can participate in it?
 » 2 years ago, # |   0 Some kind of disaster gonna come.. no thanking mike and polygon??
 » 2 years ago, # |   +13 The contest is hidden because no one thanked Mike, click here to view it.
•  » » 2 years ago, # ^ | ← Rev. 2 →   +8 Let's thank MikeMirzayanov on behalf of the codeforces community.
 » 2 years ago, # |   -30 It will be a good match because all of its designers are for Microsoft.
 » 2 years ago, # |   -11 Can we enter the cobtest as a team ?
•  » » 2 years ago, # ^ |   +12 As you can see, there is no such button on the registration page.But after the end of the round, as usual, you will be able to start virtual participation as a team.
 » 2 years ago, # |   +14 Can we hope for short problem statements?
•  » » 2 years ago, # ^ | ← Rev. 2 →   +1 I don't think so , they always have to make it complicated
 » 2 years ago, # |   +4 there is something missing...
 » 2 years ago, # |   +16 So happy adamant is finally not in the list of problemsetters! Just kidding though, the last two contests were pretty cool.
•  » » 2 years ago, # ^ |   0 a good time to increase rating before his contests? gl
 » 2 years ago, # |   +2 My New Year Resolution : I WILL WRITE CLEAN CODES
 » 2 years ago, # |   0 It's been a while since I joined CF contests! Lucky to catch one before the end of 2017 :D
 » 2 years ago, # |   0 I forgot to register. Can someone register me for this contest (out of competition)?
•  » » 2 years ago, # ^ |   0 The quote about extra registration: If you are late to register in 5 minutes before the start, you can register later during the extra registration. Extra registration opens 10 minutes after the contest starts and lasts 20 minutes.
•  » » » 2 years ago, # ^ |   0 Thanks Mike. It has been 10 mins, but dont see the extra registration icon.
 » 2 years ago, # |   -13 slightly long queue right now!
 » 2 years ago, # | ← Rev. 2 →   0 Didn't like contest, statements were very hard to understand.By the way, how to understand statement of B? I just wrote magical formula with samples and it got AC :P
•  » » 2 years ago, # ^ |   0 Think of "layer" as in Photoshop.
•  » » » 2 years ago, # ^ |   0 Still don't get it. Looking picture for explanation, but it just don't give a sh*t. Am I silly :(
•  » » » » 2 years ago, # ^ |   0 Alternatively, you can think of "layer" as "set". A set of segments must contain pairwise disjoint segments. Find the minimum number of sets that contain all the segments.
•  » » » » » 2 years ago, # ^ |   0 Emm, I understood now. Thanks!
 » 2 years ago, # |   0 What was pretest 3 on problem C?
•  » » 2 years ago, # ^ |   0 6 f s f s f s ANS : 5
•  » » 2 years ago, # ^ |   0 Integer overflow I think
•  » » 2 years ago, # ^ | ← Rev. 3 →   0 I think it is something like this 7 f f f f f s s Answer: 6
•  » » » 2 years ago, # ^ |   0 how is the answer 6. i think it should be 2
•  » » » » 2 years ago, # ^ |   +4 Indentation of the first 6 statements (5 loops and first simple statement) is defined uniquely. The 7th statement can have any indent from 0 to 5 (be part of any loop's body or just follow the first loop).
•  » » » » » 2 years ago, # ^ |   0 right! thanks for the explanation!
 » 2 years ago, # |   0 How to solve D?
•  » » 2 years ago, # ^ |   0 I think simulating with std set is fine.
•  » » » 2 years ago, # ^ |   0 I was thinkin about it but 10^6 constraint drove such thoughts away from me.
•  » » » » 2 years ago, # ^ |   0 Well, time limit is 2s and it should pass if implemented correctly.
•  » » » » » 2 years ago, # ^ |   0 Hmm, maybe
•  » » » » 2 years ago, # ^ |   0 you can use vector
•  » » » 2 years ago, # ^ |   0 How so? Thought it would TLE
•  » » » 2 years ago, # ^ |   0 Can you please explain the solution?
•  » » » 2 years ago, # ^ |   0 You can think of like maintaining two sets. One 'to_be_deleted' and other is 'candidate_for_deletion' (whose adjacent is to be deleted from first set). Now each item can be deleted from first set at most once and each item can be inserted into second set at most once. So, maintaining amortized complexity O(nlogn). Log(n) part for set insertion or find.
•  » » 2 years ago, # ^ |   0 Simulate with std::list merging adjacent blocks, if of same color.
•  » » 2 years ago, # ^ | ← Rev. 2 →   +4 You can solve it in complexity O(n).Group consecutive same elements and make one array of integers. Than all elements in new array will decrease in one operation by two except first one and last ( they will decrease for one). You can go over all groups and see minimum amount of operation to make one element of array lower than 0. Decrease all elements for that amount of operations ( first and last will decrease for that value and other will become smaller for 2 x amount of operations ). After this move remove all groups smaller than 1 and merge some groups if they have same letters.At first view this looks as brute force, but actually this is O(n). In each iteration you will decrease each viewed element at least for one and total sum of that array will be exaxtly n.
 » 2 years ago, # |   +3 What was the hack for problem A?
•  » » 2 years ago, # ^ |   0 maybe ab bb types where answer should be ab and not abb.. so you have to check s1[i]
•  » » » 2 years ago, # ^ |   +3 Oh so that means that in my room, everyone was sharp and clever enough to avoid this mistake. :(
•  » » » » 2 years ago, # ^ |   0 same :(
 » 2 years ago, # |   +12 how to solve C?
•  » » 2 years ago, # ^ |   0 dp[i][j] -> examining the ith prefix how many ways we can ident so that the ith statement is idented j times.
•  » » » 2 years ago, # ^ |   0 can you please explain a bit more?
•  » » » » 2 years ago, # ^ | ← Rev. 2 →   +3 Denote the ith statement with ai, we wish to calculate dp[i][j]. Then there are two cases. If ai - 1 = f then we just started an identation so dp[i][j] = dp[i - 1][j - 1]. Else (so we can delete some identations from the previous statement). To reduce time complexity we have to use suffix sums and use iterative dp to fit in memory.
•  » » » » » 2 years ago, # ^ |   0 thanks a lot :)
•  » » » » » 2 years ago, # ^ |   +3 Or one can implement with recursive approach (who finds it easier) and pre call dp function in proper direction to avoid stack growth.
•  » » » » » 2 years ago, # ^ |   0 Can someone tell me the equation in place of this question mark, I don't know why its appearing this way in my end.Thanks.
 » 2 years ago, # |   0 how to solve D? greedy strategy or some smart simulation?!
 » 2 years ago, # |   +29 Is using Dilworths theorem and then finding max antichain using DP overkill for B?
•  » » 2 years ago, # ^ |   +2 NO.Another alternative: If you can't understand statement like me, just search samples in OEIS and try every pattern. Works after some WA.
•  » » 2 years ago, # ^ | ← Rev. 2 →   +3 Probably :) The series which I got(pretests passed) were, if n is even, the series is 1+2+3...n/2 + n/2 +...1 and if n is odd, 2*(1+2+3...n//2)+n//2+1
•  » » 2 years ago, # ^ |   +10 @rajat1603 that is the precise definition of overkill.
•  » » 2 years ago, # ^ |   0
 » 2 years ago, # |   +7 When will the editorials be published? And how to solve C? Seemed like something to do with catalan numbers.
•  » » 2 years ago, # ^ |   +16 Editorials are up at http://codeforces.com/blog/entry/56666
 » 2 years ago, # |   +11 How to solve F?
 » 2 years ago, # |   0 Ideas for C?
•  » » 2 years ago, # ^ |   0 I solved it using dp
•  » » » 2 years ago, # ^ | ← Rev. 2 →   0 I tried dp top-down and took TLE my states was command x identation :\
•  » » » 2 years ago, # ^ |   0 how did you use dp?
•  » » » » 2 years ago, # ^ |   0 I treated the case idt = 0 solve(command+1, ident+(v[commnand]=='f'?1:0)), v[command]=='s')and the case when the last command was s: for (i = idt : 0) solve(command+1, i+(v[command=='f?1:0)), v[command] =='s') and when wasnt: solve(command+1, ident+(v[command=='f'?1:0)), v[command] == 's')
•  » » » 2 years ago, # ^ |   0 please give the recursion formula.
•  » » » 2 years ago, # ^ | ← Rev. 4 →   0 My English isn't very good but i'll trylet dp[i][j] be number of ways if you use first i commands and end up at nesting level jif a[i] == fthen just dp[i + 1][j + 1] += dp[i][j]elsefrom dp[i][j] we can get to any state of dp[i + 1][0..j] you can calculate this if you use auxiliary array of prefix sumsans will be dp[n][0]and if you are currently at i == n — 1 you just do dp[i + 1][0] += dp[i][j]
•  » » 2 years ago, # ^ |   +1 dp(i, j) = number of ways to indent the first i lines such that the last line has indentation j.Runs in O(n^2)
•  » » 2 years ago, # ^ |   0 it seems like dp, but i didn't implemented due to time..
•  » » 2 years ago, # ^ |   0 Used dp with cumulative sum to avoid TLE
 » 2 years ago, # |   +8 Is the solution for B this:floor(((n+1) * (n+1)) / 4)It passed the pretests but I don't know about systests.
•  » » 2 years ago, # ^ |   +3 it passed
 » 2 years ago, # |   +3 I had idea for C. First every consecutive f and one s we call a block, for example fffs. So you find number of blocks and also size of every block, where size is number of f. Then dp[ i ] [ j ] = dp [ i + 1 ] [ j ] + dp[ i + 1 ] [ j + 1] + ... + dp[ i + 1 ] [ j + block_i_size ]. Anyone solved this way? If u didnt, u probably wont understand me :P
 » 2 years ago, # |   +4
 » 2 years ago, # |   +19 Is it just me or is E easier than B, C and D?
•  » » 2 years ago, # ^ |   0 i didin't know about C and D, but i'm sure that B is easier than E.
•  » » 2 years ago, # ^ |   0 Don't know about B but it's definitely easier than C and D
•  » » 2 years ago, # ^ |   +3 Don't know about E but B is harder than F.
•  » » 2 years ago, # ^ |   0 A
•  » » » 2 years ago, # ^ |   +1 disagree
•  » » 2 years ago, # ^ |   +6 don't know anything but everything was hard :P
 » 2 years ago, # |   0 Does anybody know some counter tests for my solution at C. I saw many people got WA at pretest 3. Why? My solution.Your text to link here...
 » 2 years ago, # |   +7 Recursive solution for problem BAt first think of all the segments that have left point at 0. There are total N segments that have this property. We can match every one of this segment [0, x] with a segment [x, N] and draw it in one layer. Thus, we need total N layers to draw all segments that start with 0 or ends with N. All of the remaining segments are defined by the points between 1 and N-1.So, we can write, f(N) = N + f(N-2) where, f(0) = 0, f(1) = 1
•  » » 2 years ago, # ^ |   0
 » 2 years ago, # |   +6 Is C solvable using top-down dp ?
•  » » 2 years ago, # ^ |   +3
•  » » » 2 years ago, # ^ |   0 I don't understand why he used this line :res -= solve(pos + 1 , nest);
 » 2 years ago, # |   0 Div2CWhat makes this solution fail?!33689625
•  » » 2 years ago, # ^ |   0 Try this testcase:5fffssIts answer should be = 4
 » 2 years ago, # |   0 Did anyone solve D by another method : making a right arrays which stores the logical next element and making a left array which stores the logical previous element in array and then performing logical deletion by changing the left and right array values. Eg. _ a a b b_ _ left[i] {-1 , 0 , 1 , 2} ........._ _ right[i]{ 1, 2, 3, 4}_ .................... after one operation , left[i] becomes {-1,X,X,0} and right[i] becomes {3,X,X,4} and so on (by proper implementation procedure taking case of indices etc) and then count total number of steps(again proper implementation required). If anyone solved like this , please provide your code .
•  » » 2 years ago, # ^ |   0 I was solving in similar fashion but I got TLE Here is the link
 » 2 years ago, # |   0 Isn't system testing too slow?
 » 2 years ago, # |   +11 Good fight between problem D and E today
 » 2 years ago, # |   0 B had 102 test cases!!
•  » » 2 years ago, # ^ |   0 1<=N<=100
 » 2 years ago, # |   +20 It's a fantastic round :)
•  » » 2 years ago, # ^ |   +3 Winner here Congrats
•  » » » 2 years ago, # ^ |   0 Thanks :D
 » 2 years ago, # |   0 Will the user ratings change according to this contest? If yes, when?
 » 2 years ago, # |   -12 shit contest made me gren
•  » » 2 years ago, # ^ |   0 shit happens!
 » 2 years ago, # |   +5 D and E were easier than C lol
•  » » 2 years ago, # ^ |   0 E was easier than C and D, but D was harder than C, idea is very tedious in my opinion
•  » » » 2 years ago, # ^ |   0 D is pretty strightforward solution from early lessons of data structures (linked list, nostalgia). But in C you need to think a bit.
 » 2 years ago, # |   +19 it was really a great round with really great problems and a fast editorial thank you for your efforts
 » 2 years ago, # |   0 Always have some submit Fail System Test make me a little bit annoyed,whatever that's the charm of codeforces i think :)
•  » » 2 years ago, # ^ |   +1 What???
 » 2 years ago, # |   0 how to solve division 2 C problem?