Блог пользователя cyand1317

Автор cyand1317, история, 6 лет назад, По-английски

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!

Разбор задач Codeforces Round 487 (Div. 2)
  • Проголосовать: нравится
  • +144
  • Проголосовать: не нравится

»
6 лет назад, # |
  Проголосовать: нравится +23 Проголосовать: не нравится

Editorial is cool like announcement!

»
6 лет назад, # |
  Проголосовать: нравится +51 Проголосовать: не нравится
A bit simpler C solution picture
»
6 лет назад, # |
  Проголосовать: нравится +15 Проголосовать: не нравится

Super fast editorial !

»
6 лет назад, # |
Rev. 3   Проголосовать: нравится +2 Проголосовать: не нравится

Can anyone please explain the solution for C in English?

Edit: I believe I understand now. Thanks!

  • »
    »
    6 лет назад, # ^ |
      Проголосовать: нравится +1 Проголосовать: не нравится

    Just replace the one-cell components with their surroundings. Sorry for not making this clear.

»
6 лет назад, # |
  Проголосовать: нравится +23 Проголосовать: не нравится

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

»
6 лет назад, # |
  Проголосовать: нравится +26 Проголосовать: не нравится

Really enjoyed today's contest, thank you cyand1317

»
6 лет назад, # |
  Проголосовать: нравится +50 Проголосовать: не нравится

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

67 characters
»
6 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

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?

  • »
    »
    6 лет назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    no

  • »
    »
    6 лет назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    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.

    • »
      »
      »
      6 лет назад, # ^ |
      Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

      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 ?

      • »
        »
        »
        »
        6 лет назад, # ^ |
          Проголосовать: нравится +1 Проголосовать: не нравится

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

»
6 лет назад, # |
  Проголосовать: нравится +20 Проголосовать: не нравится

My solution to C:

»
6 лет назад, # |
Rev. 2   Проголосовать: нравится -11 Проголосовать: не нравится

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

  • »
    »
    6 лет назад, # ^ |
    Rev. 2   Проголосовать: нравится -38 Проголосовать: не нравится

    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.

  • »
    »
    6 лет назад, # ^ |
      Проголосовать: нравится +14 Проголосовать: не нравится

    This is known as a vacuous truth.

»
6 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

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

»
6 лет назад, # |
Rev. 2   Проголосовать: нравится +17 Проголосовать: не нравится

Ques C was Interesting.Good Contest this. cyand1317.

»
6 лет назад, # |
Rev. 2   Проголосовать: нравится +11 Проголосовать: не нравится

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

  • »
    »
    6 лет назад, # ^ |
      Проголосовать: нравится +11 Проголосовать: не нравится

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

    • »
      »
      »
      6 лет назад, # ^ |
        Проголосовать: нравится 0 Проголосовать: не нравится

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

      • »
        »
        »
        »
        6 лет назад, # ^ |
          Проголосовать: нравится 0 Проголосовать: не нравится

        No, it shouldn't.

        • »
          »
          »
          »
          »
          6 лет назад, # ^ |
            Проголосовать: нравится 0 Проголосовать: не нравится

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

          • »
            »
            »
            »
            »
            »
            6 лет назад, # ^ |
              Проголосовать: нравится +1 Проголосовать: не нравится

            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.

            • »
              »
              »
              »
              »
              »
              »
              6 лет назад, # ^ |
                Проголосовать: нравится 0 Проголосовать: не нравится

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

              • »
                »
                »
                »
                »
                »
                »
                »
                6 лет назад, # ^ |
                  Проголосовать: нравится 0 Проголосовать: не нравится

                Sorry, it should be .

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

»
6 лет назад, # |
  Проголосовать: нравится +1 Проголосовать: не нравится
my solution for C
»
6 лет назад, # |
Rev. 5   Проголосовать: нравится +30 Проголосовать: не нравится

My solution on C with input

100 100 100 100

not fine,but can accepted! :)

pic
»
6 лет назад, # |
Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится
My C solution's picture

Thanks for your efforts :)

»
6 лет назад, # |
Rev. 2   Проголосовать: нравится +35 Проголосовать: не нравится

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

Picture
»
6 лет назад, # |
  Проголосовать: нравится +22 Проголосовать: не нравится

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

»
6 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

hope every time editorial is this quick

»
6 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

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"

  • »
    »
    6 лет назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

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

    • »
      »
      »
      6 лет назад, # ^ |
        Проголосовать: нравится +3 Проголосовать: не нравится

      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.

»
6 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

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!!!

  • »
    »
    6 лет назад, # ^ |
    Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

    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!

»
6 лет назад, # |
  Проголосовать: нравится +7 Проголосовать: не нравится

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

  • »
    »
    6 лет назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

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

»
6 лет назад, # |
  Проголосовать: нравится +38 Проголосовать: не нравится

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

  • »
    »
    6 лет назад, # ^ |
      Проголосовать: нравится +13 Проголосовать: не нравится

    Nice insight! This can be modified to achieve 577.

    Hope this makes sense...
    • »
      »
      »
      6 лет назад, # ^ |
        Проголосовать: нравится 0 Проголосовать: не нравится

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

      • »
        »
        »
        »
        6 лет назад, # ^ |
          Проголосовать: нравится +5 Проголосовать: не нравится

        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.

    • »
      »
      »
      6 лет назад, # ^ |
        Проголосовать: нравится 0 Проголосовать: не нравится

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

»
6 лет назад, # |
  Проголосовать: нравится +7 Проголосовать: не нравится

(2018-06-12_050251.jpg)

»
6 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

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(?)

  • »
    »
    6 лет назад, # ^ |
      Проголосовать: нравится +8 Проголосовать: не нравится

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

»
6 лет назад, # |
Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

Mine is a little bit too complicated.

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

cries

»
6 лет назад, # |
Rev. 3   Проголосовать: нравится +12 Проголосовать: не нравится

my solution

»
6 лет назад, # |
Rev. 3   Проголосовать: нравится +2 Проголосовать: не нравится

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

»
6 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

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!

  • »
    »
    6 лет назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

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

»
6 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

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

  • »
    »
    6 лет назад, # ^ |
    Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

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

    • »
      »
      »
      6 лет назад, # ^ |
        Проголосовать: нравится +3 Проголосовать: не нравится

      Okay , I didn't know that , thanks

      • »
        »
        »
        »
        6 лет назад, # ^ |
        Rev. 4   Проголосовать: нравится 0 Проголосовать: не нравится

        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 ^_^.

        • »
          »
          »
          »
          »
          6 лет назад, # ^ |
            Проголосовать: нравится +3 Проголосовать: не нравится

          thanks for the solution :)

        • »
          »
          »
          »
          »
          6 лет назад, # ^ |
            Проголосовать: нравится +3 Проголосовать: не нравится

          Quite close — try this :)

          5 3
          0..00
          
          • »
            »
            »
            »
            »
            »
            6 лет назад, # ^ |
              Проголосовать: нравится 0 Проголосовать: не нравится

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

»
6 лет назад, # |
Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

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

  • »
    »
    6 лет назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    plz explain the problem

    • »
      »
      »
      6 лет назад, # ^ |
      Rev. 6   Проголосовать: нравится 0 Проголосовать: не нравится

      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.

»
6 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

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

  • »
    »
    6 лет назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    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

»
6 лет назад, # |
  Проголосовать: нравится +8 Проголосовать: не нравится

The idea is simple:

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

»
6 лет назад, # |
Rev. 3   Проголосовать: нравится 0 Проголосовать: не нравится

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(

»
6 лет назад, # |
  Проголосовать: нравится +9 Проголосовать: не нравится

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

»
6 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

My sol for C 100 100 100 100

Spoiler

sol for 1 1 1 1

Spoiler
»
6 лет назад, # |
  Проголосовать: нравится +8 Проголосовать: не нравится

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

»
6 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

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

Rua~ cyand1317

»
6 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

My simple solution! INPUT: 77 33 22 144

»
6 лет назад, # |
  Проголосовать: нравится +1 Проголосовать: не нравится

no time to read the story...

»
6 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

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

»
6 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

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

»
6 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

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?

»
4 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

 So cool!! I love this author!