ch_egor's blog

By ch_egor, 3 weeks ago, translation, In English

Thanks for the participation!

1700A - Optimal Path was authored and prepared by 74TrAkToR

1700B - Palindromic Numbers was authored by fedoseev.timofey and prepared by _overrated_

1700C - Helping the Nature was authored and prepared by Igorbunov

1700D - River Locks was authored and prepared by Ziware

1700E - Serega the Pirate was authored by fedoseev.timofey and prepared by _tryhard

1700F - Puzzle was authored and prepared by EntitledMonkey

Tutorial is loading...
Tutorial is loading...
Tutorial is loading...
Tutorial is loading...
Tutorial is loading...
Tutorial is loading...
 
 
 
 
  • Vote: I like it
  • +82
  • Vote: I do not like it

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

D is solvable without binary search.

If $$$t_j<max(⌈pref_i/i⌉)$$$ then there is no solution.

Otherwise the answer is $$$⌈sum(v)/t_j⌉$$$.

There is my solution 161288493

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

    Yes exactly. This works because you can assume that for a prefix, each pipe provides $$$t$$$ units of water(because if any water is "wasted" then all tanks in front of that pipe are filled). Since adding more pipes in front of a pipe does not contribute to tanks before it, if $$$t$$$ is greater than the minimum time required to fill the entire thing then that assumption is valid.

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

I solved C without prefix or suffix, but the starting idea is the same.

Solution with explanation why it works: just store the difference between 2 consecutive elements in an array, a1[2] shows the difference between the 1st and the 2nd element, (note: a1[1] is equal to the 1st element).

in a1[1] we keep the number to which all the other elements will be equal to at some point(initially it is the 1st element) and after that I can make all equal to 0 by just a1[1] moves, now let's see how do we keep it. Let's have a look on 2 different cases.

1st case: we have something like 3, 4, 5 etc. In this cases the difference is positive. So I can just simply do ans += a1[i], so at 1st ans will be 1 because I need 1 move to make 4 equal to 3 and also 1 move to make 5 equal to 4, so in total 2 moves to 1st make 5 equal to 4 and then both 4 and 4 equal to 3 in just 1 move that's why this solution is optimal.

2nd case: etc we have something like 5, 4, 3 where we have a1[i] < 0, in this case we can make ans = ans — a1[i], so ans is again going to be positive, but the difference is that now we have to make a1[1] += a1[i], because since we found out that there is a smaller number then we have to make them all equal to a1[1] + a1[i] which makes a1[1] smaller since a1[i] is negative so we still get the number a1[1] which is what we make all the elements equal to.

Code link — 161258270

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

Nice Round! Finally became Specialist!

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

my solution for problem C but I am not able give some formal proof for this

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

Problem C. I understand why the given method works, but what is the proof/intuition behind the solution that the given method is minimum number of steps??

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

    My intuition: You can alter the "height" of the entire array (either decrease or increase it), so instead of trying to make the heights of all trees $$$0$$$, I tried making them equal to the first element of the array (say $$$curh$$$), and then performing operations on the entire array at the end.

    If $$$a[i] \neq a[i+1]$$$, then we would have to perform some operations to make them equal:

    • If $$$a[i] > a[i+1]$$$, then we would have to decrease the prefix ending at $$$i$$$, and we would require $$$(a[i] - a[i+1])$$$ operations. This would also decrease the height of the array behind $$$i$$$ ($$$curh$$$) by $$$(a[i] - a[i+1])$$$.
    • If $$$a[i] < a[i+1]$$$, then we would have to decrease the suffix ending at $$$i+1$$$, and we would require $$$(a[i+1] - a[i])$$$ operations. Note, this would not affect $$$curh$$$, but would decrease all elements after $$$i+1$$$ as well, so $$$a[k+1]-a[k]$$$ $$$\forall$$$ $$$(i < k < n)$$$ would be preserved.

    So, basically adding $$$abs(a[i] - a[i+1])$$$ $$$\forall$$$ $$$i$$$ to $$$ans$$$, and decreasing the $$$curh$$$ by the same amount when $$$a[i] > a[i+1]$$$, and the final answer would be $$$(ans + abs(curh))$$$.

    Code — 161312307

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

      Exuse me, may I ask a question?

      Does $$$curh$$$ mean the final leval that is equal all the height of the trees

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

        $$$curh$$$ is the current height of the prefix of trees at $$$i$$$, that we have made equal in height as we move from $$$1$$$ to $$$n$$$, but yeah at $$$n$$$ it would be equal to the height of all trees.

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

          Thank you very much. Your solution is very helpful to me.

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

How is this pref[i]/i coming, I understand that if all i-1 are filled, then each second i unit of water falls into ith one. But the the i-1 vessels would not be filled simultaneously, may be (i-1) gets filled first and some amount falls from that to ith one, I mean it's vaguely clear how it's coming but i dont feel any strong maths , can anyone please explain

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

    My approach is a bit different from the editorial (greedy), but it involved $$$(pref[i]/i)$$$.

    So basically, $$$ \forall$$$ $$$i$$$ from $$$1$$$ to $$$k$$$ where $$$k$$$ is the number of taps you would open, we would need $$$(time \times i) \geq pre[i]$$$ so that the $$$i^{th}$$$ lock can be filled, where $$$(time \times i)$$$ is the volume that first $$$i$$$ taps would fill, and $$$pre[i]$$$ is the total volume of first $$$i$$$ locks. Which is equivalent to $$$time \geq \lceil pre[i]/i \rceil$$$. Instead of iterating through first $$$k$$$ elements of $$$pre[i]$$$ every query, we can store prefix max of $$$\lceil pre[i]/i \rceil$$$ and check if $$$time \geq max(\lceil pre[i]/i \rceil )$$$.

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

    See, keep it simple.

    pref[i] is the total volume capacity to be filled if we only consider the 1st i vessels. To get the minimum time to fill all i vessels, we open all the i taps. Each tap ejects 1 unit/sec. So minimum time required to fill all i vessels is at least pref[i] / i. ( I am not saying that min time = pref[i]/i, but it is lower bounded by pref[i]/i. )

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

I didn't understand why above method works in problem no. C Can anyone please explain me what is the intuition behind the solution why it works?

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

If you are/were getting a WA/RE verdict on problems from this contest, you can get the smallest possible counter example for your submission on cfstress.com. To do that, click on the relevant problem's link below, add your submission ID, and edit the table (or edit compressed parameters) to increase/decrease the constraints.

If you are not able to find a counter example even after changing the parameters, reply to this thread (only till the next 7 days), with links to your submission and ticket(s).

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

In problem no. C Here is my understanding

lets take a example a = [1, -2, 3, -4, 5]

  1. now we want convert this array into such an array where every element is same whether it is 0 or not;
  2. there is one clue here is that while dec or increasing the diff bw elements will remain same.

so lets prepare an array of diff b where b[i] = a[i] — a[i-1]; b = [1, -3, 5, -7, 9]

lets initialize our res = 0;

now for a[0], a[1] we want to make this 2 element equal. how can we do that ? if -> 1st element is less than 2nd element we will perform dec operation on right side of the array else -> we will perform dec operation on left side of the array

so for a[0], a[1] diff is b[1] = -3 (a[0] < a[1]); so we have to dec left side of array by 3 units ( res += 3 units); now a[0] and a[1] will be equal to -2 so we will update b[0] = -2 because in the end we have to make every element to 0;

and for a[1] and a[2] diff = 5 a[2] > a[1] so we have to dec right side of array by 5 units since diff will remain same bw elements so we don't have to bother for actual number (res += 5 units) since right side will dec so no need to update b[0]

now after perfoming all the operation every element will be equal to updated b[0]; and at last we will do (res += abs(b[0]);

This is My Solution — 161315402

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

Please add this editorial in the Contest materials.

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

Could someone figure out why my submission to E is getting TLE on test case 48? I suspect that it has something to do with the sets I'm using inside my loop, but I'm not sure. I've tried pruning it for a while, but to no avail. Help would be appreciated! Submission to E

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

    Nevermind, I figured out why. :')

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

Problem E.

Example #2:

2 3

1 6 4

3 2 5

$$$6>4$$$ and $$$5>4$$$ , so "4" is bad cell. But if we choose 4 , there isn't any valid way to make the puzzle solvable.Then we will get wrong answer "2" .

Did I get it wrong ? Thx.

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

    We can choose not only the bad cell itself, but also its neighbour to make it not bad. In this example, we can choose 4's neighbour 6 and swap it with 2, then we find a way only swap once.

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

Hello sir, To be honest, I cheated in this contest (#802) by copy pasting code from Telegram, why I didn't get booked for plagiarism? Is the Codeforces Plagiarism checker down? Or the ratings yet to be updated? I politely request you to please reduce my rating in my other account for my crimes. Kindly look into this.

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

    Hello sir, To be honest, I cheated in this contest (#802) by copy pasting code from Telegram, why I didn't get booked for plagiarism? Is the Codeforces Plagiarism checker down? Or the ratings yet to be updated? I politely request you to please reduce my rating in my other account for my crimes. Kindly look into this.

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

      Hello sir, To be honest, I cheated in this contest (#802) by copy pasting code from Telegram, why I didn't get booked for plagiarism? Is the Codeforces Plagiarism checker down? Or the ratings yet to be updated? I politely request you to please reduce my rating in my other account for my crimes. Kindly look into this.

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

Bit confused by this statement in the editorial for question div2 C:

Let's calculate the final array using prefix and suffix sums for $$$O(n)$$$. Note that it will consist of the same numbers. Add $$$|x|$$$ to the answer, where $$$x$$$ is the resulting number.

How are the prefix and suffix sums used to compute the final array? And what is $$$|x|$$$?

Thank you.

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

    In my opinion, you can solve the problem in this way.

    Use an integer $$$a$$$ to save the minium number of operations to "cut" the trees in the same height . Consider that when you meet a "new" tree which has a height of $$$h$$$. There are two conditions.

    • If $$$h \le a$$$, you have to decrease the height of all the "old" trees to $$$h$$$( use $$$a - h$$$ operations), and change the value of $$$a$$$ to $$$h$$$.
    • Otherwise you only have to decrease the height of the "new" trees $$$h - a$$$ times, and you don't have to change the value of $$$a$$$

    We can find that in both situations, you have to operate $$$|h - a|$$$ times (This is the reason to add $$$|h - a|$$$ to the answer, $$$|h - a|$$$ is the $$$x$$$ in the official solution.

    In the end, you should add |a| operations to decrease / increase all the height to 0.

    This is my code:161360992

    Thanks to user AAK who told me this method.

    I'm sorry that I am not good at using English to write articals. I hope this message will help you.

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

.

»
10 days ago, # |
  Vote: I like it 0 Vote: I do not like it

In C prblm , how did ch_egor come up with Difference Array ? What's the intuition behind it ?

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

I understand the solution that the editorial proposes for C, but why is that optimal? Is there some sort of semi-formal proof one can create? I'm having a hard time understanding why it's optimal.

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

For C, here is how I understand the proof for optimality.

We know that in the final state of (0,0..,0,0), the sum of all |d_i| = |a_{1}-a_{0}| + ... + |a_{n}-a_{n-1}| equals 0.

Now for each step of the operation, any of the 3 operations allowed can only change 1 of the n |a_{i+1}-a_{i}|. For example, given (a_{1},a_{2}...,a_{d-1},a_{d}, a_{d+1}, ...a_{n}), if we decrement (a_{d},...a{n}) by 1, then only |d_{d}|=|a_{d}-a{d-1}-1| changes, while the rest of |d{i}| stays the same.

Since the solution is designed in such a way to decrease each of the |d_{i}| to 0 sequentially, (ie |a_{1}-a_{0}| + ... + |a_{n}-a_{n-1}| is a decreasing sequence), it is clearly optimal.

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

For completeness, here is how the path in question A is optimal.

For any other path selected, there must be an instance of (i,j) -> (i+1,j) -> (i+1,j+1), of which cost could be reduced if we had opted for (i,j) -> (i,j+1) -> (i+1,j+1) instead,

If we replaces all such instances to reduce the cost of any given path, we will end up with the optimal for which there is no more such instances, and so the cost is minimised.