### awoo's blog

By awoo, history, 4 years ago, translation,

Hello Codeforces!

On October 27, 17:05 MSK Educational Codeforces Round 31 will start.

Series of Educational Rounds continue being held as Harbour.Space University initiative! You can read the details about the cooperation between Harbour.Space University and Codeforces in the blog post.

The round will be unrated for all users and will be held on extented ACM ICPC rules. After the end of the contest you will have one day to hack any solution you want. You will have access to copy any solution and test it locally.

You will be given 6 problems and 2 hours to solve them.

The problems were prepared by Ivan BledDest Androsov, Vladimir vovuh Petrov, Alexey Perforator Ripinen, Mike MikeMirzayanov Mirzayanov and me.

Good luck to all participants!

Congratulations to the winners:

Rank Competitor Problems Solved Penalty
1 biGinNer 6 175
2 natsugiri 6 228
3 palayutm 6 283
4 LHiC 6 293
5 eddy1021 6 295

Congratulations to the best hackers:

Rank Competitor Hack Count
1 No_One_Loves_The_Weak 18
2 halyavin 22:-10
3 dreamoon_love_AA 33:-35
4 kuko- 15
5 STommydx 12:-1

259 successful hacks and 368 unsuccessful hacks were made in total!

And finally people who were the first to solve each problem:

Problem Competitor Penalty
A eddy1021 0:01
B eddy1021 0:02
D cyand1317 0:18
E eddy1021 0:36
F zscoder 0:35

• +136

 » 4 years ago, # |   -39 ?detar ti si
•  » » 4 years ago, # ^ |   +65
•  » » 4 years ago, # ^ | ← Rev. 2 →   -16 !
•  » » 4 years ago, # ^ | ← Rev. 2 →   +18 https://pasteboard.co/GQNNymL.pnghttps://pasteboard.co/GQNO1vS.pngSorry I do not like the sea :( I often get seasick
•  » » 4 years ago, # ^ |   +32
•  » » » 4 years ago, # ^ |   -8 xD
 » 4 years ago, # | ← Rev. 3 →   +67 I have made a chrome extension which automatically downvotes any comments with the phrase "is it rated". You can download it from: goo.gl/V8KP39
•  » » 4 years ago, # ^ |   +8 spoiler:u Got trolled!!
•  » » 4 years ago, # ^ |   +29 Anyways, the music is good :P
•  » » 4 years ago, # ^ |   0 so mean XD
•  » » 3 years ago, # ^ |   0 Can you tell me where is music from?
 » 4 years ago, # |   +105
•  » » 4 years ago, # ^ |   0 Guy in the middle is only interested in the educational round, not rating :)
 » 4 years ago, # |   -56 Is it rated? Фалунь Дафа хорош!
 » 4 years ago, # |   -19 Wow! 2 contests in a row. I am so excited. :D
 » 4 years ago, # | ← Rev. 4 →   -9 UPD: FIXED!
•  » » 4 years ago, # ^ |   -16
 » 4 years ago, # | ← Rev. 2 →   -33 SpoilerIt isn't rated!
 » 4 years ago, # |   +38 Score distribution? :)
 » 4 years ago, # |   -47 Is it rated?
 » 4 years ago, # |   +19 Very nice contest!!! D was a very interesting problem, it tricked me into thinking I have a correct solution when it was miserably wrong.Can you please tell me how to solve D? I noticed that it will probably be some kind of divide and conquer but that's where I got stuck, but I might be completely wrong (again.. ).
•  » » 4 years ago, # ^ |   +9 It's just merging 2 to 3 piles of balls every time, with each time the cost.equals to the sum of the number of balls merged, so a greedy algorithm would work.
•  » » 4 years ago, # ^ | ← Rev. 2 →   +25 Think backwards. You have all the elements in their original position and you want to put them in starting position with smallest cost. To solve this, you can adapt the greedy algorithm to find the Huffman code. There are two main differences:1) You get the 3 smallest elements to generate a new one (instead of two).2) In the case when you have a even amount of elements you'll get a suboptimal solution if you follow this algorithm. But you can be greedy here too, just convert the smallest two to a new element to get and odd number of elements.
•  » » » 4 years ago, # ^ |   +3 Thank you!Thinking backwards can sometimes be very helpful, but I've never used it on a construction/greedy problem.I'll bear this trick in mind.
•  » » » 4 years ago, # ^ |   +3 how did you come up with this solution?
•  » » » » 4 years ago, # ^ |   0 I tried some approaches that didn't work. Until I realized the problem we were trying to solve was almost the same that this one: https://en.wikipedia.org/wiki/Huffman_coding#Problem_definitionYou can see the relation if you see the problem backwards. Initially you have all colors in their positions and you want to bring them all to first position.This problem has a known greedy solution. If you don't know the solution for the Huffman Coding problem, please read about it. You'll need to know it in order to understand next paragraph.The thing is that now you have a ternary (not a binary) tree. So we must adapt the solution. My first try was to greedily try to get the 3 smallest values and merge them. But this does not work when you have a even number of colors, because you'll have to make an operation with only 2 nodes. First I tried to make this operation using two nodes as late as possible in the merging process (when we have only 2 or 4 nodes left), but this is not optimal. So I drew some test cases and concluded that you should do it as soon as possible, so every case you have a even number of nodes you should merge the smallest two and get a problem with odd number of nodes, in which you can apply the greedy approach.
•  » » » 4 years ago, # ^ | ← Rev. 2 →   0 Can you please explain the solution for problem-D in detail. Can you please explain what changes when n is even. I am still unable to to visualise the solution you told.
•  » » » » 4 years ago, # ^ |   0 Please read my comment above.
•  » » 4 years ago, # ^ | ← Rev. 2 →   0 Greedy will work to solve D.The process of D is to build a Huffman Tree.So we can construct a Huffman Tree with 3 leaves each node that isn't a leaf to get the answer.What's more,there're similar problems in China. http://uoj.ac/problem/130 http://tyvj.cn/p/1066 (In Chinese)
 » 4 years ago, # |   0 Seems that a greedy algorithm would be the best solution for F while I used min cost flow. The time limit is quite loose.
 » 4 years ago, # |   +7 defender & Hacker same person :p
 » 4 years ago, # |   0 What is the hack for div2 B ?
•  » » 4 years ago, # ^ |   -14 6 1 4 4 4 4 4Why 38 in this case in D ?
•  » » » 4 years ago, # ^ |   +1 How Would I Know that . Don't comment irrelevant ANSWERS please
•  » » 4 years ago, # ^ |   0 For example,I sum up all ai and incorrectly considered the answer to be "yes" when x-sum=n+1 or n-1,so I am hacked only 9 min after the beginning of the hack phase.
•  » » » 4 years ago, # ^ |   0 What is the test case please.
•  » » » » 4 years ago, # ^ |   0 2 5 1 1 This test can make my program produce wrong answer.
•  » » » » » 4 years ago, # ^ |   0 But It is showing as 'invalid' input . Please can you provide me a valid input :)
•  » » » » » » 4 years ago, # ^ |   0 Between "2 5" and "1 1",there is a '\n'. Maybe you don't enter it.
 » 4 years ago, # |   +1 6 1 4 4 4 4 4 Why 38 in this case in D ?
•  » » 4 years ago, # ^ |   +1 1 4 4 4 4 4take (1, 4, 4, 4, 4, 4) and spread like this (1, 4, 4) (4, 4) (4) total cost = 21take (1, 4, 4) and spread (1) (4) (4) total cost 9take (4, 4) and spread (4) (4) total cost 8
 » 4 years ago, # |   0 How to solve E?
•  » » 4 years ago, # ^ |   +1 go from top to bottom maintaining DSU for current and previous row
 » 4 years ago, # | ← Rev. 3 →   0 can someone explain what did they mean with ordered pairs in c. the pairs are ordered based on what and when we can make a pair of (x,y) and when we can't I really hate when i don't understand the most important line in the problem XD .
•  » » 4 years ago, # ^ |   +10 It means pair (x, y) is not the same as pair (y, x). Btw you can always ask jury a question during the contest, use it if you don't understand something in statement
•  » » » 4 years ago, # ^ |   0 thx finally i solved it... I wonder when i will be able to solve D problems I have no idea what am i supposed to learn to do that there are alot alot of algorithms and learning them all is not a great idea . isn't there a beginning to train on harder problems ? btw why pressing enter here isn't working i can only make lines with bulleted list
•  » » » » 4 years ago, # ^ |   +3 You have to press enter twiceto make a new line.
 » 4 years ago, # |   -13 I think educational rounds should be rated. I mean, they are perfectly good roundsI consider some problems to not have well known solutions (even though this information is in the description of the educational rounds — maybe the ideia was once used somewhere else, but to recognize the idea in a particular problem statement is always a unique activity) and usually very few people can solve all problems (depending on the difficulty maybe it could be rated just for div 2)Also if someone does not wish to compete they could just do the round in a virtual participation
•  » » 4 years ago, # ^ |   +5 Oh boy, commenting without knowing codeforces tradition of downvoting.... That's gotta hurt.
•  » » » 4 years ago, # ^ |   0 So, he can't write his opinion about site ? Let's remove the comments. Nobody will write their "stupid" opinions.
•  » » » 4 years ago, # ^ |   0 you have anime profile
 » 4 years ago, # |   +1 can someone explain me how to solve c i didnt' get why people are multiplying the size of the group of connected station with itself because it is not necessary the if there is path from(1,2) then there is also a path from(2,1).
•  » » 4 years ago, # ^ |   +1 For every group of connected stations, it is necessary that every station is reachable from every other station since every pi's are distinct which means that only one train can leave a station(i's are distinct) and only one can reach it(pi's are distinct). Due to which every connected stations would form a cycle and would contribute it's size^2 to the final result.
•  » » 4 years ago, # ^ | ← Rev. 2 →   +2 In this problem, the graph is directed, so if you have a strong component, it is a cycle.In a cycle, if you can reach vertex Y from vertex X, you can reach vertex X from vertex Y. In other words, all vertex in the same component can reach all other vertex in this component (including itself).So, if you have a component with N vertex, then you have N * N pairs reachable from each other.
•  » » » 4 years ago, # ^ | ← Rev. 3 →   0 hey...guys help......i did that ...i ran dfs and got all components...then i joined the first two components with highest verteces ..then N*N for all components...but getting wrong answer on case 18 shows my output>ans
•  » » » » 4 years ago, # ^ |   0 i use disjoint sets to find numbers of cycles and then merge the biggest two cycles.http://codeforces.com/contest/884/submission/31817720
•  » » » » » 4 years ago, # ^ |   0 i did quite the same
•  » » » » » » 4 years ago, # ^ |   0 All my test cases seems to pass. Maybe you can check the corner cases, where n = 2 or n = 1.Maybe some problem in there.
 » 4 years ago, # |   0 hey...guys help......gettin WA...i ran dfs and got all components...then i joined the first two components with highest vertices ..then N*N (N=number of vertex in a comp) for all components...but getting wrong answer on case 18 shows my output>ans
•  » » 4 years ago, # ^ |   0 Type cast before you multiply the answer . Like, instead of ans=N*N write ans=(long long)N*N . Do the same for every multiplication hope it will get AC :)
•  » » » 4 years ago, # ^ |   0
•  » » » » 4 years ago, # ^ |   0 Change cout<<(llint)(n*n) into cout<<(llint)n*n 
•  » » » » » 4 years ago, # ^ |   0 wow...thanks man....what was wrong with cout<<(llint)(n*n) by the way
•  » » » » » » 4 years ago, # ^ | ← Rev. 2 →   0 The first way you are multiplying two ints and then casting that overflow result to a long. The second way you cast the first n to a long that way the second n is implicitly converted to a long as well when doing the multiplication.
•  » » » » » » » 4 years ago, # ^ |   0 oh..it's clear now .i thought u have to typecast the whole equation ... thanks man
•  » » » » » » 4 years ago, # ^ |   0 or u can use 1LL * n * n1LL means 1 in long long
•  » » » » » » » 4 years ago, # ^ |   0 yeah..that works too man....didn;t know
 » 4 years ago, # |   0 C Bertown Subway http://codeforces.com/contest/884/submission/31826056pretty confused...
•  » » 4 years ago, # ^ |   0 I found the problem myself, incorrect max1 and max2 (JUST IGNORE THE POST)
 » 4 years ago, # |   +3 where can i see the problems? im new in this page. :( yesterday i registered for the concourse, but i can't participated. can you helpe me to find the problems please?
•  » » 4 years ago, # ^ |   +3
•  » » 4 years ago, # ^ |   0 thank you mister
 » 4 years ago, # |   0 where is the editorial ?
 » 4 years ago, # | ← Rev. 3 →   0 There is a Telegram bot that informs us upcoming contests regularlyUsername is @CodeForcesBot
 » 4 years ago, # |   0 Auto comment: topic has been updated by awoo (previous revision, new revision, compare).
 » 4 years ago, # |   0 Auto comment: topic has been updated by awoo (previous revision, new revision, compare).
 » 4 years ago, # |   0 I am confused with something.How can someone solve two problems in two seconds...
•  » » 4 years ago, # ^ |   0 two minutes*