DeliciousFlatChest's blog

By DeliciousFlatChest, history, 5 years ago, In English

Good day, Codeforces! Or in my language, magandang araw, Codeforces!

Codeforces Round 597 (Div. 2) will be held on Nov/01/2019 17:35 (Moscow time). Is it rated? Yes, but only for participants below 2100 rating.

Of course, this round is not made by me alone. So, I would like to thank the following people for their help in making this round possible:

There will be 6 problems, and you will be given 2 hours to solve them.

The scoring distribution is as follows: 750-750-1250-1750-2250-2500.

I hope you enjoy the round!

Update: editorial is out now

| Write comment?
»
5 years ago, # |
Rev. 2   Vote: I like it +128 Vote: I do not like it

best round i ever tested. keima orz

»
5 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Are you the first one from Philippines to make a contest on codeforces ?

»
5 years ago, # |
  Vote: I like it -8 Vote: I do not like it

I hope I can become candidate master after this round :DDDDDDDDD

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

    I hope, that this round will be balanced, and all people get results, they needed.

»
5 years ago, # |
  Vote: I like it +91 Vote: I do not like it

After almost 3 years I am back on CodeForces and gonna participate in this round. Wish me luck!

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

    You lied. You didn't participate in this round.

»
5 years ago, # |
  Vote: I like it +18 Vote: I do not like it

It clashes with a codechef round , but after reading comments from testers ,it seems like, i should ditch that and participate here ...

»
5 years ago, # |
  Vote: I like it +10 Vote: I do not like it

I think it must be one of the best contests in Codeforces!

»
5 years ago, # |
  Vote: I like it +17 Vote: I do not like it

I wish contest has strong pretests. I don't like to take wrong answers on main tests.

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

    Whenever 300iq was taster , 193 tastcase passed and then suddenly wrong answer in tastcase 194

»
5 years ago, # |
  Vote: I like it +51 Vote: I do not like it

As a tester, I enjoyed solving problems. Well written problem statements mixed with Chinese culture. One of the problems is about a childhood game and it was completely interesting for me!

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

    how interesting would it be a D or E problem about game theory :P

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

    I hope it is not interactive, I had bad luck trying to interact with my Chinese friends' kids!

»
5 years ago, # |
  Vote: I like it +10 Vote: I do not like it

Keima915 OP, from green to orange in 7 months .. interested about the contest to start my 7 months journey :p

»
5 years ago, # |
  Vote: I like it +1 Vote: I do not like it

hope solve a,b,c

»
5 years ago, # |
  Vote: I like it +5 Vote: I do not like it

Please can anyone say me this round I wanna be specialist how many problems must I solve

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

    Like what you did in your last round.

    • »
      »
      »
      5 years ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      How can I improve? advise me something.

      I already participated 27 contests result is newbie.

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

        Always getting out of your comfort zone. And focusing on fixing your mistakes.

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

    I think you only need solve 2 problems in short time or 3 problems

    • »
      »
      »
      5 years ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      How they calculate it to be specialist?

      • »
        »
        »
        »
        5 years ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

        By your relative ranking to other people, and your previous rating vs. other people's ratings around your ranking

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

          huh.. very complicated, i will go and change the css to red.

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

         It's very trouble :<

»
5 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Expect for the constest!

»
5 years ago, # |
  Vote: I like it +4 Vote: I do not like it

I wish I can get expert in the contest again. :)

Good luck to everyone!

»
5 years ago, # |
  Vote: I like it +21 Vote: I do not like it

I m back Bois.. Had a busy October but now I am back to top the charts again.

»
5 years ago, # |
  Vote: I like it +10 Vote: I do not like it

The contestants had to face some difficulty in the previous contest due to several server failure. Though it was overcome in few seconds but its disappointing to reload the page over and over again during the contest hour. Div-2 rating changes also had to roll back because of some problems and we had to wait for several hours to get the rating changes in the last contest. Hope the authority will take care of these matters in this round.

»
5 years ago, # |
  Vote: I like it 0 Vote: I do not like it

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

»
5 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Best of luck in your first contest!

»
5 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Why first and second question has same score distribution....does that mean they have same difficulty level??

»
5 years ago, # |
Rev. 2   Vote: I like it -8 Vote: I do not like it

Hope we have a fair race :)

»
5 years ago, # |
  Vote: I like it -8 Vote: I do not like it

I hope that I can turn it into a blue name.

»
5 years ago, # |
Rev. 2   Vote: I like it -35 Vote: I do not like it

Another DISGUSTING reading contest.

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

    Reading is also a part of CP. So you should adjust yourself to read long questions. Else make the question look smaller to you. How? You figure it out ;).

    • »
      »
      »
      5 years ago, # ^ |
      Rev. 2   Vote: I like it -15 Vote: I do not like it

      I don't like to read tonns of text after hard work day. It tires the brain completely.

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

        Do you think everyone is only doing CP? Are they not tired?. Let's not make any excuses and just read the question there is no other way.

  • »
    »
    5 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Well, I guess that's just your excuse for not being able to solve problems on this contest. The statements were actually well written and short. Go practice instead of complaining.

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

      Well, I don't know if the statements were well-written but problem E's statement is definitely not short.

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

        You're right, they were well written except for E. When I saw that statement I didn't even try to read it and went for problem F.

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

strong pre test cases for problems at code forces I ever seen!!

»
5 years ago, # |
  Vote: I like it +4 Vote: I do not like it

Wrong answer on pretest 13 on problem D, No idea why. :(

Any one have idea what is going on in pretest 13 ?

»
5 years ago, # |
Rev. 2   Vote: I like it 0 Vote: I do not like it

TC 9 of problem C?

  • »
    »
    5 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Were u taking modulo when calculating the fibonacci ????

  • »
    »
    5 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    That test case got me too. I spent the last hour trying to fix whatever was wrong my fibonacci-number calculator.

    I was modding by 10^9+7 everywhere I could see, but for some reason, my 89-th and onward Fib numbers were wrong. So of course the Fib products were also wrong too. Please send help

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

      I think. You should replace ret*=fibNum(x); as ret = (ret * 1ll * fibNum(x)) % M and also temp = (temp1 * 1ll * temp2) % M;

      • »
        »
        »
        »
        5 years ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

        Not sure what the || (or? or something else...) is meant to do or what difference ret*=a vs ret=ret*a would make, care to explain?

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

    If you need help tell the approach of your solution rather than asking what was the test case. After some time you will get to know it right? :)

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

      I found out that ways to arrange characters of length i which are consecutive, can be found out by this formula,

      Pseudocode

      if(i is even) dp[i] = dp[i-1]*2 +1;
      else dp[i] = dp[i-1]*2 - 1;
      

      In my solution, i was doing like this:

       dp[0] = dp[1] = 0LL;
       dp[2] = 2LL;
       dp[3] = 3LL;
      for(int i=4;i<=sz(s);i++){
              dp[i] = (dp[i-1]*2LL)%MOD;
              if(i%2) dp[i] = (dp[i]+1LL)%MOD;
              else dp[i] = (dp[i]-1LL + MOD)%MOD;
              //cout<<i<<" "<<dp[i]<<"\n";
          }
      

      Is the problem with Modulo that i am doing? Please someone help.

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

        First of all, your first "if" statement has identical branches.(now ok)

        Secondly, dp[1] should be 1

        Thirdly, by the formula you have given dp[4] = dp[3] * 2 + 1 = 7, but actually dp[4] = 5. For example :

        intput:

        uuuu

        1.uuuu 2.wuu 3.uwu 4.uuw 5.ww

        • »
          »
          »
          »
          »
          5 years ago, # ^ |
            Vote: I like it 0 Vote: I do not like it

          Here is my output of first 10 numbers. Check once again, i think you are misreading something.

          4 5
          5 11
          6 21
          7 43
          8 85
          9 171
          10 341
          
          • »
            »
            »
            »
            »
            »
            5 years ago, # ^ |
              Vote: I like it 0 Vote: I do not like it

            dp[5] = 8 not 11

            • »
              »
              »
              »
              »
              »
              »
              5 years ago, # ^ |
                Vote: I like it 0 Vote: I do not like it

              Then how I was able to pass 8 test cases? lol

              • »
                »
                »
                »
                »
                »
                »
                »
                5 years ago, # ^ |
                  Vote: I like it 0 Vote: I do not like it

                till 8 TC,

                the continuous occurrence of n and u is not greater than 4.

            • »
              »
              »
              »
              »
              »
              »
              5 years ago, # ^ |
                Vote: I like it 0 Vote: I do not like it

              Thanks anyways, I was calculating repeating cases again and again.

              1.uuuuu  2.wuuu 3. wwu 4.wuw
                       5.uwuu 6.uww
                       7.uuwu 8.wwu
                       9.uuuw 10.wuw 11.uww
              

              where 8,10 and 11 are repeating. Wasted 1 hour thinking about something wrong with computations.

              Thank you :)

          • »
            »
            »
            »
            »
            »
            5 years ago, # ^ |
              Vote: I like it 0 Vote: I do not like it

            I calculated according to your first two lines of your comment (the if else part), you said dp[i] = dp[i-1] * 2 + 1 if i is even, maybe you have mistaken even with odd there, anyway, your formula is incorrect I guess.

»
5 years ago, # |
  Vote: I like it +17 Vote: I do not like it

how to solve D?

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

    Kruskal or Prim to find smallest tree. However the graph must be modified a little bit. Add a new node (let's say it's the power supply for the power stations) and the edge from this source to each of n nodes is equal to the cost to build a station there.

    • »
      »
      »
      5 years ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      Dont we need to make sure that there is atleast one power station? Wouldnt your approach fail when the power stations cost are really high, but the points are close by?

      • »
        »
        »
        »
        5 years ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

        However, your minimum spanning tree will also need to include the new node, which represents a sort of "super power supply" and ensures that at least one node is connected to the new node, and thus has a power station.

      • »
        »
        »
        »
        5 years ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

        Hmm? a tree is a connected graph, thus the newly added node (power supply) must belong to tree too. If the power supply is connected to node i, then you put a station at node i. Since the supply is always connected to some city because of connectedness, there is always at least one power station.

      • »
        »
        »
        »
        5 years ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

        No because we are finding a spanning tree which is connected if the original graph is connected too thus there'll be a path from the power station to every city.

»
5 years ago, # |
  Vote: I like it +25 Vote: I do not like it

What the hell was pretest 13 in D :(((

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

    Did you consider the case when $$$(x_i, y_i) = (x_j, y_j)$$$ even if $$$i!= j$$$. I think this is the mistake, I am not sure though, because I too got wrong answer on test case $$$13$$$. I didn't consider this case, so maybe this is the mistake I made.

    • »
      »
      »
      5 years ago, # ^ |
      Rev. 2   Vote: I like it +6 Vote: I do not like it

      IS it matters? Because dijkstra will take care of this fact I guess. CAn you please give the example by which you debug your code?

    • »
      »
      »
      5 years ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      I considered this case. I was not finding MST though, which I think was the expected soln

»
5 years ago, # |
  Vote: I like it 0 Vote: I do not like it

approach for problem C?

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

    I was getting some kind of fibonacci sequence

  • »
    »
    5 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    say we have len length of string of either n or u, in how many ways we can make pair in the string

    so if we make x pairs of 'n' ,we are left with len-2*x 'n' characters and we have x+1 blocks where we can fill them , so distribute len-2*x objects among x+1 persons such that each get zero or more with (len-x,x) ways

    and iterate x from 0 to len/2

  • »
    »
    5 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Any chain of U's can be broken up in fib(length) ways:

    Proof: if there are n of them: UU...U we can condition on whether to turn the first U into a W, or not: If we do, then it becomes W(U...U) (with n-2 U's) If we don't, then it becomes U(U...U) (with n-1 U's)

    Now each k-chain of U's or N's in the string has Fib(k) possible strings, so we multiply Fib(k) over all the k's

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

      Nice

      But how did you calculate the Fibonacci sequence?

      I was doing mod 1e9+7 during the calculation and I'm getting wrong answer on pretest 6

    • »
      »
      »
      5 years ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      Any chain of U's can be broken up in fib(length) ways

      How did you come up with this intuition?

      • »
        »
        »
        »
        5 years ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

        For my case...I understood this by observation, I calculated the results for the first few lengths of chain and then realized the pattern :3

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

        Consider u as 1 and w as 2 , then how many possible combinations exist such that sum is n.

        Let n = 4

        uuuu = 1 + 1 + 1 + 1

        wuu = 2 + 1 + 1

        uwu = 1 + 2 + 1

        uuw = 1 + 1 + 2

        ww = 2 + 2

        There exists 5 ways which is nothing but fib[4].

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

        I saw it in a book (Proofs That Really Count) in the first chapter. It explained that fibonacci numbers can be thought of as the number of ways to tile a 1xn grid using (unlimited) dominoes of size 1x2 and 1x1. There you condition on whether you place a rectangle or square domino in the leftmost place.

»
5 years ago, # |
  Vote: I like it +15 Vote: I do not like it

what is test case 13 in D

»
5 years ago, # |
  Vote: I like it +10 Vote: I do not like it

I thought this was an amazing round :D What lovely well framed questions

»
5 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Does problem D using Prime Algorithm? I did it but got WA on test case 4. What is TC 4 :(

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

    I think you mean the Prim Algorithm. As far as I know, yes.

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

      Yes, Prim Algorithm. Sadly, i still didn't solve it. After solving A, B, C for around 50 minutes. I came to problem D, the statement is so long and demotivate me a lot. After relaxing 10 mins, I decided to read the statement because I had 1 hour remaining time and the problem didn't hard as much as I think. If I started to solve it sooner, I would have more chances to debug. It's experiment for me. Very nice contest =)))

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

        Yeah, I understand. I was puzzled too when I saw the super long statement. Just calm down and don't be afraid of those things. I believe you can do much better in the future. Good luck!

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

          Slightly off-topic, but I love comments like this for the example they set for the CF/CP community. :')

  • »
    »
    5 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    I solved D with Prim's algo.

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

      Dijkstra?I did using Dijkstra....But I guess the algorithm is similar XD

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

        It's almost the same algorithm.

        • »
          »
          »
          »
          »
          5 years ago, # ^ |
          Rev. 2   Vote: I like it -11 Vote: I do not like it

          -is-this-fft- Is this prim?

          Code

          Edit: I need to re-order these two statements for AC. lol

          ans += tp.first;
          if(mark[tp.second.first]) continue;
          
          • »
            »
            »
            »
            »
            »
            5 years ago, # ^ |
              Vote: I like it 0 Vote: I do not like it

            It seems so

            • »
              »
              »
              »
              »
              »
              »
              5 years ago, # ^ |
                Vote: I like it -8 Vote: I do not like it

              hmm.. 13 is a devil's number i must say.

              test cases should be 1..12 and then 14..30

  • »
    »
    5 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Kruskal is fair enough

  • »
    »
    5 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Check out if you have used "long long int" instead of "int". I also got WA at test case 4, and this helped me :)

    • »
      »
      »
      5 years ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      I used long long instead of int, but It didn't solve. Btw, what is the difference between long long and long long int? are they same?

      • »
        »
        »
        »
        5 years ago, # ^ |
        Rev. 2   Vote: I like it +1 Vote: I do not like it

        Yes, they are identical.

      • »
        »
        »
        »
        5 years ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

        My situation is exactly the same as yours.Long long didn't save me.(•́ω•̀ ٥)

      • »
        »
        »
        »
        5 years ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

        Hey bro~I find a lil issue in my code,I defined a variable as int but it should be long long.Thus the program got overflow.Maybe you should check the type of each variable carefully.

        • »
          »
          »
          »
          »
          5 years ago, # ^ |
            Vote: I like it 0 Vote: I do not like it

          Thanks bro, I definitely solve it again. I have just woken up.

          • »
            »
            »
            »
            »
            »
            5 years ago, # ^ |
              Vote: I like it 0 Vote: I do not like it

            I lack of dummy city.

»
5 years ago, # |
  Vote: I like it +8 Vote: I do not like it

What is pretest 13 of D? Wasted almost half hour :(

»
5 years ago, # |
  Vote: I like it +1 Vote: I do not like it

UwU

»
5 years ago, # |
  Vote: I like it +19 Vote: I do not like it

dpforces

»
5 years ago, # |
  Vote: I like it +7 Vote: I do not like it

How to solve F?

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

    Dp with digits (in this case is binary digits).

    You have a+b = a xor b + a&b. Then a + b = a xor b if and only if a&b = 0.

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

    I pre-solved it with digit dp. Let $$$f(pos, smaller_1, larger_1, smaller_2, larger_2)$$$ be the number of way to fill the first $$$pos$$$ binary bits such that [ the first number's prefix is already smaller than $$$r$$$ ], [ the first number's prefix is already larger than $$$l$$$ ], [ the second...], [ the second...] and their prefixes have no set bits in the same position so far. The transition is not hard to come up with. The answer is the sum of all entries in $$$f(0)$$$.

    • »
      »
      »
      5 years ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      I am trying to understand your solution and transition. Could you please explain the transitions and the continue statements? I think this is a much generic approach. Thanks

      • »
        »
        »
        »
        5 years ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

        PMed you :)

        • »
          »
          »
          »
          »
          5 years ago, # ^ |
            Vote: I like it 0 Vote: I do not like it

          Could you please forward the message to me too. I am also confused as to what would be the transitions. Thanks in advance.

        • »
          »
          »
          »
          »
          5 years ago, # ^ |
            Vote: I like it 0 Vote: I do not like it

          Could you please forward the message to me too ))

»
5 years ago, # |
  Vote: I like it 0 Vote: I do not like it

I finally realized that it was problem E until I submitted my code(since mirror sites don't show the indices of problems
I fooled myself XDDDDDD

»
5 years ago, # |
  Vote: I like it +16 Vote: I do not like it

Nice round. F is a fairly common problem btw. But it is still nice :)

»
5 years ago, # |
  Vote: I like it 0 Vote: I do not like it

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

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

Nice Contest and problems.

But A was quite similar to this problem.

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

Find out why this gets WA8 (takes less than 5 seconds), i couldn't during the whole contest :DDDDDDDD

Solution

Question #2: which lines cause the trouble?

Answer
  • »
    »
    5 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Answer to #2. Because the range of index starts from 0, not 1.

»
5 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Ques.D) Shichikuji and Power Grid: In this question which concept and data structure are used. I think so Kruskal for the shortest path and DP for choosing the powerhouse or connection.

Suggest or provide some explanation, I am a beginner for this type of question.
  • »
    »
    5 years ago, # ^ |
    Rev. 2   Vote: I like it +2 Vote: I do not like it

    I used priority queue to solve.

    1. First, push the cost of setting plants at each city into priority queue along with city number.

    2. Then, start where cost of setting plant is smallest.

    3. Then push the cost making a connection from this city to every unelectrified city (along with city details) and push them into priority queue. Extract minimum cost (setting plant or making a connection) and go to step 3 (n-1 times).

  • »
    »
    5 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    My solution: Using Kruskal:

    Create all the possible edges and their weights(using formula in the statement). Sort the edges according to their weights.

    Suppose you are trying to connect the connected component U and the connected component V using the edges (x, y). Basically you have 2 options:

    • Build a power station in a city in U and a power station in a city in V (Just pick the city with less cost). You don't have to build the edge (x, y) anymore.

    • If you decide to build the edge (x, y) to connect U and V, then you have to build a power station in a city in the union of U and V. Just pick the smallest one.

    Just pick the optimal options for each edge (x, y) and add up the cost.

»
5 years ago, # |
  Vote: I like it +1 Vote: I do not like it

In A I guessed from test cases that a and b needs to be coprime, and the submission worked, But I don't get why is this correct answer. For example a = 3, b = 7 there are infinitely many numbers which are coprime to 3 as well as 7, then aren't there infinite black numbers?

  • »
    »
    5 years ago, # ^ |
      Vote: I like it +1 Vote: I do not like it
  • »
    »
    5 years ago, # ^ |
    Rev. 2   Vote: I like it +4 Vote: I do not like it

    A number $$$X$$$ will have color white iff $$$X$$$ can be written as a combination of $$$(a,b)$$$

    ==> There exists $$$k_1,k_2>=0$$$ such that $$$X=k_1*a+k_2*b$$$.

    So the numbers $$$X$$$ having color black will be the ones such that that equation has no solutions. Since that's the Diophantine Equation(to which there's either an infinite number of solutions, or there are none), having no solutions means $$$X$$$ is not a multiple of $$$gcd(a,b)$$$.

    So if $$$gcd(a,b)=1$$$ then there's no such X.

    Else there will be many; infinitely many.

»
5 years ago, # |
  Vote: I like it +23 Vote: I do not like it

D can be solved using a trick: create a virtual vertex, let's denote it as n + 1, then for every vertex connect it to (n + 1)th vertex with an edge having a weight equal to the vextex's c value. Then the problem becomes finding the MST of a given graph.

»
5 years ago, # |
  Vote: I like it +26 Vote: I do not like it

The competition was awesome !!

»
5 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Maybe I'm the only one who solve B using dp and C using 2-dimension dp (I didn't think of Fibonacci or any stuffs related to it)

»
5 years ago, # |
Rev. 2   Vote: I like it 0 Vote: I do not like it

In problem C, I was using square free Fibonacci series. But, I got WA on pretest 9. Can someone help me?? My solution

»
5 years ago, # |
  Vote: I like it +40 Vote: I do not like it

Anyone notices that there seems to be no one (at least very very few people) that fails system test. Amazing contest!

»
5 years ago, # |
Rev. 2   Vote: I like it +23 Vote: I do not like it

Damn, these 4 ms help me become a candidate master!

»
5 years ago, # |
  Vote: I like it 0 Vote: I do not like it

I converted the problem C into "how many ways you can get a sum s using coins {1,2}"..then somehow didn't able to implement it in time...Its kind of sad

  • »
    »
    5 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    That is a very nice solution.

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

      but I later figured it out that it will not work since,in counting number of ways a sum can be generated from fixed number of coins, order doesn't matters,but in our case order of selection will matter...eg. sum=3 can be generated from coin-sets {1,2} in two different ways {1,1,1} ans {1,2}(note that {1,2} and {2,1} are same) but the answer should be 3.It will convert to staircase problem counting number of ways to reach stair n if you can climb 1 or 2 stair at a time....correct me if I am wrong

»
5 years ago, # |
Rev. 2   Vote: I like it 0 Vote: I do not like it

Can someone help me with solution of D.. Here's my submission 64039124
My idea was to check if a node can be connected with any other node such that the cost for wiring is minimum and less than or equal to the cost to build a power station on that node. If such a node is available then construct an edge between them. Otherwise build a power station on that node.
Lastly, if a component has no such node which has power station in it , then build a power station that requires minimum cost in one of the node of the component..

It is generating way too much minimum cost for test case 13. I couldnt find why

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

    Try this:

    3
    1 1
    2 2
    1 3
    1 10 12
    2 3 1
    

    Ans is 15 and not 17

    • »
      »
      »
      5 years ago, # ^ |
      Rev. 2   Vote: I like it +1 Vote: I do not like it

      This solution also generates 15
      This is the output
      15
      1
      1
      2
      2 3
      3 1

  • »
    »
    5 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    The correct answer is 18

    3
    1 3
    2 1
    1 4
    10 10 3 
    1 1 8 
    
»
5 years ago, # |
  Vote: I like it 0 Vote: I do not like it

A very balanced contest with strong cases , thank you :)

»
5 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Great round! Thank you)

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

I had following idea to D. Lets make minimum spanning tree of graph with edges $$$c(i, j) = (k_i+k_j) * d(i, j)$$$ for all $$$i , j$$$. Firstly lets add the cheapest plant. Then sort edges in non-increasing order and we will try to delete every edge. If we are considering edge $$$(x,y)$$$ let $$$c_1$$$ will be component with vert $$$x$$$ of tree without edge $$$(x, y)$$$ and $$$c_2$$$ will be component with vert $$$y$$$ of tree without edge $$$(x, y)$$$. Only one of this components has installed plant now. Let it be $$$c_2$$$ . Then find cost of the cheapest plant in $$$c_2$$$ and check if its better to add plant instead of edge from spanning tree. If its better to add plant, we delete edge $$$(x, y)$$$ and add plant.

But, my solution got WA13. I will be grateful if you point out my mistake.

  • »
    »
    5 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Not entirely sure but could be that you are not using the "cost" of power plant while sorting, you are only using wiring cost while sorting? Both types of costs need to be consider.

    edges.pb(tii((k[i] + k[j]) * dist(i, j, coord), i, j));
    
    SORT(edges);
    
    
»
5 years ago, # |
  Vote: I like it +15 Vote: I do not like it

Thanks DeliciousFlatChest !

That was a good contest !

»
5 years ago, # |
  Vote: I like it +37 Vote: I do not like it

However, she died when she was only in fifth grade so she is not smart enough for this.

Wait, what codeforces?

»
5 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Has anyone solved D using dynamic programming?

»
5 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Another solution for D is the O(n^2) version of Prim's algorithm which works better on a dense graph. It doesn't need extra dummy nodes either. Is it the most efficient solution?

I solved D in this way after the round, but my implementation was slower than I expected.

»
5 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Can anyone help me with problem D. I sumbited the same code twice, and in the constest y got TLE, but after resumbitting i got AC. https://mirror.codeforces.com/contest/1245/submission/64045463 https://mirror.codeforces.com/contest/1245/submission/64035229

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

    Your AC code was just 4 ms away from TLE. It just got lucky. The execution time of the same code can differ by a few ms in different submissions. That is the reason behind TLE. Your code was not just lucky enough to get AC in contest time!

»
5 years ago, # |
  Vote: I like it +4 Vote: I do not like it

D is very much similar to this problem : https://vjudge.net/problem/LightOJ-1059

»
5 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Although the contest was very well written and prepared, but still after seeing the next contest, I am like — "Finally, a div. 3 round...., Yay!"

»
5 years ago, # |
Rev. 2   Vote: I like it +3 Vote: I do not like it

Hello my solution to problem D is either bugged or incorrect. With bugs I can cope but I worry it might be simply incorrect. It fails to pass test 13 (wrong answer).

My idea:

Firstly, take each city and make network out of it, making total n networks. Assume that every network doesn't have electricity supplied to it.

while (there exists network that doesnt have electricity supplied) {
  take any network P that doesnt have electricity supplied

  if (its cheaper to build plant inside P, than to connect P to any other network
      (OR) its impossible to connect P to any other network (there are noo other networks)) {
    build plant (cheapest possible amongst members in P) inside P supplying electricity to it
  }
  else {
    build connection between P andd other, closest possible network (closest = cheapest road)
    merging two networks into one
  }
}

I'm not worried about time complexity as above can be implemented in a fairly fast way. Just whether this should work or not.

Thanks for help in advance.

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

    Hello :)

    I didn't read your method, all I could do to help was stresstest, and I found a case where your code(I used the last submission) fails compared to my accepted solution.

    test case
    your answer
    correct answer
»
5 years ago, # |
  Vote: I like it 0 Vote: I do not like it

How are you supposed to solve D using Kruskal's Algorithm?

When I sorted the 2,000,000 edges, I got TLE on Test 7. Is this only because I used Java, or is Kruskal too slow in general for this problem?

  • »
    »
    5 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    I've heard that inbuilt sorting function in java is sometimes slow(maybe it is a quick sort variant),i do not know otherwise...

    • »
      »
      »
      5 years ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      I have a sort method that randomizes the numbers being sorted first, so that it is immune to the Quicksort TLE. I simply believe that the time constraints are a little too tough for Java, at least using Kruskal.

      I used Prim's algorithm to pass the test case in just 202 MS though.

»
5 years ago, # |
  Vote: I like it 0 Vote: I do not like it

great job I love this round too

»
5 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Can someone help me for problem B? I cannot find out where I am wrong? 64097713

  • »
    »
    5 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    The way you find the optimal sequence of moves(your string 'alice') in the case of YES is wrong.

    Try this case to find what you did wrong.

    test case
    correct answer