By KAN, 3 years ago, translation, ,

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, 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:

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

• +235

 » 3 years ago, # |   +29 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!
 » 3 years ago, # |   +29 Errichto is back!
 » 3 years ago, # |   +56 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! List all participants from div. 1 who solved at least two problems from top to bottom of the standings, ties broken by the time of last AC. List all participants from div. 2 who solved at least five problems from top to bottom of the standings, ties broken by the time of last AC. Append the second list to the back of the first list. Use the following code to generate the indices of the winners in the resulting list. The seed is the score of first place in the next div. 1 contest. The length is the length of the list. code#include "testlib.h" #include using namespace std; int main() { rnd.setSeed(); set winners; while (winners.size() < 5) winners.insert(rnd.next(1, )); for (auto winner: winners) cout << winner << " "; cout << endl; return 0; } 
 » 3 years ago, # |   -112 send_nodes is involved? Damn, hope it won't be unrated :)
•  » » 3 years ago, # ^ |   -17 Hope, history will not repeat because in this contest, there are 22 problem setters and testers.
 » 3 years ago, # |   -76 Upvote this comment if you want high rating!
•  » » 3 years ago, # ^ |   -18 educate yourself if you want high rating!
 » 3 years ago, # |   -15 Proposed, prepared and tested by 22 :3
 » 3 years ago, # | ← Rev. 2 →   +2 I 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/28488942Sorry, the question i asked in the wrong place. The contest i mentioned above is div1 #423
 » 3 years ago, # | ← Rev. 3 →   +4 Am I the only one who can't open any other user's submission page like submissions
•  » » 3 years ago, # ^ |   0 No you're not, i also can't open.
•  » » 3 years ago, # ^ |   0 I think after this round everything will be ok.
•  » » 3 years ago, # ^ |   0 maybe it's just to prevent delay submission during the contest, which participant complaint for each contest lul
 » 3 years ago, # |   +15 This contest is not listed for some reason at clist.by
•  » » 3 years ago, # ^ |   +9 Some reason is problem with codeforces api.
•  » » 3 years ago, # ^ |   +2 Can it be because the API is not working which in turn is to prevent us from seeing questions done by testers.
 » 3 years ago, # | ← Rev. 2 →   -40 Third round by send_nodes .. hope that it won't end up unrated. xD
•  » » 3 years ago, # ^ |   +7 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 :()
 » 3 years ago, # |   +11 if @tourist tested the problems then round will not have any issues(like the rounds 420 & 421). :3
 » 3 years ago, # |   +2 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 :)
•  » » 3 years ago, # ^ |   +1 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
•  » » 3 years ago, # ^ |   +2 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.
•  » » 3 years ago, # ^ | ← Rev. 2 →   +11 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.
•  » » » 3 years ago, # ^ |   0 :)
 » 3 years ago, # |   -19 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 ^^
•  » » 3 years ago, # ^ |   -24 Why does people downVote your comments without any reason (maybe even without reading your comment) ?
 » 3 years ago, # |   -9 hope there will be no delay of 10 minutes.
 » 3 years ago, # |   -22 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?
•  » » 3 years ago, # ^ |   0 Can you share your solution to E
•  » » » 3 years ago, # ^ |   0 You can simulate it using binary indexed tree and std :: set.
•  » » » 3 years ago, # ^ |   0 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.
•  » » 3 years ago, # ^ |   +6 E is pretty easy. It's a standard fenwick tree problem. I'm ashamed I couldn't solve C though T_T
•  » » » 3 years ago, # ^ |   0 Could you point out the error in my solution? 28523227
 » 3 years ago, # |   +67 Please check OlRed2017's submissions. It doesn't look like only one person is participating.
•  » » 3 years ago, # ^ |   +42 Disqualified. However, it's better to write such messages in "ask a question" during a contest.
•  » » » 3 years ago, # ^ |   +8 sorry, but is it possible to ask question if you are not registered?
•  » » » » 3 years ago, # ^ |   +8 I have no idea :( Can anybody check?
•  » » » 3 years ago, # ^ |   +18 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.
•  » » » » 3 years ago, # ^ |   +10 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.
•  » » » » » 3 years ago, # ^ |   +8 Well, it actually was pointed out many times.
•  » » » » » 3 years ago, # ^ |   +1 Here is "nobody points that out":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
•  » » » » » 3 years ago, # ^ |   +8 One more FYI (of course there would be much more) http://codeforces.com/blog/entry/43880
•  » » » » 3 years ago, # ^ |   +61
•  » » » » 3 years ago, # ^ | ← Rev. 3 →   +8 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.
•  » » » » » 3 years ago, # ^ |   +8 black_horse2014 and RNS_RMH, accounts used by multiple North Korean guys to regularly cheat
•  » » » » » » 3 years ago, # ^ |   +22 North korea is underrated :)
•  » » 3 years ago, # ^ |   -25 jealous !
 » 3 years ago, # |   +52 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:)
 » 3 years ago, # |   0 Can someone provide me hack testcase for my solution A div 1.Hacked code : https://pastebin.com/0hYtTQcP
•  » » 3 years ago, # ^ |   0 1 1 1 1 1
•  » » » 3 years ago, # ^ |   0 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 :)
 » 3 years ago, # |   +66 sort(a + 1, a + 1 + n); sort(b + 1, b + 1 + n); Rip rating :(
•  » » 3 years ago, # ^ |   0 lel. you mean sort(b+1, b+1+k)? or is it not Office Keys problem?
•  » » » 3 years ago, # ^ |   0 Yep, I failed this problem because of typo.
•  » » » » 3 years ago, # ^ |   0 I thought you forgot sorting at all like I did lol
•  » » 3 years ago, # ^ |   0 I failed bin search because of l=1=)))
 » 3 years ago, # |   +1 Hack Case for Div2 A ?
•  » » 3 years ago, # ^ |   +3 3 10 8 8 Answer is "NO".
•  » » » 3 years ago, # ^ |   0 wow,i have also hacked one solution by exactly same above Test Case . =D
•  » » 3 years ago, # ^ |   +1 there were many!! someone in my room has passesd pretests with this soluion http://codeforces.com/contest/831/submission/28522407 !!
•  » » 3 years ago, # ^ |   0 2 1 2 or 2 2 1
 » 3 years ago, # |   +8 How to solve C and D (Div 2)?
•  » » 3 years ago, # ^ | ← Rev. 2 →   +1 Eagerly waiting for the replies:) Can someone explain there idea please
•  » » 3 years ago, # ^ | ← Rev. 4 →   0 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].
•  » » » 3 years ago, # ^ |   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
•  » » » » 3 years ago, # ^ |   +4 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 (x1k2 ,y
•  » » 3 years ago, # ^ |   0 I solved D using binary search + Maximum matching
•  » » » 3 years ago, # ^ |   0 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.
•  » » » » 3 years ago, # ^ |   -7 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.
•  » » » » » 3 years ago, # ^ |   0 You mean to connect person i to key j if |ij| + |jp| ≤ mid , and then run a maximum bipartite matching ?
•  » » » » » » 3 years ago, # ^ |   0 exactly.
•  » » » 3 years ago, # ^ |   +3 Hi, can I ask you about time complexity of your code?
•  » » » » 3 years ago, # ^ |   0 The matching works in O(n*k) so you just need to add log because of the Binary Search.
•  » » » » » 3 years ago, # ^ |   0 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 is n * k. I think test cases was weak.
•  » » 3 years ago, # ^ | ← Rev. 2 →   +4 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..
•  » » » 3 years ago, # ^ |   0 Yes, you are right. I solved it using the same method.
•  » » 3 years ago, # ^ |   +4 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.
•  » » » 3 years ago, # ^ |   0 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.
•  » » » 3 years ago, # ^ |   0 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.
 » 3 years ago, # |   +9 How to solve C ??? I am so ashamed I could not solve it whole contest :(
•  » » 3 years ago, # ^ |   0 Lets say your path starts at 0. Create array for its values (adding a_i). Now make some path value to b_0.
•  » » » 3 years ago, # ^ |   0 Sorry But I do not get it :( Please explain in a bit detail !!
•  » » » » 3 years ago, # ^ |   0 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)
•  » » 3 years ago, # ^ |   0 You know b[0] must be after some judge i, so check for every position i, if this could work in linear time
•  » » » 3 years ago, # ^ |   +7 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 tautsjasiunsas
•  » » » » 3 years ago, # ^ |   0 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
•  » » 3 years ago, # ^ |   +1 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.
•  » » » 3 years ago, # ^ |   +6 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
 » 3 years ago, # |   +14 very tight time limit for div1 D :(
•  » » 3 years ago, # ^ |   -10 Yeah. I got TLE on pretest 12 :(
•  » » 3 years ago, # ^ |   +10 You can preprocess it?
•  » » » 3 years ago, # ^ |   -9 Do you think this was intended to compute 400 numbers and write them on the source code?
•  » » » » 3 years ago, # ^ |   -13 You are making it sound as it is some rocket science, but in fact it is very common technique
•  » » » » » 3 years ago, # ^ |   +5 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.
•  » » 3 years ago, # ^ |   -10 There's a k^2 log k solution though
•  » » » 3 years ago, # ^ |   +3 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.
•  » » » » 3 years ago, # ^ |   0 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.)
•  » » » 3 years ago, # ^ |   0 Can you please elaborate on it, send_nodes :^)I am very curious how you change the DP to be k^2 log k
•  » » » » 3 years ago, # ^ | ← Rev. 2 →   0 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 x non-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 FFT
 » 3 years ago, # | ← Rev. 5 →   +9 What a weak set of pretests are there in A. for (int j = 0; j <= k - n; j++) { int t = 0; for (int i = 0; i < n; i++) _max(t, abs(b[j] - p) + abs(a[i] - b[j])); _min(res, t); } Verdict: Pretests passed. Should be abs(b[j + i] - p) + abs(a[i] - b[j + i]). Noticed my mistake after a solution was blocked.
•  » » 3 years ago, # ^ |   +8 Pretests are so weak that my solution without sorting passed. And even wasn't hacked :( RIP rating
•  » » 3 years ago, # ^ |   +5 For Div 1A / Div 2D Not only pretests, I saw a wrong solution passing the system test.  ll res=INT_MAX; sort(a,a+n); sort(b,b+k); for(int i=0;i
 » 3 years ago, # |   0 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.
•  » » 3 years ago, # ^ |   0 I used bs + max matching
•  » » » 3 years ago, # ^ | ← Rev. 3 →   0 I got TLE with optimized Kuhn matching
•  » » » » 3 years ago, # ^ |   +3 Same here, I need to use hopcroft-karp to pass time limit. Idk why
•  » » » » » 3 years ago, # ^ |   0 hopcroft-karp is sqrt(n)*m worst case, other is n * m
•  » » » » » » 3 years ago, # ^ |   +3 Yes, but shouldn't n*m pass time limit too? binary search O(log(1e10)) * n * m
•  » » » » » » » 3 years ago, # ^ |   +1 m = n * k, number of edges
•  » » » » » » » » 3 years ago, # ^ |   0 Ah I forgot about that. Thank you
 » 3 years ago, # |   0 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
•  » » 3 years ago, # ^ |   0 I just did sort :D Use some interval of keys and map each key to people :D
•  » » » 3 years ago, # ^ |   0 So the best case is always the one where we're allocating n keys lying next to each other? How to prove that?
•  » » » » 3 years ago, # ^ |   +3 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.
•  » » » » » 3 years ago, # ^ |   0 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.
•  » » 3 years ago, # ^ | ← Rev. 2 →   0 I think your approach is wrong. Try this test. 2 2 1000 1 1000 1 2 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.
•  » » » 3 years ago, # ^ | ← Rev. 2 →   0 what if we count the number of distinct keys? EDIT: ok, i understand what i did wrong, thank you!
•  » » » » 3 years ago, # ^ |   +4 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.
•  » » » » » 3 years ago, # ^ |   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
•  » » » » » » 3 years ago, # ^ |   0 Lets say there are any two person (a and b) and two keys (c and d) and we want to link this two persons with this two keys. Denote pi and kj as the positions of person i and key j respectively. If pa < pb and kc < kd the following inequality holds: |pa - kc| + |pb - kd| ≤ |pa - kd| + |pb - kc|So person a will take key c and person b will take key b. Extending this argument to the whole group, we claim that if person i is linked with key j all persons before i need to be linked with keys before j, and now you may apply dynamic programming. 28508775
•  » » » » » » » 3 years ago, # ^ | ← Rev. 2 →   0 let's say people are at = pa=10 & pb=20 and the keys are at ka=50 kb=60 kc=70. Now according dp solution if i decide to take kb for pa, i must choose kc for pb(or any other key after kb). But here choosing ka for pb should be optimal, isn't it ?
•  » » » 3 years ago, # ^ |   +1 Answer 1996?
 » 3 years ago, # |   +3 What is pretest 5 div2e?
•  » » 3 years ago, # ^ | ← Rev. 2 →   +5 something similar to41 3 2 3
•  » » 3 years ago, # ^ |   0 I also got wa on that.My solution failed because i didn't treat equal numbers correctly,maybe you have same mistake.
 » 3 years ago, # | ← Rev. 2 →   +6 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)
•  » » 3 years ago, # ^ |   0 I also did that greedy approach
 » 3 years ago, # |   0 So, after contests, can someone provide mapping between those problems and VK Cup ones?
 » 3 years ago, # |   0 Could D div1 be solved computing recursively the number of paths and the number of pairs of paths for each height? :((
•  » » 3 years ago, # ^ | ← Rev. 2 →   +8 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.
•  » » » 3 years ago, # ^ |   0 You're right, thanks, I got lost in contest hype + too many cases not well ordered. Thanks
 » 3 years ago, # |   0 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?
•  » » 3 years ago, # ^ |   +14 C++ is crazy.
 » 3 years ago, # | ← Rev. 3 →   0 Hack Cases for div2 A 310 8 8 output — NO41 2 3 4 output YES71 2 3 4 3 3 1 output : NO
 » 3 years ago, # |   -12 Is WA in a sample which is not a pretest 1 costs WA ?!!!!KAN
 » 3 years ago, # | ← Rev. 3 →   -29 it's like this is the slowest system test ever |:
 » 3 years ago, # |   +1 Can someone describe the solution for D?
•  » » 3 years ago, # ^ | ← Rev. 4 →   +18 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.
•  » » 3 years ago, # ^ | ← Rev. 2 →   +41 dp[i][j] means number of sets of j disjoint paths in a tree of height iThe 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 path2- 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 path3- 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
 » 3 years ago, # |   0 I can't believe I failed to pass div2 A. This is quite embarrassing
 » 3 years ago, # | ← Rev. 3 →   +27 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
•  » » 3 years ago, # ^ | ← Rev. 2 →   0 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 :)
•  » » » 3 years ago, # ^ | ← Rev. 2 →   +5 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.
•  » » » » 3 years ago, # ^ |   0 Oh yea.. got it.. Thanks :)
 » 3 years ago, # |   -15 For God Sake when you wanna add pretests, add them strong not so easy and stupid, for Div.2 D, I wrote: match[node]=1; match[nx]=1; instead of: match[node]=nx; match[nx]=node; And still I got it pretests passed :\ I can't believe it
 » 3 years ago, # | ← Rev. 3 →   0 Can anybody please tell me what's wrong with my submission on E problem? Getting WA on 5th pretest. 28522539UPD: Nevermind, stupid mistake
 » 3 years ago, # |   +25 How to solve Div 1 C ?
•  » » 3 years ago, # ^ | ← Rev. 3 →   +109 Basically problem is asking to maximize d such that: We can do some algebra to get: The right hand side doesn't depend on d, so basically we can consider it some constant C and just try to find the maximum d such that .Now, if this were monotonic, we could find d easily using binary search. Unfortunately, it's not, because is decreasing while d is increasing.The trick here is that there aren't many distinct values of . In fact, for any such ai there are only such distinct values. Anyway all the possible distinct values are given by i and for all .So what we can do is get all the possible distinct values of and also the bounds l and r such that l ≤ d ≤ r gives 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 d within 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
•  » » » 3 years ago, # ^ | ← Rev. 2 →   +16 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 .
•  » » » » 3 years ago, # ^ | ← Rev. 3 →   0 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 n factor 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,  - v prefix sum trick; for each ai 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 to l and to the one after r in the sum array. We can find locations of these l and r in 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 .
•  » » » » » 3 years ago, # ^ |   +21 Actually, it can be shown that your solution (and my solution) runs in time (A is the maximum of {ai}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 to x and greater than x separately. The first part is obviously O(x) size. And the second part is size because for each input ai, in order to , should be satisfied.Then we can set to minimize the quantity.
•  » » » » 3 years ago, # ^ |   0 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 in O(1).
 » 3 years ago, # | ← Rev. 2 →   +22 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.
•  » » 3 years ago, # ^ | ← Rev. 2 →   +64 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 :(
•  » » » 3 years ago, # ^ |   +15 I implemented it. But I forgot there could be several connected components :(
•  » » » 3 years ago, # ^ |   +38 And do you know is this just a coincidence or there is some meaning of that?
•  » » » » 3 years ago, # ^ | ← Rev. 2 →   +19 Well, if the variables are x1, x2, ... xn, then the condition is equivalent to the matrix being positive definite, which is one definition of the Dynkin diagram. (We take cij to be if there is an edge between i, j, and 0 otherwise.)However, DEGwer's solution is essentially the same method that classifies Dynkin diagrams.
•  » » 3 years ago, # ^ |   0 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
•  » » 3 years ago, # ^ | ← Rev. 2 →   +13 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.
•  » » » 3 years ago, # ^ | ← Rev. 3 →   0 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
•  » » » » 3 years ago, # ^ |   0 Yes, you are right. The proof will be in the editorial.
•  » » 3 years ago, # ^ |   0 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.
•  » » » 3 years ago, # ^ |   0 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.
 » 3 years ago, # |   0 How to solve div2 C?
 » 3 years ago, # |   0 Will we be able to view our submissions page after this contest?
•  » » 3 years ago, # ^ |   0 Yes
 » 3 years ago, # |   +42 That moment when you are unable to solve Div1 C and see this solution :P
 » 3 years ago, # |   0 why CF-predictor dosen't work ?
•  » » 3 years ago, # ^ |   0 It's because of the API
 » 3 years ago, # |   -6 When will the ratings be updated?
•  » » 3 years ago, # ^ | ← Rev. 2 →   -8 Dude have some patience
 » 3 years ago, # | ← Rev. 2 →   -12 Codeforces api is down
•  » » 3 years ago, # ^ |   -6 God _/_
 » 3 years ago, # |   +2 http://codeforces.com/contest/831/submission/28526420Why does this code time out? I have seen multiple N2 * logN solutions that passed for this problem.
•  » » 3 years ago, # ^ |   0 I timed out on the same test :(http://codeforces.com/contest/831/submission/28515589
 » 3 years ago, # |   +1 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 :(
•  » » 3 years ago, # ^ |   0 did you checked the condition "If Polycarp messes something up and there is no options, print "0" (without quotes)."
•  » » » 3 years ago, # ^ | ← Rev. 2 →   0 The solution is supposed to terminate correct or not, I can't see anything falling into infinite loop in my code, is there?
•  » » 3 years ago, # ^ |   0 It's O(n * k * log2k). map and set are not O(1).
•  » » » 3 years ago, # ^ | ← Rev. 2 →   +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 ?
 » 3 years ago, # |   +1 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.
•  » » 3 years ago, # ^ | ← Rev. 2 →   0 Div2 C Accepted by unodered map code
•  » » » 3 years ago, # ^ |   0 Hi @oo7rm.Can you explain your idea ,If you don't mind. Thank You!
•  » » » » 3 years ago, # ^ | ← Rev. 2 →   0 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 b[i]=x+a[i]+a[i+1]..a[j] x = b[i]-a[i]-a[i+1]..-a[j]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. Complexity is O(k*k*log(k))With Fast I/O and unodered map you may get accepted. Hope it's clear.
•  » » » » » 3 years ago, # ^ |   0 Thank you so much for sparing your time .I understood it well
•  » » » » » 3 years ago, # ^ |   0 I implemented the same idea but getting TLE Once can you check it plz http://codeforces.com/contest/831/submission/28539653
•  » » 3 years ago, # ^ |   +1 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.
 » 3 years ago, # |   0 How is N^2logN getting TLE in div 2 C? Or did I miss something? http://codeforces.com/contest/831/submission/28516440
•  » » 3 years ago, # ^ |   0 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..
 » 3 years ago, # |   0 Awesome rounds! Thanks! The scoring is a bit screwed but for Div2 but still a good round
 » 3 years ago, # | ← Rev. 2 →   +10 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?
•  » » 3 years ago, # ^ | ← Rev. 4 →   0 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. #include "testlib.h" #include using namespace std; int main() { rnd.setSeed(); set winners; while (winners.size() < 5) winners.insert(rnd.next(1, )); for (auto winner: winners) cout << winner << " "; cout << endl; return 0; } 
 » 3 years ago, # |   +1 Friendly Div2C,my friend.
 » 3 years ago, # | ← Rev. 3 →   +5 Solution to Div1 B using just multiset 28517177.Shouldn't it give TLE? Hmmmm.
•  » » 3 years ago, # ^ | ← Rev. 4 →   +8 It should. 99999 cards with 2 and one card with one in the middle is a hack. #include using namespace std; int main() { cout << 100000 << endl; for(int i = 1; i <= 49999; i++) cout << 2 << ' '; cout << 1 << ' '; for(int i = 1; i <= 50000; i++) cout << 2 << ' '; } 
 » 3 years ago, # |   +91
 » 3 years ago, # |   +10 When will the winners of the prizes be announced and how you'll pick them randomaly ??
 » 3 years ago, # |   +9 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.
•  » » 3 years ago, # ^ |   +7 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.
•  » » » 3 years ago, # ^ | ← Rev. 2 →   0 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. program.cpp:173:5: error: redefinition of 'int n' int n; 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...
 » 3 years ago, # |   0 How to solve Div2E??I've already seen that it has a solution using fenwick tree..but could anyone elaborate??Thanks in advance
•  » » 3 years ago, # ^ | ← Rev. 2 →   0 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
 » 3 years ago, # |   +26 I'm so sad :(
 » 3 years ago, # | ← Rev. 2 →   +78 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).
•  » » 3 years ago, # ^ |   0 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 :\ !!
•  » » 3 years ago, # ^ |   +1 Thanks, i got +3 :D Still div2 :(
 » 3 years ago, # |   0 Could anyone explain how to solve Div1.C ? thanks
•  » » 3 years ago, # ^ |   0
 » 3 years ago, # |   0 Can any one give a DP solution for Div2 D.Please keep it sweet and simple..Thanks.
•  » » 3 years ago, # ^ |   0 28516949
•  » » » 3 years ago, # ^ |   0
•  » » » » 3 years ago, # ^ |   0 can you tell me about your dp state
•  » » 3 years ago, # ^ | ← Rev. 2 →   0 If you are interested in clean top-bottom DP implementation,you may check mine.(http://codeforces.com/contest/831/submission/28530870)
•  » » 3 years ago, # ^ |   0
•  » » » 3 years ago, # ^ |   0 Finally done man..Thanks all for your support..
 » 3 years ago, # |   0 When will the list of winners of championship souvenirs be published ?
 » 3 years ago, # |   0 Can anyone explain how to solve DIV-2 E?
•  » » 3 years ago, # ^ |   +9 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 + id First id - 1 elements place to the back Erase element id Answer will be in ansTime complexity is O(nlogn) because our Treap will be empty after n iterations (on each iteration we erase only one element)
•  » » » 3 years ago, # ^ |   0 can you give some tutorial/link on Implicit Treap
•  » » » » 3 years ago, # ^ |   +1
•  » » 3 years ago, # ^ | ← Rev. 5 →   +3 Let's see what is actually happening — Each time,the array is rotated to 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 . r=val[arr[i]].lower_bound(l) or r=val[arr[i]].lower_bound(1) 5) No of times that you read a no is r-l+1 or (n-l+1) + r 6) There is a catch here.The above formula doesn't exclude the removed numbers.To do this,keep a fenwick tree to store and query the no of removed postions in a range and do the appropriate correction. 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
•  » » » 3 years ago, # ^ |   +3 Nice Solution :)
•  » » 3 years ago, # ^ | ← Rev. 2 →   +18 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, 2Firstly, 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, 1By considering the '3's, we will fill the array as:3, 2, 2, 1, 1 for a total of 9.
•  » » » 3 years ago, # ^ | ← Rev. 2 →   0 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. 28545844edit: btw, my friend used balanced binary search tree to get its subtrees size's :D.
•  » » » » 3 years ago, # ^ |   +5 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.
 » 3 years ago, # |   +57
 » 3 years ago, # |   0 Did anyone solve DIV2 C using Dynamic Programming?I searched a lot but didn't found any.
 » 3 years ago, # |   +3 Mere mortals are still not able to view VK Finals contest.
 » 3 years ago, # |   0 Editorial is waiting for winter to come. Winter is coming and so is the editorial.
»
3 years ago, # |
+21

And the souvenir winners are determined (seed = 3954, length = 394).

List place Contest Rank Name
65 830 65 halin.george
69 830 69 Neil
153 830 153 BigBag
265 830 266 whczr
320 830 323 Rydberg

Congratulations!

•  » » 3 years ago, # ^ |   +8 Thanks!It's a nice surprise after 3 weeks :)
•  » » 3 years ago, # ^ |   0 Thanks!Wow,I'm really excited to become the luckydog and looking forward to the special souvenir!
 » 3 years ago, # |   0 So where's the souvenir?It has been 2 months but I haven't heard of anything about it.Am I ignored? :D
•  » » 22 months ago, # ^ |   +2 Just can't believe that I haven't heard of anything about the souvenir till now.I think you must have forgotten this.
•  » » » 22 months ago, # ^ |   -8 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.