PikMike's blog

By PikMike, history, 4 weeks ago, translation, In English,

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 0n25 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 Hinata_On_Fire 18
2 halyavin 22:-10
3 dreamoon 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
C gritukan 0:06
D cyand1317 0:18
E eddy1021 0:36
F zscoder 0:35

UPD: Editorial is uploaded

 
 
 
 
  • Vote: I like it  
  • +136
  • Vote: I do not like it  

»
4 weeks ago, # |
  Vote: I like it -39 Vote: I do not like it

?detar ti si

»
4 weeks ago, # |
Rev. 3   Vote: I like it +67 Vote: I do not like it

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 weeks ago, # |
  Vote: I like it +105 Vote: I do not like it

  • »
    »
    4 weeks ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Guy in the middle is only interested in the educational round, not rating :)

»
4 weeks ago, # |
  Vote: I like it -56 Vote: I do not like it

Is it rated? Фалунь Дафа хорош!

»
4 weeks ago, # |
  Vote: I like it -19 Vote: I do not like it

Wow! 2 contests in a row. I am so excited. :D

»
4 weeks ago, # |
Rev. 3   Vote: I like it -9 Vote: I do not like it

WTF? cf user: srikanthrock260 registered 48 years ago! Is it bug or hack?

UPD: FIXED!

»
3 weeks ago, # |
Rev. 2   Vote: I like it -33 Vote: I do not like it
Spoiler
»
3 weeks ago, # |
  Vote: I like it +38 Vote: I do not like it

Score distribution? :)

»
3 weeks ago, # |
  Vote: I like it -47 Vote: I do not like it

Is it rated?

»
3 weeks ago, # |
  Vote: I like it +19 Vote: I do not like it

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.. ).

  • »
    »
    3 weeks ago, # ^ |
      Vote: I like it +9 Vote: I do not like it

    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.

  • »
    »
    3 weeks ago, # ^ |
    Rev. 2   Vote: I like it +25 Vote: I do not like it

    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.

    • »
      »
      »
      3 weeks ago, # ^ |
        Vote: I like it +3 Vote: I do not like it

      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.

    • »
      »
      »
      3 weeks ago, # ^ |
        Vote: I like it +3 Vote: I do not like it

      how did you come up with this solution?

      • »
        »
        »
        »
        3 weeks ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

        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_definition

        You 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.

    • »
      »
      »
      3 weeks ago, # ^ |
      Rev. 2   Vote: I like it 0 Vote: I do not like it

      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.

  • »
    »
    3 weeks ago, # ^ |
    Rev. 2   Vote: I like it 0 Vote: I do not like it

    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.

    1. http://uoj.ac/problem/130
    2. http://tyvj.cn/p/1066 (In Chinese)
»
3 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

Seems that a greedy algorithm would be the best solution for F while I used min cost flow. The time limit is quite loose.

»
3 weeks ago, # |
  Vote: I like it +7 Vote: I do not like it

defender & Hacker same person :p

»
3 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

What is the hack for div2 B ?

  • »
    »
    3 weeks ago, # ^ |
      Vote: I like it -14 Vote: I do not like it

    6 1 4 4 4 4 4

    Why 38 in this case in D ?

    • »
      »
      »
      3 weeks ago, # ^ |
        Vote: I like it +1 Vote: I do not like it

      How Would I Know that .

      Don't comment irrelevant ANSWERS please

  • »
    »
    3 weeks ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    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.

    • »
      »
      »
      3 weeks ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      What is the test case please.

      • »
        »
        »
        »
        3 weeks ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

        2 5 1 1 This test can make my program produce wrong answer.

        • »
          »
          »
          »
          »
          3 weeks ago, # ^ |
            Vote: I like it 0 Vote: I do not like it

          But It is showing as 'invalid' input . Please can you provide me a valid input :)

          • »
            »
            »
            »
            »
            »
            3 weeks ago, # ^ |
              Vote: I like it 0 Vote: I do not like it

            Between "2 5" and "1 1",there is a '\n'. Maybe you don't enter it.

»
3 weeks ago, # |
  Vote: I like it +1 Vote: I do not like it

6 1 4 4 4 4 4 Why 38 in this case in D ?

  • »
    »
    3 weeks ago, # ^ |
      Vote: I like it +1 Vote: I do not like it

    1 4 4 4 4 4

    take (1, 4, 4, 4, 4, 4) and spread like this (1, 4, 4) (4, 4) (4) total cost = 21

    take (1, 4, 4) and spread (1) (4) (4) total cost 9

    take (4, 4) and spread (4) (4) total cost 8

»
3 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

How to solve E?

  • »
    »
    3 weeks ago, # ^ |
      Vote: I like it +1 Vote: I do not like it

    go from top to bottom maintaining DSU for current and previous row

»
3 weeks ago, # |
Rev. 3   Vote: I like it 0 Vote: I do not like it
  • 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 .
  • »
    »
    3 weeks ago, # ^ |
      Vote: I like it +10 Vote: I do not like it

    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

    • »
      »
      »
      3 weeks ago, # ^ |
        Vote: I like it 0 Vote: I do not like it
      • 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
      • »
        »
        »
        »
        3 weeks ago, # ^ |
          Vote: I like it +3 Vote: I do not like it

        You have to press enter twice

        to make a new line.

»
3 weeks ago, # |
  Vote: I like it -13 Vote: I do not like it

I think educational rounds should be rated. I mean, they are perfectly good rounds

I 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

  • »
    »
    3 weeks ago, # ^ |
      Vote: I like it +5 Vote: I do not like it

    Oh boy, commenting without knowing codeforces tradition of downvoting.... That's gotta hurt.

    • »
      »
      »
      3 weeks ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      So, he can't write his opinion about site ? Let's remove the comments. Nobody will write their "stupid" opinions.

    • »
      »
      »
      3 weeks ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      you have anime profile

»
3 weeks ago, # |
  Vote: I like it +1 Vote: I do not like it

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).

  • »
    »
    3 weeks ago, # ^ |
      Vote: I like it +1 Vote: I do not like it

    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.

  • »
    »
    3 weeks ago, # ^ |
    Rev. 2   Vote: I like it +2 Vote: I do not like it

    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.

    • »
      »
      »
      3 weeks ago, # ^ |
      Rev. 3   Vote: I like it 0 Vote: I do not like it

      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

»
3 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

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

  • »
    »
    3 weeks ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

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

»
3 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it
  • »
    »
    3 weeks ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    I found the problem myself, incorrect max1 and max2 (JUST IGNORE THE POST)

»
3 weeks ago, # |
  Vote: I like it +3 Vote: I do not like it

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?

»
3 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

where is the editorial ?

»
3 weeks ago, # |
Rev. 3   Vote: I like it 0 Vote: I do not like it

There is a Telegram bot that informs us upcoming contests regularly

Username is @CodeForcesBot

»
3 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

Auto comment: topic has been updated by PikMike (previous revision, new revision, compare).

»
3 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

Auto comment: topic has been updated by PikMike (previous revision, new revision, compare).

»
3 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

I am confused with something.How can someone solve two problems in two seconds...