cyand1317's blog

By cyand1317, history, 2 months ago, In English,

Selamat petang!

The curtain has fallen on Codeforces Round #487 (Div. 2). Have you enjoyed the problems themselves? Or the stories? Or both? Neither?

I hadn't ever intended to create a hard contest, believe me... (╥﹏╥) The author will try to find ways to estimate the difficulty better in the future. Also, stronger pretests, notes taken.

Anyways, hope you've all enjoyed the challenges you've faced, and gained something from this round. Congratulations to those who performed well, and commiserations to those waiting for their next chance to shine (^_−)−☆

Below are the tutorials of all problems. Feel free to point out mistakes (if any) or share your ideas in the comments! I might be overcomplicating or confusing something > <

Tutorial is loading...
Short Ruby solution
Tutorial is loading...
Noam's C++ solution
Python solution for the original problem as well as for the last challenge
C++ seemingly-brute-force solution
Tutorial is loading...
Model solution
Tutorial is loading...
Model solution
Tutorial is loading...
Model solution

See you next time! I hope I'll be welcomed. Cheers!

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

»
2 months ago, # |
  Vote: I like it +23 Vote: I do not like it

Editorial is cool like announcement!

»
2 months ago, # |
  Vote: I like it +51 Vote: I do not like it
A bit simpler C solution picture
»
2 months ago, # |
  Vote: I like it +15 Vote: I do not like it

Super fast editorial !

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

Can anyone please explain the solution for C in English?

Edit: I believe I understand now. Thanks!

»
2 months ago, # |
  Vote: I like it +23 Vote: I do not like it

woah, rating change of 195 in just 30 hours for me.boss feeling

»
2 months ago, # |
  Vote: I like it +26 Vote: I do not like it

Really enjoyed today's contest, thank you cyand1317

»
2 months ago, # |
  Vote: I like it +50 Vote: I do not like it

Found a smaller solution for A, simply changed product to XOR in your Ruby solution ^.^

67 characters
»
2 months ago, # |
  Vote: I like it 0 Vote: I do not like it

I know that in problem C, number of components cannot exceed 100. But will your solution work for inputs like "1225 1225 1 1" if we remove that constraint?

  • »
    »
    2 months ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    no

  • »
    »
    2 months ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    It will work for large input, but the number of rows will exceed 50. The problem is designed so that there are a huge number of ways to construct an anwer.

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

      For "1225 1225 1 1", we can do it 50x50 grid. But with your solution I don't think it's possible. Can you extend your solution to work for such inputs ?

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

        I can add one special check and make a 50×51 grid just for this case (> <)

        The best solution I can come up with so far is here. I have no idea how to extend it...

»
2 months ago, # |
  Vote: I like it +20 Vote: I do not like it

My solution to C:

»
2 months ago, # |
Rev. 2   Vote: I like it -11 Vote: I do not like it

for p==n in Problem B there was no way to conclude answer is No as only about positive p the condition was mentioned. This cost me whole problem. sad wordings :(

  • »
    »
    2 months ago, # ^ |
    Rev. 2   Vote: I like it -38 Vote: I do not like it

    Yes it kind of amazes me that the setter penalizes for such a case which is ambigous.I was on the verge of solving C and then my solution got hacked due to this thing n==p and it never came to my mind that this could be the error.Really disgusting from a contestant point of view.That was shit of a testcase.

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

      ever heard of the word "edge case"?

      • »
        »
        »
        »
        2 months ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

        Yes it had been a edge case had the answer been Yes because there existed no "i" for which the constraint was valid.

        • »
          »
          »
          »
          »
          2 months ago, # ^ |
            Vote: I like it 0 Vote: I do not like it

          There is no valid i so yes it is a period. but the question asked whether it is not a period. so the answer is the opposite that is No.

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

    This is known as a vacuous truth.

»
2 months ago, # |
  Vote: I like it 0 Vote: I do not like it

Please explain C, can't really seem to get the editorialist's code also to mention the picture too!! :P

»
2 months ago, # |
Rev. 2   Vote: I like it +17 Vote: I do not like it

Ques C was Interesting.Good Contest this. cyand1317.

»
2 months ago, # |
Rev. 2   Vote: I like it +11 Vote: I do not like it

It is easier to solve D (in linear time for sorted input) if u divide points on basis of sign of x and v and u won't have to worry about fractions. http://codeforces.com/contest/989/submission/39163175

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

    Actually dividing them into two sets according to the sign of v is enough: 39187157.

    • »
      »
      »
      2 months ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      I think it should be *it > x in this line. while (it != minus.end() && (*it < x || wmax * (long long)(*it — x + l) <= abs(*it + x + l)))

      • »
        »
        »
        »
        2 months ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

        No, it shouldn't.

        • »
          »
          »
          »
          »
          2 months ago, # ^ |
            Vote: I like it 0 Vote: I do not like it

          @Jakube how did you derive the formula you used to check for valid pairs?

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

            To be honest, only by reading the editorial. I used the same formula: .

            But I don't see why the editoral then goes further distinguishing cases. From the sketch, (and the fact that the slope is less or equal than 45˚) is it really obvious that it isn't necessary. For each xu just find the first xv that satisfies the condition, and then all xw > xv automatically satisfy the condition.

            • »
              »
              »
              »
              »
              »
              »
              2 months ago, # ^ |
                Vote: I like it 0 Vote: I do not like it

              @Jakube can you explain how you derive that then? I'm confused about why it is not x_v-x_u+l on the left side, since x_v > x_u...

              • »
                »
                »
                »
                »
                »
                »
                »
                2 months ago, # ^ |
                  Vote: I like it 0 Vote: I do not like it

                Sorry, it should be .

                I just copied it from the editorial, and it seems like they have it wrong too.

                • »
                  »
                  »
                  »
                  »
                  »
                  »
                  »
                  »
                  2 months ago, # ^ |
                    Vote: I like it 0 Vote: I do not like it

                  Fixed now, thanks for pointing out.

»
2 months ago, # |
  Vote: I like it +1 Vote: I do not like it
my solution for C
»
2 months ago, # |
Rev. 5   Vote: I like it +30 Vote: I do not like it

My solution on C with input

100 100 100 100

not fine,but can accepted! :)

pic
»
2 months ago, # |
Rev. 2   Vote: I like it 0 Vote: I do not like it
My C solution's picture

Thanks for your efforts :)

»
2 months ago, # |
Rev. 2   Vote: I like it +35 Vote: I do not like it

My picture for C (test 100 100 100 100):

Picture
»
2 months ago, # |
  Vote: I like it +22 Vote: I do not like it

Thanks for this super-ultra-hyper-mega-meta-great-delicious-wonderful contest cyand1317 !

»
2 months ago, # |
  Vote: I like it 0 Vote: I do not like it

hope every time editorial is this quick

»
2 months ago, # |
  Vote: I like it 0 Vote: I do not like it

IN EDITORIAL OF E -> can you please explain this line "For each l, we should calculate the average of f(m−1)u such that the u-th point lies on l"

  • »
    »
    2 months ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    1 more ques.. IN the code of E what have u used GCD function for in struct line?

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

      GCD is used to normalize the equation of the line in order to remove duplicates. This is not the only way, though.

      The sentence above means, for example, if points A, B, C lie on a certain line l, then the final probability is if l is chosen.

»
2 months ago, # |
  Vote: I like it 0 Vote: I do not like it

My code runs perfectly okay on test 18 of B but it is giving an WA on test case 18. I am using g++ compiler on my pc. Can't understand why, since the output it produces in the test case should not be produced by program logic.

Submission link : My Submission

Any insight would be helpful.

Thanks!!!

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

    To explain why:

    diff = n — p => 1 (for n = 3 & p = 2) for (int i = 0; i < diff; ++i) runs only once flag == false (since v[0] = 1 and v[2] = 0 output is "No" which is produced by my compiler but WA on codeforces. Can't understand... PLEASE HELP!

»
2 months ago, # |
  Vote: I like it +7 Vote: I do not like it

Here's my C for input 100 60 13 1

Very fun question, good job cyand1317 :)

(My solution handles 1 ≤ a, b, c, d ≤ 145.)

  • »
    »
    2 months ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    This is the simplest to understand of all solutions but maximum number of components can only be 145 :)

»
2 months ago, # |
  Vote: I like it +38 Vote: I do not like it

With a pattern like this you can handle cases with a,b,c,d <= 385.

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

    Nice insight! This can be modified to achieve 577.

    Hope this makes sense...
    • »
      »
      »
      2 months ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      Does this eating strategy really work? Because you eat almost the same number of two colors.

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

        In the top-left area we have only eaten blue ones. It should be easy to eat yellow and pink ones then.

        We can do this for each area separately, eating an arbitrary number of each colour, so I think it does work.

    • »
      »
      »
      2 months ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      You can also use the middle vertical strip. Then you can do a,b,c,d<=600

»
2 months ago, # |
  Vote: I like it +7 Vote: I do not like it

(2018-06-12_050251.jpg)

»
2 months ago, # |
  Vote: I like it 0 Vote: I do not like it

problem D 2 10 100 2 1 1 -1 answer should be 1 but the standard puts 0 it shouldn't be xu<xv but xu<xv+l(?)

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

    In the problem, no clouds should intersect at the beginning. The model solution doesn't handle cases where they initially intersect.

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

Mine is a little bit too complicated.

A = 100, B = 90, C = 70, D = 50

cries

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

my solution

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

For those looking for an idea to solve problem C, this is a really simple solution. Feel free to check my submission if you want. The code works fine even for a,b,c,d <= 300. This is the case where A = B = C = D = 100 :)

»
2 months ago, # |
  Vote: I like it 0 Vote: I do not like it

Thanks to the writer! I love this contest!

»
2 months ago, # |
  Vote: I like it 0 Vote: I do not like it

My solution to E is actually in O(n4 + 30n3 + qn3)-time, where 30 is the laziness cutoff mentioned in the editorial. It passed the system test just because I was lucky :) http://codeforces.com/contest/989/submission/39167167

I enjoyed this contest very much. Thanks!

  • »
    »
    2 months ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    You are excellent!! I also know a strange solution..

    Because of the convergence of probability , we can make the mi no more than 60 .

    So we can get the probability by dp and brute force. And it can also pass the system test with high speed.

    Forgive my poor English...

»
2 months ago, # |
  Vote: I like it 0 Vote: I do not like it

http://codeforces.com/contest/989/submission/39180094 This is my solution for Div 2-B , I think it will also work for bonus-3(n<=10^5), but I am not sure,please correct me if i am wrong .

Thanks in advance :)

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

    You need, in bonus.3, to cope also with bonus.2.

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

      Okay , I didn't know that , thanks

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

        Sorry if I misunderstood you ^_^. I meant by my reply that not just the constraint on range of n was added in bonus.3, but also they added that you need to print the lexicographically minimum string if the answer is not NO.

        And as I saw from your code, it doesn't cope with bonus.3, because it doesn't print the "lexico. mini."

        And for solving this, I suggest to replace each '.' with '0' (after making sure that the answer is not NO) then iterate over the string from index 0 to n - p - 1 (inclusive) (indexing from 0) to see if there is an index i that setisfy s[i]! = s[i + p].

        If there is, then this is the answer, because we shouldn't change any character other than the dots and this string is not p-periodic.

        If no, we should iterate over the string from right to left, and the first index we see and it was a dot before replacing dots with zeros, we should change it to '1', and the resulting string is the answer.

        Hode my answer is correct :)

        Please cyand1317, judge this solution for bonus.3 in problem B ^_^.

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

          thanks for the solution :)

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

          Quite close — try this :)

          5 3
          0..00
          
          • »
            »
            »
            »
            »
            »
            2 months ago, # ^ |
              Vote: I like it 0 Vote: I do not like it

            True. I need when I iterate from right to left to check for the first index i that setisfies both following two condition:

            1) i in [0, n - p - 1] or [p, n - 1].

            2) s[i] = '.' before the replacement.

            True?

            Thank you very much :)

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

Problem E turns out to be an exact Markov chain problem xD

  • »
    »
    2 months ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    plz explain the problem

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

      let

      each entry represent the probability (ex : 1 → 2 is the probability of going from 1 to 2)

      Then, A2 =

      (this one is bit hard to recognize, by the way.)

      By generalization,

      where ... can be any sequence of n - 1 vertices

      The answer is MAXline(sum - of - the - (row, column)[Mline * Am - 1]) where Mline is initial state of for each line and (row=index of vertices belongs to initial line), (column=vertex index of destination) (i'm sorry this must be hard to understand, but this is my best explanation) (and with some optimizations originally written in editorial)

      You can google 'markov chain' for much more elegant explains.

»
2 months ago, # |
  Vote: I like it 0 Vote: I do not like it

Can someone please explain the solution (visualization) of problem D.

  • »
    »
    2 months ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Think x axis as position and y axis as time. then,

    For moon, x = yw

    For cloud with speed s, x = sy + xo and x = sy + xo + l where s is 1 or -1

»
2 months ago, # |
  Vote: I like it +8 Vote: I do not like it

The idea is simple:

Implementation is here: http://codeforces.com/contest/989/submission/39190964

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

solution for (100 100 100 100) Full code at — http://codeforces.com/contest/989/submission/39193422 Interesting problem!! :)

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

http://codeforces.com/contest/989/submission/39194022

With a slight change, up to 183 zones of each color will work, giving out a table of 50 * 48

My solution for "100 100 100 100":

Output

My solution for "50 30 25 10":

Output

Maybe in future I make it in images, but now it only text(

»
2 months ago, # |
  Vote: I like it +9 Vote: I do not like it

In problem D editorial: "For a pair of rightwards-moving cloud u and leftwards-moving cloud v, their intersection in the diagram has a top corner of ... ", is y coordinate correct? I think it should be (x_v + l — x_u) / 2 instead of (x_u — x_v + l) / 2 (x_u < x_v, right?)

»
2 months ago, # |
  Vote: I like it 0 Vote: I do not like it

My sol for C 100 100 100 100

Spoiler

sol for 1 1 1 1

Spoiler
»
2 months ago, # |
  Vote: I like it +8 Vote: I do not like it

cyand1317 Sir, I know basic programming like i am able to solve Div2 A,B, C(sometimes)...... Can you tell me what all topics(and from where) i should do to improve so that i will be able to solve div2 C and Div2 D much easily....... Thankyou...

»
2 months ago, # |
  Vote: I like it 0 Vote: I do not like it

I love your D, such a cuuuuuuute and beeeeeeeeeautiful idea!

Rua~ cyand1317

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

    Thaaaaaaank yooooooooou!

    It's not duliu! Not ever! > <

    • »
      »
      »
      2 months ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      Surely not DuLiu, it's kinda standard of neat and fresh problems.

»
2 months ago, # |
  Vote: I like it 0 Vote: I do not like it

My simple solution! INPUT: 77 33 22 144

»
2 months ago, # |
  Vote: I like it +1 Vote: I do not like it

no time to read the story...

»
2 months ago, # |
  Vote: I like it 0 Vote: I do not like it

Super cool contest.!! This contest helped a lot of participants to improve their ratings as the questions were well-framed and logical.

»
2 months ago, # |
  Vote: I like it 0 Vote: I do not like it

Bonus. D Solve for intervals of various lengths, with possible intersection at the beginning.

»
2 months ago, # |
  Vote: I like it 0 Vote: I do not like it

I get wrong answer in Pro E for Error of accuracy, and my 1.5 hours run out. Maybe we should pay more attention to the calculation of plane geometry...

»
2 months ago, # |
  Vote: I like it 0 Vote: I do not like it

For problem E instead of taking average I did

cases:

1) M turns starting from point in S 2) First turn from point not in S + M-1 turns starting from point in S

and I took max of resulting vector

It seems precision is worse, and it failed seventh test case by 7*10^-6 (error margin is 10^-6). Now is it just precision problem or is there some logical error. And how to improve the accuracy?