Please subscribe to the official Codeforces channel in Telegram via the link: https://t.me/codeforces_official. ×

### Ajosteen's blog

By Ajosteen, 3 months ago, translation, ,

Hello, community!

Codeforces Round #509 will be held on Sep/16/2018 13:35 (Moscow time). The round will be rated for Div. 2 contestants. There will be 6 problems for 2 hours. Please, notice that the start time is unusual.

The round will be rated for the div. 2 participants. The statements will be available in Russian and English languages.

The round will start 2 hours after the start of the Qualification Stage, so they will finish around same time. That's why we ask the participants of the Quals to stay silent and don't share the statements of the contest with anyone. Unfortunately, we cannot add all the problems from Quals to the round, it will contain only six problems.

The problems for the official contest were prepared by the guys from the jury in the person of Alex fcspartakm Frolov, Adilbek adedalic Dalabaev, Ivan BledDest Androsov and me.

We also would like to express our gratitude to Anton arsijo Tsypko for coordination of the round and Mike MikeMirzayanov Mirzayanov for the permission to make a mirror and Codeforces and Polygon platforms. Also big thanks to the testers: IlyaLos, Perforator, kuviman, HolkinPV, zubec, StasyaCat, Karasick for testing.

As usual, the scoring distribution will be announced just before the round.

Good luck!

UPD: Scoring Distribution: 500-1000-1500-2000-2500-3000

UPD2: Editorial

•
• +237
•

 » 3 months ago, # |   +29 After 9 days, wait is over.
•  » » 3 months ago, # ^ |   -46 LOOK AT THIS ------------> https://www.youtube.com/watch?v=OBc7IXh3ex4
 » 3 months ago, # | ← Rev. 2 →   +9 Early tomorrow morning there is also the Qualification Stage of Singapore (mirror available on Kattis).Looks like the ICPC preparation is underway simultaneously all over the world :D
•  » » 3 months ago, # ^ |   0 How to solve D and E?
•  » » » 3 months ago, # ^ |   0 My soln for D — You can refer here (Question is a bit similar to this) to find all cycles in D. One observation — if there exist 2 edges of a vertex which leads it to 0 then this vertex belongs to the soln set => vertex belongs to cycle.Now all cycles which have zero as vertex belongs to the soln set. And If at least one vertex of cycle belongs to soln set then all vertex belongs to the soln set. So dfs2 was made to find soln set which marks all cycles which belong to soln set. And then runs dfs2 for all vertex of this set.
•  » » » » 3 months ago, # ^ |   0 Thank you, I got ACed.
•  » » » 3 months ago, # ^ | ← Rev. 2 →   0 Another approach for D that I found after contest time (should give some credits to my friend liv1n9 for some ideas within it, not sure if this was his exact approach coz' I didn't fully manage to get his words :D).A junction can be considered safe if there are at least 2 paths from junction 0 to it (obviously, junction 0 is a safe junction itself).Therefore, I'll transform the given undirected graph to a directed graph (each bidirectional edge will be considered as 2 edges between two junctions, just with different directions).With this new graph created, I'll perform 2 separate DFS traverse, both started from 0:The first traverse will give me a directed subgraph (consisting of directed edges) that allow me to reach every junction from junction 0 (yet not the other way around). After that traverse being complete, I'll delete that whole subgraph.The second traverse will let me know if each junction is safe (i.e. there exists another path from 0 to that junction, after deleting the first path given in the previous subgraph).The subgraph deletion can be handled easily if adjacency list of each junction is maintained by a set instead of vector/array.
•  » » » » 3 months ago, # ^ |   0 I think this approach will fail on following test case. 3 3 0 1 0 2 1 2Because deleting a subgraph will delete 2 of 3 edges. And based on which 2 edges are deleted remaining graph will have 0 or 0,1 or 0,2 as an answer.But in fact, all 3 vertexes are in soln set.
•  » » » » » 3 months ago, # ^ | ← Rev. 2 →   0 Actually, I should apology for my explanation being a bit vague.The subgraph being deleted is a directed one, that means I'll only delete the edges that can lead from junction 0 to other junctions (but not the other way around).Therefore, after 1st DFS, directed edges (0 → 1), (1 → 2) will be deleted.The second DFS can still reach all other junctions (one possible path is 0 → 2 → 1).(Explanation edited in the main comment as well).
•  » » 3 months ago, # ^ | ← Rev. 2 →   0 How to solve C, E ??
•  » » » 3 months ago, # ^ |   0 My idea for E: binary search + flowYou can binary search the answer: with each value z, build a bipartite graph that, there exists a edge between (xi, yj) if aij ≥ z. z can be the minimum value of a combination if the maximum bipartite matching of the newly built graph equals exactly N — this could be solved by maxflow algorithms.(I didn't solve it during contest time, just knew the idea, but couldn't implement maximum bipartite matchings properly :-P)
•  » » » 3 months ago, # ^ | ← Rev. 4 →   +11 You can solve C using dynamic programming. First observation: after building N characters, we can uniquely determine the last N characters.So let's dp(i, j, k) be the number of ways, we are at i-th character, already at j-th character of string s from prefix and at k-th character of string s from suffix.Then answer will be sum of dp(n, j, k) where j >= k.Solution for E: first we binary search the answer, let's assume we are at mid, build a network flow, add an edge with capacity equal to 1 from source to every row, add an edge with capacity equal to 1 from every column to sink, then for each row and each column (assume it's i-th row and j-th column), if aij >= mid then we add edge from row i to column j with capacity equal to 1. Then if maximum flow equal to size of board then l = mid + 1, else r = mid
 » 3 months ago, # | ← Rev. 2 →   -17 thanks cf
 » 3 months ago, # |   0 i don't understand this line properly. "The round will start 2 hours after the start of the Qualification Stage, so they will finish around same time." can you please explain it in details?
•  » » 3 months ago, # ^ |   0 It means that Quals is the 4-hour length contest
•  » » » 3 months ago, # ^ |   +2 when i can start? from the qualification stage?
•  » » » » 3 months ago, # ^ |   +17 You can start tomorrow on 13:35 (moscow time) at cf round
 » 3 months ago, # |   -16 It is rated for Div2. My rating is 1900+ is it rated for me?
•  » » 3 months ago, # ^ |   +8 Yes
 » 3 months ago, # |   +55 Perfect time for Chinese users!
•  » » 3 months ago, # ^ |   +27 You are right!thanks for Codeforces!the begin time is so good!
•  » » » 3 months ago, # ^ |   +20 I'm Chinese too. The time is really wonderful!
•  » » » » 3 months ago, # ^ |   +12 Wonderful time!Thanks for codeforces!
•  » » 3 months ago, # ^ | ← Rev. 3 →   +14 Wow! It's wonderful. And I hope that the description of the problems will concise After the Contest:………………I can only make a joke:"My English is so bad"……
 » 3 months ago, # |   -9 It Was So long time.
 » 3 months ago, # | ← Rev. 2 →   0 Ajosteen, are problem statements gonna be long like in NEERC rounds or adapted to CF round?
•  » » 3 months ago, # ^ | ← Rev. 4 →   +12 The statements' format will be as in usual div2 rounds.
 » 3 months ago, # |   +37 Personally speaking, I think that Codeforces is the best oj in the world.
 » 3 months ago, # |   +9 8000+ contestants
 » 3 months ago, # | ← Rev. 2 →   +8 Solved 2 problems for the first time
 » 3 months ago, # |   +37 queue
•  » » 3 months ago, # ^ |   0 damn man really :(
 » 3 months ago, # |   +27 My submission has been staying in queue for 5 minutes, any help ?
 » 3 months ago, # | ← Rev. 3 →   +33 I have much more penalty on pC because of the queue, can I have some points back?Edit: Actually, 40 points won't affect me too much, but I feel sad for those who were actually affected by the delay.
 » 3 months ago, # | ← Rev. 4 →   +22 If one is not good at English (such as me) : then : Is it EnglishForces???Is it Codespeed???……
•  » » 3 months ago, # ^ |   +9 Or maybe... SpeedForce!
•  » » » 3 months ago, # ^ | ← Rev. 3 →   +8 ……
•  » » 3 months ago, # ^ |   +3 Result of not thanking KAN XD
 » 3 months ago, # |   0 extend the round due to queue by at least 10 minutes
 » 3 months ago, # |   +3 why the f I checked my submission after I had locked.....
 » 3 months ago, # |   0 EnglishForces
 » 3 months ago, # | ← Rev. 2 →   0 What's wrong with this solution for D? 42940213
•  » » 3 months ago, # ^ | ← Rev. 2 →   +1 Test Case 5- 2 1 1 2 3 4 Your output is 3. But the answer is 2. My one attempt failed due to this. :P
 » 3 months ago, # | ← Rev. 2 →   +20 This problem set seems to be the most balanced one in recent times on codeforces:DBtw how to solve F? I could reduce it to finding maximum number of points lying on a straight line in a given set of points,but couldn't use the property that distance between adjacent points(along one co-ordinate) is same.
•  » » 3 months ago, # ^ | ← Rev. 3 →   +9 let assume your picks B and A , and B-A is T;so in the first line you get A + 2t + 4t + 8t, and in the second line a+t , a+3t ....you only need find the answer for every t which is power of 2.because for example picking t=6 is subset of t=2;I guess you can find an answer of every power of 2 . Note: for every T you should look at numbers in mod 2t. so increase mapA[a[i]%2t]++ and mapB[(b[i]%2t)]++so look for the maximum mapA[i] + mapB[i+t];
 » 3 months ago, # |   -66 please consider making it unrated
 » 3 months ago, # |   0 test case 5 on problem d ?
•  » » 3 months ago, # ^ |   +4 I think it is similar to2 1 1 5 6 10The answer is 5. Wrong solutions might output 9.
•  » » » 3 months ago, # ^ |   0 thanks !
 » 3 months ago, # |   +3 Anyone has idea what pretest 7 for C is?
 » 3 months ago, # |   +6 https://codeforces.com/blog/entry/61876this says editorial posted 3 hours ago
•  » » 3 months ago, # ^ |   +15 It was saved in drafts.
•  » » » 3 months ago, # ^ |   0 ohh
 » 3 months ago, # |   -11 i think cf started div4...
 » 3 months ago, # |   0 Any idea on what might be the pretest-9 in Div2 C? Thanks
 » 3 months ago, # |   +9 Why i can't see another's solutions?
 » 3 months ago, # |   0 How to solve E?
•  » » 3 months ago, # ^ |   +6 Each input must be in the form of i n since node n will fall into one of the parts after erasing an edge. If i n exists multiple times, add nodes with smaller indices between them.
 » 3 months ago, # |   +33 RIP all contestant who thought that A can be equal to B in F...
•  » » 3 months ago, # ^ |   +33 Isn't "RIP all contestant who didn't thought that A can be equal to B in F" ??
•  » » » 3 months ago, # ^ |   +13 Wait, so it turned out that the clarification for my question is incorrect?
•  » » » » 3 months ago, # ^ |   +19 I'm really sorry for that(When your question arrived, the only thing I had in mind was "A and B are on the different sides of the tube, how can they be equal?" I haven't thought that the question was about x-coordinates.
•  » » » » » 3 months ago, # ^ |   +14 I could not solve F in time, so it didn't affect me anyway.
•  » » » » » 3 months ago, # ^ |   0 I think BledDest is formally right in this case...
 » 3 months ago, # | ← Rev. 2 →   +11 In F, for the test 1 100 1 1 200 1 would the answer be 1 or 2 (ray bouncing off vertically)?
•  » » 3 months ago, # ^ |   +8 I have the same question
•  » » 3 months ago, # ^ |   +7 It should be 2, since there is no restrictions on relative positions of A and B. I'm sorry for the absence of such test in the pretests, trying to break some clever solutions, I forgot about this basic one.
•  » » » 3 months ago, # ^ |   +50
•  » » 3 months ago, # ^ |   +3 2. I got hacked for this case.
•  » » 3 months ago, # ^ |   0 Got fst for this case
 » 3 months ago, # | ← Rev. 2 →   +4 Explain me please why I got TL on pretest #9 (Problem C) Solution
•  » » 3 months ago, # ^ |   +6 cur=upper_bound(ms.begin(),ms.end(),pp);complexity of upper_bound on set is O(n), If you want to use upper bound use s.upper_bound(value to be searched) which is O(logN)
•  » » » 3 months ago, # ^ |   +3 One more bit of information in addition to what you've said: http://www.cplusplus.com/reference/algorithm/upper_bound/. Complexity On average, logarithmic in the distance between first and last: Performs approximately log2(N)+1 element comparisons (where N is this distance). On non-random-access iterators, the iterator advances produce themselves an additional linear complexity in N on average.
 » 3 months ago, # |   0 I just don't get it why would that take runtimeerror even if i erase an iterated element from set I should still be able to reach the iterator valueI kept getting runtimeerror until i changed this... but why would that work for some test but not for pretest 9solution
•  » » 3 months ago, # ^ |   0 even if i erase an iterated element from set I should still be able to reach the iterator value Lol.After you've erased the element, the iterator is invalid. Essentially, it can be seen as a nullptr or any other random trash.
•  » » » 3 months ago, # ^ |   0 I know that means this is a mistake but that worked for some tests and it shouldnt at all if it is
•  » » » » 3 months ago, # ^ |   0 It's called undefined behavior. Sometimes iterator might still point to the memory which has useful data, sometimes it might not.
•  » » » » » 3 months ago, # ^ |   0 well that's a better explanation thx
 » 3 months ago, # |   0 If I submit a solution at time t, my submission is inque for a hour, what's the final submitted time of the solution? t or t+60?
•  » » 3 months ago, # ^ |   +13 Of course t. Penalty is counted by the time of submission, not by the time of judgement.
•  » » » 3 months ago, # ^ |   0 OK, thanks.
 » 3 months ago, # |   0 Maybe I will become gree tomorrow...
 » 3 months ago, # |   0 why pA with counting sort would pass...a O(1e9) solution passes the test with 534ms...
 » 3 months ago, # | ← Rev. 14 →   +61 The round just became worse... :'(
 » 3 months ago, # |   +9 There are same submission of problem C by some participants so please look into this matter. MikeMirzayanov
•  » » 3 months ago, # ^ | ← Rev. 2 →   +28 http://codeforces.com/contest/1041/submission/42933160 http://codeforces.com/contest/1041/submission/42936047 These two submissions are the same. There may be more cases like this.
•  » » » 3 months ago, # ^ | ← Rev. 3 →   +9 sans21 amc1996 pls upvote gourav comment.
•  » » 3 months ago, # ^ | ← Rev. 2 →   -18 The logic similarity is coincidence. There is a wrong submission as well as the number of successful submissions are also different for both users as well the code.(Problem D). Though well meaning, this is a false flag. MikeMirzayanov
•  » » » 3 months ago, # ^ |   +7 Chal jhootha...kisi aur ko banana...hume sab pata h
 » 3 months ago, # |   +136
 » 3 months ago, # |   +2 RATED PLIZZZ
 » 3 months ago, # |   0 Tutorial #1 and Tutorial #2 redirect to the same link
 » 3 months ago, # |   0 Rated Rated Rated xDGive me back my purple <3
 » 3 months ago, # |   +18 I can't make a submission, seems like practice mode is disabled. Is this supposed to happen?
•  » » 3 months ago, # ^ |   0 Practice mode is disabled during system testing. You can submit now.
•  » » » 3 months ago, # ^ |   0 I know that. Systest was over, and usually practice mode is instantly enabled. Thanks for answering anyway!
 » 3 months ago, # |   0 How does this soln passes System Test Cases? It iterates from 1 to 1e9 in worst test cases. Even passes Test Case (My failed hack.) 3 1 1000000 1000000000 with time 15ms.
•  » » 3 months ago, # ^ | ← Rev. 2 →   +12 Because of compiler optimizations, that source is literally O(n), which is good enough. I once got tricked by this, and i've learned my lesson since
•  » » 3 months ago, # ^ |   0 I got 5 unsuccessful hack because of this(-_-).
 » 3 months ago, # | ← Rev. 2 →   +3
 » 3 months ago, # |   +28 https://gyazo.com/3874d1fae9f8da4c56d05359da48d26eSo many tags lmao.
 » 3 months ago, # |   +24 What wrong with D? Don't make me scare :(
 » 3 months ago, # |   +8 WTF?
•  » » 3 months ago, # ^ |   +5 that troll is strong
 » 3 months ago, # | ← Rev. 2 →   -9 When somebody being a candidate master and can edit tags.![ ]()
 » 3 months ago, # | ← Rev. 3 →   0 For all of you who had WA on E on test 33 and don't know why. My problem was:  int i = 0; pair p = make_pair(i, ++i); Pair p contains (1, 1) instead of (0, 1) :/I would be grateful if someone could explain briefly what is the cause of such behavior.
•  » » 3 months ago, # ^ |   +11 Arguments of any function/constructor could be calculated in any order (it's not strictly wrote in C++ standart). Thus, some compilers use left-to-right calculations, some of them use right-to-left, some of them could even use some crazy rules. You can learn more here: https://en.cppreference.com/w/cpp/language/eval_order
 » 3 months ago, # | ← Rev. 2 →   -14 The number of tags (algorithms that can be used to solve the problem) of problem C, D and E is huge and impressive. :) Ajosteen, thank you very much for this awesome and interesting contest.
 » 3 months ago, # |   0 So why do I think that D is much easier than C?For D u just need to get the prefix sum and do lower_bound.I get WA on pretest 9 of C :(.
 » 3 months ago, # |   0 Why does everytime I spend hours during contest to get an idea but the idea hits my brain in just about 10/15 minutes after the contest is over? So frustrated... :(
•  » » 3 months ago, # ^ |   0 Its okay as long as you keep getting ideas. Some of us dont even get the idea.
•  » » » 3 months ago, # ^ |   0 What's the point of getting the idea though if you can't submit in contest time? Well it's still better than nothing but submitting correct in contest is what it really matters
•  » » » » 3 months ago, # ^ |   0 Time will improve with time. Dont worry.
 » 3 months ago, # | ← Rev. 3 →   -8 Wrong answer on sample test cases isn't supposed to get time penalties, correct?I accidentally submitted an incorrect solution to the 3rd question (which was wrong on sample test case 2) and I got time penalty. Is this wrong or am I incorrect?
•  » » 3 months ago, # ^ |   +14 Only failure at the 1st test can be ignored.
•  » » » 3 months ago, # ^ |   +5 Oh okay.. Thanks
 » 3 months ago, # | ← Rev. 2 →   0 I failed WA in D test 11, any ideas what I do wrong? (Was trying to solve with 2 pointers)
 » 3 months ago, # | ← Rev. 3 →   0 Sorry, it's offtopic. Anyone knows how to add Codeforces contests to google calendar? Upd:- Got it now.
 » 3 months ago, # |   0 Can problem D get a DP tag too? My approach was to calculate the covered distance when I start from the i'th segment and using previously stored data of other segments which are already calculated. Of course, there are better approaches to this problem.
 » 3 months ago, # |   -22 sorry,codeforces,i feel surprised that i will receive a letter from you. As a foreign person, i often attend some contests in cf. But i not always get good grades, because my contest skills and English are not so good.I don't want to become green pupil, i just want to be a specialist.In the contest, i copy my friend's coding, this is truth,i don't want to hide from responsibilities.At first,i want to do D problem, because i have done the similar problem before. Unfortunately,there is some thing wrong with my coding. But i don't want to decrease my rating, so i copy. At first, i don't know CF can find the problem, maybe AC automation or trie? And i don't know CF will consider the problem so seriously. I swear i won't do this again. Some people will ask why i don't login a new id, because i don't want to let my story faded away.I want to record every contest, so i can always let myself keep hardworking.I will keep practicing,please don't look down me. All in all, i'm very sorry, i won't do this again.
•  » » 3 months ago, # ^ |   -14 oh, and i can do problem c, but i want to increase my rating more, so i just saw D.10minutes is not enough for c. Also,my stl is not so good.
 » 3 months ago, # |   +8 Easiest F I've ever seen
 » 3 months ago, # |   0 Can somebody help me in problem C 43011918, i am getting the message "wrong output format Unexpected end of file — int32 expected" on test case 13 ,but i am not able to find any such mistake where i am accessing value from any wrong index.Thanks in advance!
•  » » 3 months ago, # ^ |   0 It means you wrote less than n-1 commands
•  » » » 3 months ago, # ^ |   0 Thanks man.
 » 2 months ago, # |   +8 Full Qualification Stage have been added to Gyms.