Hi!

On Thursday, July 13, 2017, at 15:05 UTC Codeforces Round #424 will be held. Some of the problems will be from VK Cup 2017 Finals, some are prepared by Codeforces team to complete the problemset.

There will be *six* problems in the second division, five as usual in the first, three of them shared. The problems of this round are proposed, prepared and tested by: send_nodes, akvasha, ilya_the_lamer, fcspartakm, Perforator, MikeMirzayanov, PavelKunyavskiy, qwerty787788, Belonogov, izban, tourist, vepifanov, AlexFetisov, winger, Errichto, Gassa, naagi, I_Remember_Olya_ashmelev, Endagorion, ifsmirnov, Arterm and me. Huge thanks to all who helped with the preparation!

**There will be prizes from VK social network in this round as well!** Namely, among participants solved five or more problems in second division, or two or more problems in first division, five are to be selected randomly. They will receive championship souvenirs. There is no country nor language restriction, everyone can win a prize. One don't have to have participated in VK Cup to receive the prize. Exact selection algorithm will be announced before the start of the round.

Good luck!

Congratulations to the winners!

Div. 1:

Div. 2:

The analysis is here.

The problems correspond to problems of VK Cup 2017 - Finals as follows:

- Problem 830C - Bamboo Partition — is problem 823C - Bamboo Partition, author is me;
- Problem 830D - Singer House — is problem 823E - Singer House, authors are send_nodes and me;
- Problem 830E - Perpetual Motion Machine — is problem 823F - Perpetual Motion Machine, authors are akvasha and ilya_the_lamer.

Congratulations to souvenir winners!

Eligible list place | Contest | Rank | Handle |
---|---|---|---|

65 | 830 | 65 | halin.george |

69 | 830 | 69 | Neil |

153 | 830 | 153 | BigBag |

265 | 830 | 266 | whczr |

320 | 830 | 323 | Rydberg |

I wonder if it is frowned upon to compete in a codeforces round during work? I guess we'll find out, I can't miss VK Finals!

Errichto is back!

By the way, the algorithm for choosing winners is the same as in the previous round. The winners of the previous round will be chosen with the use of the first place score in this div. 1 round!

codesend_nodes is involved? Damn, hope it won't be unrated :)

Hope, history will not repeat because in this contest, there are 22 problem setters and testers.

Upvote this comment if you want high rating!

educate yourself if you want high rating!

Proposed, prepared and tested by

22:3I used binary search to pass div1.E (have been accepted). but later, I found it was probably wrong. Can someone provide me with a data or prove it is right? thanks！ code goes here: http://codeforces.com/contest/827/submission/28488942

Sorry, the question i asked in the wrong place. The contest i mentioned above is div1 #423

Am I the only one who can't open any other user's submission page like submissions

No you're not, i also can't open.

I think after this round everything will be ok.

maybe it's just to prevent delay submission during the contest, which participant complaint for each contest lul

This contest is not listed for some reason at clist.by

Some reason is problem with codeforces api.

Can it be because the API is not working which in turn is to prevent us from seeing questions done by testers.

Third round by send_nodes .. hope that it won't end up unrated. xD

I'm sorry dude, but it is how cf works in community...

You get tones of downvotes if your rating's low...

You can't hold a contest because your rating's low...

There might be some issues if you hold a contest and your rating's low...

I don't have an idea how to improve my rating after years being on this website, Nor to be better in community. Hope someone help me in some new ways... . And something else, please think about it before starting downvote with millions of account(fake or real :()

if @tourist tested the problems then round will not have any issues(like the rounds 420 & 421). :3

I already participated two days ago in the VK contest. When I uploaded my solution the system showed that it passed the tests, but after the contest it said that it exceeded the time limit. Does it work always the way, that you don't see a time limit exeeding during the contest or was it due to the fact that I was an unrated participant?

Anyway, best luck and fun to all of you today :)

It was because you solution was not fast enough to pass the remaining system tests ! during contest only pretests are tested that's why it shows pretest passed ! hope you got it

During the contest, your code is tested on a subset of the final tests, called PRETESTS. After you have passed the pretests, you can lock your solution and then view other participants' codes and try to hack them. Others who have locked their solutions can view your code irrespective of whether or not you have locked your code. Once the coding phase is over, your solutions will be tested on the entire set of tests. This phase is called system testing.

It is the system testing, in the round, the judge runs only about 15 cases on your code, if your code passed you got PREtests passed. And after the contest, they run around another 100 test on your code and give you your final verdicts. You can also learn about hacking a solution.

:)

22 problem setter & tourist among them ... this contest must be super good.

Best of luck to all participants in both divisions, i'll try to read all problems this time ^^

Why does people downVote your comments without any reason (maybe even without reading your comment) ?

hope there will be no delay of 10 minutes.

People who code correct in their first attempt, how do you do it?

I know how to solve A, B, C, D, E but I can't code D in 25 minutes, even though it's so simple, and I've done similar problems so many times!

Btw is E too easy, or am I missing something?

Can you share your solution to E

You can simulate it using binary indexed tree and std :: set.

Calculate distance from i to i+1 on it's right and left. Then add answer from right and left for each i sequentially. Remember to decrease count of alive elements on left and right. You can use segment tree.

E is pretty easy. It's a standard fenwick tree problem. I'm ashamed I couldn't solve C though T_T

Could you point out the error in my solution? 28523227

Please check 248926's submissions. It doesn't look like only one person is participating.

Disqualified. However, it's better to write such messages in "ask a question" during a contest.

sorry, but is it possible to ask question if you are not registered?

I have no idea :( Can anybody check?

If somebody is giving a shit about multiple person participating from one account, why won't you disqualify North Korean accounts that participate frequently (some blackhorse or some RHS or something), they never get disqualified.

Maybe because nobody points that out? This account was banned just because it was top 1 and I opened his (their?) submissions just to find out what are the solutions and noticed that there are three distinct templates.

Well, it actually was pointed out many times.

Here is "nobody points that out":

1) http://codeforces.com/blog/entry/52653#comment-367697 + http://codeforces.com/contest/815/standings

2) http://codeforces.com/blog/entry/19331?#comment-242113 + http://codeforces.com/contest/559/standings (however this one is pretty old)

There are more cases like that, but pointing it out every time would take too much time :P

One more FYI (of course there would be much more) http://codeforces.com/blog/entry/43880

Sorry, but what is a blackhorse or an RHS?

edit: lol, just a question guys, no need to downvote... Doesn't seem wrong or offtopic for me.

black_horse2014 and RNS3, accounts used by multiple North Korean guys to regularly cheat

North korea is underrated :)

jealous !

Hi guys! Unfortunately CF API is turned off, so CF-Predictor couldn't obtain data from codeforces and make rating change prediction. API should be enabled back after this round, so I hope CF-Predictor will work fine:)

Can someone provide me hack testcase for my solution A div 1.

Hacked code : https://pastebin.com/0hYtTQcP

1 1 1 1 1

Yep, I realized it before 2-3 minutes. Actually I think they should mention it in the statement as possible situation, but anyway my mistake :) Congratz for hack :)

sort(a + 1, a + 1 + n);

sort(b + 1, b + 1 + n);

Rip rating :(

lel. you mean sort(b+1, b+1+k)? or is it not Office Keys problem?

Yep, I failed this problem because of typo.

I thought you forgot sorting at all like I did lol

I failed bin search because of l=1=)))

Hack Case for Div2 A ?

3

10 8 8

Answer is "NO".

wow,i have also hacked one solution by exactly same above Test Case . =D

there were many!! someone in my room has passesd pretests with this soluion http://codeforces.com/contest/831/submission/28522407 !!

2 1 2 or 2 2 1

How to solve C and D (Div 2)?

Eagerly waiting for the replies:) Can someone explain there idea please

D is very simple question of basic DP. sort all men and keys on the basis of their positions and then u have dp state as dp[men][key] = min(max(time taken to that men after picking that key , dp[men+1][key+1]) ,dp[men][key+1]). and after all recursive calls ...your final answer is dp[0][0].

can you please tell why the dp solution works only when you sort the arrays? not able to figure out how does that helps in finding out the optimal answer

if you don't sort the arrays than after allotting a key to a guy you have to iterate from starting among all the available keys thus your solution would be of O(n*k*k) but after sorting u can do it in O(n*k)...

Let see how it works, suppose you have two guys at x1 and x2 (x1<x2) and keys at k1 and k2 (k1<k2) and y be your final destination.. the total time you will need from keys to y will be same i.e abs(k1-y)+abs(k2-y) no matter which key you give to whom.. but if u assume all cases like k1<=y<=k2 ,y>k2 ,y<k1 then you can see in each case it is optimal to give k1 to guy at x1 and k2 to guy at x2.. you can generalize it...I can proof it generally but it is hard to write here ..try yourself to generalize it..

`dp[cur_p][cur_k] = min(solve(cur_p, cur_k + 1), max(abs(person[cur_p] - keys[cur_k]) + abs(p - keys[cur_k]),solve(cur_p + 1, cur_k + 1)));`

Enigma27 Can you explain why we're taking max inside min?

Edit: refer to complete solution here.Have you solved the egg drop puzzle, try solving that. You will get a very good intuition of why there is a max inside a min.

Thanks, got it. :)

I solved D using binary search + Maximum matching

Can you please elaborate .

Initially I thought the problem was an instance of Assignment Problem , but then realised that we need to minimise the maximum instead of the sum.

Do a binary search for the answer, for each value

`mid`

you need to construct the graph as following:if the man at index

`i`

can reach the key at index`j`

and then return from the key at index`j`

to the office, then you can add an edge between the man at`i`

and the key at`j`

now you just need to do a maximum matching on the resulting bipartite graph, and check if this matching is equal to the number of people.You mean to connect person

ito keyjif |ij| + |jp| ≤mid, and then run a maximum bipartite matching ?exactly.

Hi, can I ask you about time complexity of your code?

The matching works in O(n*k) so you just need to add log because of the Binary Search.

Which algorithm do you use for finding maximum bipartite matching? if you use hopcroft-karp algorithm your code's time complexity will be

O(sqrt(V) *E). Maximum of E in worst case isn*k. I think test cases was weak.For problem D:

I guess that the chosen key should be a consecutive n keys segment.. I don't know whether it will pass, but it seems pretty simple..

Yes, you are right. I solved it using the same method.

I solved D as follows: It's optimal to use a set of keys that are neighbours. Sort the keys, sort the people. Let the rightmost person go get the rightmost key, etc. Try every key as rightmost key.

Yup this is actually correct and by far the simplest solution of D.Can anyone please give me the proof of this solution and why this always works irrespective of the location of the office.

I think it can be done faster using trinary search over choices where leftmost key from set of keys that are neighbours is. For i-th person, if we will look how length of his path to key and then to office is changing while we are changing leftmost key from set of keys that are neighbours, that length should decrease while i-th key from chosen set of keys is on the left of office, and then increase when i-th key from chosen set of keys is on the right of office. So length of path of i-th person is increasing first and decreasing later. So time when all people get to office (which is maximum of lengths of paths over all persons) also is increasing first and decreasing later, so we can use trinary search. It should work in O(n*log(k)) (not including sorting). I didn't implemented that solution during contest because O(n*k) worked.

How to solve C ??? I am so ashamed I could not solve it whole contest :(

Lets say your path starts at 0. Create array for its values (adding a_i). Now make some path value to b_0.

Sorry But I do not get it :( Please explain in a bit detail !!

Lets make array k[n] k[0]=0; k[i]=k[i-1]+a[i]. When you know you will pass thru b[0]. So lets iterate j (0, n) and now you will have possible route c[i]=k[j]-b[0]+k[i] or smth. similar. Check if route is good. I did use some sets so it was O(kklogk)

You know b[0] must be after some judge i, so check for every position i, if this could work in linear time

Height of stupidity of mine !!! I was checking for every b,instead should have checked only for a single b !!!! That is too much stupidity :( Anyways Thanks yassin_ and Tutis

That is exactly what i was thinking( checking for every b) and i knew it was gonna TLE so i didn't code it cus it was obv k*n*n :C

let us get the prefix sum for all A's, now sort them. then get the value of all B's and sort them. now let us say the max value in B is x, now for x to be at position i, the initial value will be x — pref_sum[i]. then using this initial value generate the the array and check whether all numbers come in b.

I just got it accepted !!!! I was so close .. Due to C ,I did not try D and D was easier than C :( (Atleast DP solution was ... ) Anyways Thanks satylogin

very tight time limit for div1 D :(

Yeah. I got TLE on pretest 12 :(

You can preprocess it?

Do you think this was intended to compute 400 numbers and write them on the source code?

You are making it sound as it is some rocket science, but in fact it is very common technique

very common technique but was not intended in this problem, and there's no point let participants do it instead of just submitting their dp solution.

There's a k^2 log k solution though

What do you imply? if my O(n^3) sol should get TLE then all participants' O(n^3) sol should get TLE too. but that the same solution gets TLE with some people while gets AC with others is too unfair.

It's awkward that 400 initially ran under the time limit, but 399 failed in main tests later. Has anybody managed to make O(N^3) pass in Java?

(Yes, you can preprocess or you can use FFT to speed things up, but n<=400 suggests n^3 is fine.)

Can you please elaborate on it, send_nodes :^)

I am very curious how you change the DP to be k^2 log k

Normal dp is like dp(i,j) giving number of ways to choose j non-intersecting paths in a tree with height i. Slowest part of computing the DP is finding out the number of ways to get

xnon-intersecting paths from the left and right subtrees. It's important that you can multiply all the dp values for trees of height i-1 with itself in a polynomial mult. fashion to get these number of ways, and you can use these results for dp(i,p) for all p. So it's just k^2 log k with FFTWhat a weak set of pretests are there in A.

Verdict: Pretests passed. Should be

Noticed my mistake after a solution was blocked.

Pretests are so weak that my solution without sorting passed. And even wasn't hacked :( RIP rating

For Div 1A / Div 2D Not only pretests, I saw a wrong solution passing the system test.

It can be seen that for array b index will reach to n+k whereas b can have max index possible till k.

Link to Code

For D could you do DP with the states being the number of people that got to the office and the hashed state of the array of keys? That was the only solution I could think of in contest.

I used bs + max matching

I got TLE with optimized Kuhn matching

Same here, I need to use hopcroft-karp to pass time limit. Idk why

hopcroft-karp is sqrt(n)*m worst case, other is n * m

Yes, but shouldn't n*m pass time limit too? binary search O(log(1e10)) * n * m

m = n * k, number of edges

Ah I forgot about that. Thank you

Is this idea correct for div2 D? you binary search for the answer. for a certain value m, you call a function that returns true if the total number of keys such as the distant from a dude to the keys <= m, otherwise false? tried to implement it but didnt make it and i dunno if it's correct

I just did sort :D Use some interval of keys and map each key to people :D

So the best case is always the one where we're allocating n keys lying next to each other? How to prove that?

Its yasy to see what if a wants key B and b wants key A and a>b and A>B whay need to swap keys. Ok, no intersecting lines. Lets say we need a keys left to the office. if some key from a to the left is not used, you can simply shift every to the left of that key to one in the right of those and get (maybe) better result. Same with the right. So we just get some segment of size n around the office.

Thanks for the explanation. It's still not super obvious thing to me (I have to look over some different cases to check your first point for example) but it's much better than "You have to understand" part in official analysis :) Looks like I'm really not good with greedy tasks like this.

I think your approach is wrong. Try this test.

Notice that both keys are close to the first "dude" but the second "dude" is far away from keys and he needs to pick one of them.

what if we count the number of distinct keys?

EDIT: ok, i understand what i did wrong, thank you!

What do you mean by count the number of distinct keys. Notice that the problem you need to solve if you perform binary search is a maximum matching between keys and "dudes". But the graph is not random enough so you can perform a greedy. For each of the "dudes" you have an interval where he can look for the key. You need to cover all the intervals with keys inside it. It is a classical greedy problem. The overall complexity will be O(n * m * log(L) )

Probably that solution fits in time, but there is a dynamic programming approach where each state dp[i][j] represent the best solution for the first i "dudes" using the first j keys. (This works after sorting the "dudes" and the keys). The overall complexity of this solution is O(n * m) since each state can be computed in O(1) if all previous states are already computed.

can you please tell why the dp solution works only when you sort the arrays? not able to figure out how does that helps in finding out the optimal answer

Lets say there are any two person (

aandb) and two keys (candd) and we want to link this two persons with this two keys. Denotep_{i}andk_{j}as the positions of personiand keyjrespectively. Ifp_{a}<p_{b}andk_{c}<k_{d}the following inequality holds:p_{a}-k_{c}| + |p_{b}-k_{d}| ≤ |p_{a}-k_{d}| + |p_{b}-k_{c}|So person

awill take keycand personbwill take keyb. Extending this argument to the whole group, we claim that if personiis linked with keyjall persons beforeineed to be linked with keys beforej, and now you may apply dynamic programming. 28508775let's say people are at =

pa=10 &pb=20 and the keys are atka=50kb=60kc=70. Now according dp solution if i decide to takekbforpa, i must choosekcforpb(or any other key afterkb). But here choosingkaforpbshould be optimal, isn't it ?Answer 1996?

What is pretest 5 div2e?

something similar to

4

1 3 2 3

I also got wa on that.My solution failed because i didn't treat equal numbers correctly,maybe you have same mistake.

Am I the only one who tried to solve Div2D using greedy approach?(sort each man by max distance from p and select best possible key)

I also did that greedy approach

So, after contests, can someone provide mapping between those problems and VK Cup ones?

Could D div1 be solved computing recursively the number of paths and the number of pairs of paths for each height? :((

No. Informally, for pairs of paths you need triples of paths. Consider following situation: you want to count pairs of non-intersecting paths where both are in the same subtree except one of them touches root and goes down again (to the same subtree). If root is removed, this construction becomes a triple of non-intersecting paths.

You're right, thanks, I got lost in contest hype + too many cases not well ordered. Thanks

why this submission of DIV2A didn't fail test '1 2'

shouldn't condition

`w[r] < w[r-1]`

be checked before 'r > 0' and throw ArrayOutOfBounds?C++ is crazy.

Hack Cases for div2 A 3

10 8 8 output — NO

4

1 2 3 4 output YES

7

1 2 3 4 3 3 1 output : NO

Is WA in a sample which is not a pretest 1 costs WA ?!!!!

KAN

it's like this is the slowest system test ever |:

Can someone describe the solution for D?

Consider the following (more general) problem:

For every T from 1 to K and for every P from 1 to K, calculate how many different sets of P disjoint paths there are in a tree of size T.It turns out that you can calculate these values easily using answers for smaller trees.

dp[i][j] means number of sets of j disjoint paths in a tree of height i

The final answer is dp[n][1], now to compute dp[i][j] you have to consider many cases:

1- select total of j-1 paths from the left and right subtrees and let the root be the j-th path

2- select total of j paths from the left and right subtrees and either let the root be at start/end of some of the paths or let the root be not involved in any path

3- select total of j+1 paths from the left and right subtrees and merge two paths into one path using the root node as a node between those two paths

I can't believe I failed to pass div2 A. This is quite embarrassing

Div1 A could be solved in

`O((n + k)*logp)`

:We can run binary search on answer. For fixed time we can for every person define the reachable segment where he can come and then return to the office. Then we need check if we can assign different keys for each segment. It can be done greedy in O(n).

Accepted solution

Can you please explain the greedy part a bit more in detail. I tried a similar method but then messed up in the greedy to submit a stupid code.

Suppose I am checking whether time 'x' is possible, I just concluded "true" if there are "n" distinct keys which can be collected in 'x' time and "n" people can reach office using come key in 'x' time. "n" is the number of people.

Thanks in advance :)

We can sort keys and segments by left end, then iterate over segments and assign to current segment leftmost unassigned key that lies inside it. If there isn't such key, chosen time is not enough.

Also we even don't need to sort segments every time. We can just sort people at the beginning, because all segments are linearly expand while time changes.

Oh yea.. got it.. Thanks :)

For God Sake when you wanna add pretests, add them strong not so easy and stupid, for Div.2 D, I wrote:

instead of:

And still I got it pretests passed :\ I can't believe it

Can anybody please tell me what's wrong with my submission on E problem? Getting WA on 5th pretest. 28522539

UPD: Nevermind, stupid mistake

How to solve Div 1 C ?

Basically problem is asking to maximize

dsuch that:We can do some algebra to get:

The right hand side doesn't depend on

d, so basically we can consider it some constantCand just try to find the maximumdsuch that .Now, if this were monotonic, we could find

deasily using binary search. Unfortunately, it's not, because is decreasing whiledis increasing.The trick here is that there aren't many distinct values of . In fact, for any such

a_{i}there are only such distinct values. Anyway all the possible distinct values are given byiand for all .So what we can do is get all the possible distinct values of and also the bounds

landrsuch thatl≤d≤rgives that specific value. Now, intersect all these ranges. (It seems like a lot, but actually it's only about different ranges.) The new ranges will be [l,r] for which all are constant.Now, for each range, we can now binary search

dwithin the range; since all are constant, we know will be monotonically increasing. Actually we don't even need binary search at this point, but at least binary search requires less thinking. (Make sure to preprocess all the sums for each range before doing the binary search.)The runtime should be or something along these lines.

If it helps, here's my code. 28521138

Hi! Thanks for provided analysis of this problem. I looked into you code and I have a question about its complexity.

It looks like your solution is actually.

You have ranges (I'm pretty sure this value is much smaller after perfoming

unique, but I can't see obvious reasons why it should be ). After you compute just iterating through initial array for every range. This is the slowest part of your algorithm and it takes .You're right; thanks for pointing this out! My code specifically is actually with very low constant factor, so it still passes.

But actually there is a way to knock out the extra

nfactor make it run in around , with some log factors, using some clever bookkeeping.First we will need to find all the ranges with all constant like before. Now we initialize all the sums to zero, then we can do the +

v, -vprefix sum trick; for eacha_{i}we find all the possible values of and the ranges [l,r] giving each of these values. For each range, we can then just add toland to the one afterrin the sum array. We can find locations of theselandrin the sum array using binary search.Afterwards, we can cumulate all the values, it will give the same sum array but in with some log factors, instead of .

Actually, it can be shown that your solution (and my solution) runs in time (

Ais the maximum of {a_{i}}_{i}). That is, the number of distinct values is instead of .To see that, for a number

x, we can count the number of values that are less than or equal toxand greater thanxseparately. The first part is obviouslyO(x) size. And the second part is size because for each inputa_{i}, in order to , should be satisfied.Then we can set to minimize the quantity.

Yeah, I think the complexity of the code should be .

There is some way to optimize this to , though; you don't need to recalculate the whole stuff, before performing

unique, every range corresponds to a single changing, so the sum can be updated inO(1).I mistook the starting time and couldn't participate, but D and E are very interesting problems! Thank you for the writer!

Here is my solution for E.(It may contain mistakes, since I haven't tested it yet.)

-If there are circle, assign 1 for all node which is contained in circle.

-If there is a vertex v s.t. deg(v)>=4, assign 2 for the center and 1 for the neighbor.

-If there is a connected component which contains 2 vertices u,v s.t. deg(u),deg(v)>=3, assign 2 on the u-v path and 1 for the 4 neighbor of u and v.

-If there are only paths, the answer is no.

-Then, there is only one vertex v s.t. deg(v)=3 for each component. Let's denote the tree as a tuple of integer, s.t. each integer is the length of path which go out from v.

-If it is (2,2,2), (1,3,3) or (1,2,5) or more, we can construct the tree and otherwise not, since we can prove that in the optimal solution, the value on each path will be arithmetic progression.

I think your solution is correct.

The connected graphs for which the problem doesn't hold are known as Coxeter-Dynkin diagrams.

I didn't have time to finish implementing this though :(

I implemented it. But I forgot there could be several connected components :(

And do you know is this just a coincidence or there is some meaning of that?

Well, if the variables are

x_{1},x_{2}, ...x_{n}, then the condition is equivalent to the matrix being positive definite, which is one definition of the Dynkin diagram. (We takec_{ij}to be if there is an edge betweeni,j, and 0 otherwise.)However, DEGwer's solution is essentially the same method that classifies Dynkin diagrams.

Proof of last sentence:

Let us name the value on the path, from leaf to the v, x_1, x_1+x_2, x_1+x_2+x_3, ...,x_1+...x_n=value(v). Then the sum of score of the edges and vertices on this path is -sum_{i<j}(x_ix_j) = -(value(v)-sum(x_i^2))/2, then the optimal value is -(1-1/n)value(v)/2. It just means (2,2,2), (1,3,3), (1,2,5) or more is YES and otherwise NO.

akvasha and me, as the authors of Div1E problem, are pleased to hear this from you. :)

Moreover, there is strict criterion whether 3-tuple (a, b, c) is good. It will be stated in the editorial.

Presumably something like: Let f(n-1) = 1/2 * (1-1/n). Then the tuple is good iff f(a)+f(b)+f(c) >= 1?

Edit 2: Equivalently, in more readable form, 1/(a+1) + 1/(b+1) + 1/(c+1) <= 1

Yes, you are right. The proof will be in the editorial.

Regarding to last part. I know that for a particular tree (even any graph) we can check if it is ok by checking if corresponding matrix is positive-definite using Sylvester's theorem, and for a case of (1, 1, k) it can be easily proven manually, so that's some way to prove whole correctness. However I am not fine with your "otherwise not, since we can prove that in the optimal solution, the value on each path will be arithmetic progression." argument. The thing is, "optimal solution" is kinda useless notion here, it is either -infty or 0 and in second case you do not know if 0 is achieved with only zero weights. I also noted during contest that if some value is different than half of sum of its neighbours then we can optimize result by changing only that value, but for vast majority of cases it is not possible to achieve a stable set of values. How your argument goes for trees (2,2,1) and (2,2,3)? You can't achieve local optimality in neither of them, but one is fine other one is doesn't.

Ok, I got it, center value has to be something and then rest is determined and we directly check if such assignment is ok, no need to explain xd.

How to solve div2 C?

Will we be able to view our submissions page after this contest?

Yes

That moment when you are unable to solve Div1 C and see this solution :P

why CF-predictor dosen't work ?

It's because of the API

When will the ratings be updated?

Dude have some patience

Codeforces api is down

God _/_

http://codeforces.com/contest/831/submission/28526420

Why does this code time out? I have seen multiple

N^{2}*logNsolutions that passed for this problem.I timed out on the same test :(

http://codeforces.com/contest/831/submission/28515589

28522257

28522581

28523125

Can someone help me why some submissions for Div2 C TLE on pretest 11 ?

With O(NK) (in the latest submission) I was not expecting it to TLE :/

Please ignore if the solution is correct or wrong I am just concerned with the TLE for the moment

Feeling bad I wasn't able to solve it, RIP ratings :(

did you checked the condition "If Polycarp messes something up and there is no options, print "0" (without quotes)."

The solution is supposed to terminate correct or not, I can't see anything falling into infinite loop in my code, is there?

It's

O(n*k*log^{2}k). map and set are notO(1).By the third submission I switched to unordered_map and unordered_set which should reduce the complexity to O(NK)

But really an anti-hash test in pretests ?

This is high time now.Somebody please help. Earlier in one codeforces contest ,I solved a problem using unordered map ,it gave TLE,then I used map on that question it gave accepted. Now in today's contest I used map in place of unordered map in problem C and it gave TLE, & when I used unoredered map ,it gave accepted. Somebody please tell me should Unordered map worst case be considered O(n) or O(1) in competitive contests and what should be considered while calculating time complexity at interview round of any company.

Div2 C Accepted by unodered map code

Hi @oo7rm.Can you explain your idea ,If you don't mind. Thank You!

let x be the initial score , for the value x to be the valid initial score x + a[i] must match all the b[i]'s . Now x+a[i] can be equal to some b[i] , x+a[i]+a[i+1]..a[j] must be equal to some other let us say b[j],so

so i am subtracting the values one by one from every b[i] and incrementing their count in a map. At last i iterate through the map and all the values >=n will be my ans. I have used other map to ensure that the all the x found out in the inner loop are counted only once.

With Fast I/O and unodered map you may get accepted. Hope it's clear.

Thank you so much for sparing your time .I understood it well

I implemented the same idea but getting TLE Once can you check it plz http://codeforces.com/contest/831/submission/28539653

In most programming contests, you can treat them as O(1) with good probability (*usually* setters don't try to break hashes, since it's generally not easy to break a hash without knowing what it is). However, in codeforces, in the solution, you effectively make your hash public, so it is possible (especially if you use the stl hash) that someone will specifically target the hash to give its worst O(n) performance. Hence, on codeforces, it's usually better to use map rather than unordered_map.

How is N^2logN getting TLE in div 2 C? Or did I miss something? http://codeforces.com/contest/831/submission/28516440

I think your constant value is high! I solved in (n^2)logn as well, to be precise mine was O(n(n + nlogn)) and coupled with fast input and output,I JUST managed to pass the system test(1500 ms).. So I guess your constant value is high and also,why did you not use cin.tie(0)?I thought it was important for fast input output,correct me if I am wrong please,still learning..

Awesome rounds! Thanks! The scoring is a bit screwed but for Div2 but still a good round

Before systest: I'm quite worried about my C. There may be some case that I didn't handle. I'm 100% sure that A and B will pass though.

After systest: C passed, A failed...

Btw, when will the winner of the prizes be announced?

You can deduce it yourself, the code's given below. Thing is, the seed is defined as the maximal score for a contestant on the next Div1. There's no Div1 posted on the contest notice-board thingy, so it'll probably take a week. The only people who may get a prize are Div1 with >= 2 tasks solved, and Div2 with >= 5 tasks solved.

Friendly Div2C,my friend.

Solution to Div1 B using just multiset 28517177.

Shouldn't it give TLE? Hmmmm.

It should. 99999 cards with 2 and one card with one in the middle is a hack.

When will the winners of the prizes be announced and how you'll pick them randomaly ??

28521929

28520986

This looks like cheating to me(If I am wrong, sorry). Because I think nobody will use variable names like nnnn and aa, with unnecessary splay tree template.

Sadly, with this kind of solution it's kind of hard to tell. The actual code you submit is about 3 lines long, and involves an exhaustive list. Additionally, he did have an earlier "skipped" submission without the splay tree code and strange variable names (probably because it was the flagged as equal to someone else's code). My personal stand is that there is totally not enough evidence to flag him as a cheater here.

1) What's wrong with the first submission? I don't understand.

2) I suspect that the code is skipped because he resubmitted instead. Also, the strange naming of nnnn is from the compilation error that he got.

So he just add a few n to solve the issue, I would do that too. The thing I don't understand is why he resubmit with a unnecessary splay tree template...

How to solve Div2E??I've already seen that it has a solution using fenwick tree..but could anyone elaborate??Thanks in advance

Use set for every card weight and use BIT to store how many cards is left. iterate thru cards sets from lowest to highest weight and for every set go to lower_bound of current index, if it==end it=set.begin() add the answer from BIT from current to new. Update the BIT with -1 at *it and charge curr=new. Check my solution: 28522814

I'm so sad :(

By the way, it looks like some top-placed users from div.2 are also cheaters. So we are going to remove them and recalculate ratings, it will take some time.

The algorithm of announcing souvenirs' winners is posted, but it will take some time for me to implement (the seed for the current contest it not known yet, but the seed for round #432 should be ok right now).

Why you didn't update all the information about the new standing !!

My graph and contest page show that I'm the 4th place , but actually I'm the second :\ !!

Thanks, i got +3 :D Still div2 :(

Could anyone explain how to solve Div1.C ? thanks

http://codeforces.com/blog/entry/53267?#comment-373142

Can any one give a DP solution for Div2 D.Please keep it sweet and simple..Thanks.

28516949

http://codeforces.com/contest/831/submission/28516949

can you tell me about your dp state

If you are interested in clean top-bottom DP implementation,you may check mine.(http://codeforces.com/contest/831/submission/28530870)

http://codeforces.com/blog/entry/53267?#comment-373035

Finally done man..Thanks all for your support..

When will the list of winners of championship souvenirs be published ?

Can anyone explain how to solve DIV-2 E?

As for me, the easiest way to solve it is Implicit Treap (but I saw solutions with other data structures)

We can use Implicit Treap as an array in which we can cut some part, join parts and find index of minimum (all of this in

O(logn) time)So we can do this while Treap is not empty:

Find index of minimum (name it

id)ans=ans+idFirst

id- 1 elements place to the backErase element

idAnswer will be in

ansTime complexity is

O(nlogn) because our Treap will be empty afterniterations (on each iteration we erase only one element)can you give some tutorial/link on Implicit Treap

https://e-maxx-eng.appspot.com/data_structures/treap.html

Let's see what is actually happening — Each time,the array is

rotatedto the first smallest no and then,this no is removed.1) To keep a track of the rotation ,we only need the beginning position.

2) Keep an array of sets(

set<int>val[size]) to store the positions of each number in a sorted manner and erase this position once the no is removed.3) Sort the array.In the ith-iteration, look for a[i] in the rotated array.

4) Let beginning position ->

l, position of a[i] is .7) At last,update the beginning position to r.(or r+1) Complexity — O(

nlogn)Link to my solution : http://codeforces.com/contest/831/submission/28528292

Nice Solution :)

Alternative solution (runs in linear time since bucket sort is possible):

Consider the problem in the following light: We don't cycle the cards. We simply look from top to bottom and remove each minimum card. Then we sum up the round number in which each card was removed. We may track the round each card was removed by iterating through values of a_i in increasing order. Summing up across all cards, we may get the answer.

Example: 3, 2, 3, 1, 2

Firstly, we remove the '1'. Then consider the 2 '2's. The last '2' to be removed will be the one in position 2. A few details later, we get that the numbers are removed in rounds:

?, 2, ?, 1, 1

By considering the '3's, we will fill the array as:

3, 2, 2, 1, 1 for a total of 9.

Edit: http://codeforces.com/contest/830/submission/28544566

My solution involving BIT uses same amount of time :D Because we are using BIT for every number O(1) times it is about O(Nlog*N), but i don't know what exactly what logarithmic factor it has. 28545844

edit: btw, my friend used balanced binary search tree to get its subtrees size's :D.

I wasn't trying to say my solution was better. It just avoids Fenwick and may be conceptually simpler/interesting to some people.

Besides, it's pretty hard to tell O(N) from O(N lg N) in practice, especially with relatively large input. I believe the time mainly comes from reading input, since that generally has high constant.

Did anyone solve DIV2 C using Dynamic Programming?

I searched a lot but didn't found any.

Mere mortals are still not able to view VK Finals contest.

Editorial is waiting for winter to come.

Winter is coming and so is the editorial.

And the souvenir winners are determined (

seed= 3954,length= 394).Congratulations!

Thanks!

It's a nice surprise after 3 weeks :)

Thanks!Wow,I'm really excited to become the luckydog and looking forward to the special souvenir!

So where's the souvenir?It has been 2 months but I haven't heard of anything about it.Am I ignored? :D

Just can't believe that I haven't heard of anything about the souvenir till now.I think you must have forgotten this.

Actually I remind persons in due every few weeks about that, it seems that the souvenirs are stuck somewhere between VK and Codeforces. I think we will manage to resolve this problem eventually.