KAN's blog

By KAN, 9 months ago, translation, In English,

931A - Friends Meeting

At first understand the fact that friend should make their moves one be one and the friend who initially was left should move to the right and other friend should move to the left. Let len = |a - b|. Then the first friend will make cntA = len / 2 moves, and the second friend — cntB = len - len / 2 moves. So the answer is the sum of two arithmetic progressions cntA·(cntA + 1) / 2 and cntB·(cntB + 1) / 2.

The given constrains allowed to calculate this sums in linear time — simply iterate from 1 to cntA for the first sum and from 1 to cntB to the second.

Tutorial is loading...
Tutorial is loading...
Tutorial is loading...
Tutorial is loading...
Tutorial is loading...
Tutorial is loading...
Tutorial is loading...

Thanks GreenGrape for translation!

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

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

Oh plz, where's the tutorial for div1 E?

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

Are there other problems similar to 944D — Game with String? It is a very interesting problem and I want to practice it more. Thanks

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

Is Div. 1 D solvable by some kind of modified convex hull algorithm?

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

    I think the method mentioned by the tutorial, is just some kind of modified convex hull algorithm.

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

Anya should write the measurements equal to (min + 1) in the amount of (leftSum - minSum), Please explain what does it mean ? Thanks

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

Can someone explain Div.2C?

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

    Say you have only 0's, 1's and 2's in array.

    To preserve average you can either pick 0 and 2 and change both to 1 or pick two 1's and change one of them to 0 and other one to 2. Obviously, it makes no sense to take 0, 2 change it to two 1's and then change it back to 0 and 2 again, you won't gain anything.

    So now you pick one of the transformations 0,2 into 1,1 or 1,1 into 0,2. Pick one that gives you more numbers to change and perform transformations.

    Example:

    0 0 0 1 1 1 2 2 2 2 2

    Here, you can pick two 1's and get the array:

    0 0 0 0 1 2 2 2 2 2 2

    but that way you changed only 2 numbers. It's better to pick 0's and 2's, change them into 1's so you will get:

    1 1 1 1 1 1 1 1 1 2 2

    (notice how you have to left 2's at the end since you don't have more 0's to "balance" the change in terms of average value).

    For the next paragraph I will use this definition: cnt(x) — number of times x is present in array

    How many changes will you get from transforming 0's and 2's into 1's? min(cnt(0), cnt(2)) * 2

    How many changes will you get from transforming 1's into 0's and 2's? floor(cnt(1) / 2) * 2 (fancy way of saying cnt(1) if cnt(1) is even and cnt(1) — 1 if it's odd)

    Special cases:

    1) There are only 0's in array; there are only 0's and 1's in array — in those cases you cannot change anything (remember about the constraint that your minimal/maximal numbers have to be between minimal/maximal from original array, so you don't have any possibility for change without breaking this constraint or changing average). Obviously the same case for only 1's etc.

    2) There are 0's and 2's in array — that just reduces to transforming as many of them as you can into 1's.

    My solution:

    http://codeforces.com/contest/931/submission/35947027

    (it's not crystal clear, because of the part which actually changes the numbers in array, I guess I should have done it in different way)

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

    Find diff = 0, 1, or 2 depending on if there are 1, 2, or 3 different numbers. My solution was to look at these cases:

    • diff <= 1 means that nothing better can be done than duplicating all results.
    • diff == 2 means that we have numbers x1, x2, x3 ordered from smallest to largest. We can transform pairs of (x1,x3) into (x2,x2); and we can transform pairs of (x2,x2) into (x1,x3). Each transformation reduces the number of copied results by 2. Find the maximum number of transformations you can make between those two types of pairs.

    my solution

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

I'm wondering why there's still no tuturials for the problem Coins Exhibition. I got stuck on this problem and need help.....

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

Problem A video solution: https://youtu.be/bFEmX3y8idE Problem B video solution: https://youtu.be/tzF_nagpR5A

Problem C and D coming

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

so where is the solution of div1.E?`

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

Is the formula in a 944B problem for finding the number of (min + 1)s is correct? // leftSum — minSum ?

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

"The analysis of the last problem will soon be added."

KAN Excuse me, sir?

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

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

Plz help me why the answer of test case 45 is 50

here is my submission 36503648

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

Hello everyone.

For the problem 944 E, my code gets WA at test case 3.

This is my code- http://codeforces.com/contest/930/submission/38547479

I would like to know the error in my code.

For every index i, I'm taking the sum of longest non-decreasing subsequence ending at i, and the longest non-increasing subsequence starting at i, minus 1.