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

Автор sevlll777, история, 3 года назад, перевод, По-русски

Спасибо за участие!

1872A - Two Vessels

Разбор
Решение

1872B - The Corridor or There and Back Again

Разбор
Решение

1872C - Non-coprime Split

Разбор
Решение

1872D - Plus Minus Permutation

Разбор
Решение

1872E - Data Structures Fan

Разбор
Решение

1872F - Selling a Menagerie

Разбор
Решение

1872G - Replace With Product

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

»
3 года назад, скрыть # |
 
Проголосовать: нравится +11 Проголосовать: не нравится

Спасибо за разбор

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

why are we taking ceil in problem A?

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

    because if we take floor or don't take anything we will not be considering the residue.

    Residue here means , for example taking a = 5, b = 18, c = 5. Therefore after the first pour we will have a = 10, b = 13, c = 5

    Now the residue is 3lt but since c = 5 we cannot pour another full bucket of c thus we will be pouring the residue ( remaining 3lt with c ) thus we have to take ceil to consider this residue or rather we could say in a case where the final water transfer of quantity less than the value of c

    I hope you understood it

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

Does anyone have a solution to problem E through a segment tree?

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

222359696 I had somewhat similar thinking process in D, however, my way of calculation led to imprecise numbers where there were lots of digits. But why exactly? Test 4 failed because there were differences in the 17th tenth lol.

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

    In Python the / operator is float division, even if your result could be an integer, even something dumb like:

    >>> print('{:f}'.format(100000000000000000000000/1))
    99999999999999991611392.000000
    

    When you do int() it's already too late! replace / with //, the integer division operator, in the score calculation in your solution, it makes your solution work.

»
3 года назад, скрыть # |
 
Проголосовать: нравится +31 Проголосовать: не нравится

For problem G, let's say we want to find under what conditions it is optimal take the product of a subarray .

Suppose we have a prefix product equal to $$$p$$$ at index $$$i$$$ and we are considering joining this product to a $$$ \gt 1$$$ element at index $$$j \gt i$$$ to take the product. In the worst case, we have the array $$$A = [p, 1, ..., 1, 2]$$$ with $$$n - 2$$$ ones in between the first and last element.

For the product to be optimal: $$$2 * p \gt p + (n - 2) + 2 \Rightarrow p \gt n$$$, so the total product ($$$2 * p$$$) must be strictly bigger than $$$2n$$$ as mentioned in the tutorial.

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

For problem F, can someone please find the scenario where this submission is failing? 222376285

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

problem A ,why 2*c ?

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

Good problem and fast editorial, Thanks for this contest!

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

We can make the bound even better ( although not needed ) for problem G. We shall first exclude all prefix and suffix ones to get new array. If we include all elements of this new array , the answer is atleast P ( product of all elements ) — 2 * 10^5*10^9 ( here by answer I mean product(subarray(l,r)) — sum(subarray(l,r)) as we are maximizing it.). Which means it is atleast P — 2^48. Now any subarray other than this full array will have product at most P / 2. so answer for any subarray is atmost P / 2. Now , P — 2 ^ 48 >= P / 2 implies P >= 2 ^ 49. hence we can check if P >= 2 ^ 49 ( instead of 60 . )

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

Alternate thought process of Problem A:

WLOG assume, a<b (otherwise swap a and b) let m = (a+b)/2, now we need to pour water from vessel B to vessel A such that both vessel contain 'm' unit of water. We can only think in terms of vessel B (vessel A will be automatically handled). So we need to transfer (b-m) water from vessel B (to vessel A). Each time we can pour almost 'c' unit.

So ans = ceil ((b-m)/c)

My submission:222221006

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

Silly me has written a lazy segment tree for E.

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

problems were well balanced thank you for the contest

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

Editorial solution for problem G TLE on test 61

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

I'm new to CP. I used codeforces for 10 days, a few months ago, to improve my implementation skills. But the thing is, I can't solve questions like C (the gcd one). Since I'm new to cp, I wouldn't mind if I can't solve the D or above problems. I really want to learn how to solve math problems. Like it's so hard. I feel like it's totally different from my college-level math. Though they are all very basic math problems, I can't solve them on codeforces or codechef. I try to solve a math problem (div2/3 A) but when I look at the editorial, it's just only an equation. Can anyone suggest some resources to learn how to solve these gcd, prime numbers, combinatorics, kind of math problems on codeforces?? I'm gonna take cp seriously from now.

Thank you!

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

Thanks for the tutorial.

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

222445465 does anyone know why i am getting runtime error in this code?

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

For G, there probably be a roughly prof: say we have a1(>1), 1, 1, 1,... (we have x ones), P1(products of remaining numbers), so if we left a1 the result will be a1 + x + P1, otherwise it's P1 * a1. Then a1+x+P1-P1*a1=(1-a1)*P1+a1+x, because P1 is large enough, and a1>1, a1+x+P1-P1*a1 will always < 0, so a1+x+P1 < P1*a1.

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

Why is there inconsistency in the rating change mentioned in friends standing and the friends rating change? My rating change displayed in the last column of friends standing and in friends rating change are different.

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

Interesting div.3 contest.

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

How to solve problem E if instead of finding XOR of elements we had to find sum?
Calculate the value of the bitwise XOR of the numbers ai for all indices i such that si=g
Here, instead of bitwise XOR, we had to calculate sum.

How to solve F if an animal was afraid of more than one animal?

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

1599 is like a clown. Please, give me one extra point༼ つ ◕_◕ ༽つ.

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

Wow, problem D has been explained amazing

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

Problem F can be solved using std::multiset. My solution is here

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

Is this arithmetic progression formula useful here? Sn = n/2((2 * a)+ (n — 1) * d) I got wrong answer on testcase 4 here is my submission: https://mirror.codeforces.com/contest/1872/submission/222426491

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

Simple Neat and Clean code for Codeforces Round 895 (Div. 3)

KrishnaSh1355

Solutions:

Problem A : 1872A - Two Vessels Submission A : 222226952

Problem B : 1872B - The Corridor or There and Back Again Submission B : 222235441

Problem C : 1872C - Non-coprime Split Submission C : 222275700

Problem D : 1872D - Plus Minus Permutation Submission D : 222260066

Problem E : 1872E - Data Structures Fan Submission E : 222285746

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

I don't understand A. Why is it 2*c, why not c, 3c, 4c??

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

    We want $$$a=b$$$, then let's say $$$a \lt b$$$. So $$$a+x=b-x$$$ (take $$$x$$$ from bigger one to small one).

    $$$2x=b-a \rightarrow x = \frac{b-a}{2}$$$.

    Ok, in one operation you can only add $$$c$$$ to $$$x$$$, then answer is $$$\lceil \frac{x}{c} \rceil$$$.

    $$$x$$$ may not be an integer, so use this trick: $$$\lceil \frac{x}{y} \rceil = \lceil \frac{k \cdot x}{k \cdot y} \rceil$$$, answer is $$$\lceil \frac{2x}{2c} \rceil$$$ or $$$\lceil \frac{4x}{4c} \rceil$$$ or $$$\lceil \frac{2n \cdot x}{2n \cdot c} \rceil$$$.

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

    Example:

    if(a > b) swap(a,b);
    ll koef = 50;
    ll x = (koef / 2) * (b - a);
    ll y = koef * c;
    cout << (x + y - 1) / y;
    
»
3 года назад, скрыть # |
 
Проголосовать: нравится +3 Проголосовать: не нравится

Lovely F :))

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

Really good problems, thanks authors

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

for problem E ,1e15 or 2^60 or 2^48 are very loose bounds .It seems to me that the solvers that passed the test cases didnot actually solve the problem.Nobody here has comeup with such bound .I actually want to understand the problem.

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

whats wrong in my code for problem D ,in test case 3 it fails at one particular case . Can anyone tell whats the mistake ? https://mirror.codeforces.com/contest/1872/submission/223526983

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

Why is sample test 3 for problem F correct?

Input
Output

With this output the money you get is 31, but if the output is:

Other output

The money is 32. What?

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

    1 is afraid of 2
    2 is afraid of 1
    3, 4, 5 are afraid of 1

    Maximum cost will be 31:

    For 4, cost will be 2*1 = 2 -> because 1 is still not sold

    For 5, cost will be 2*1 = 2 -> because 1 is still not sold

    For 1, cost will be 2*9 = 18 -> because 2 is still not sold

    For 2, cost will be 1*8 = 8 -> because now 1 is sold and 2 is not afraid of any animal

    For 3, cost will be 1*1 = 1 -> because now 1 is sold and 3 is not afraid of any animal

    Total = 2 + 2 + 18 + 8 + 1 = 31

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

why my code is giving wrong output?

Submission Link Problem G

»
23 месяца назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

I solved problem F using the same logic as the editorial but am getting a MLE, could someone explain what is the bottleneck in this code 265848420

»
7 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

In problem E, I learn very basic and nice concept that i use XOR as prefix , suffix. Nice problem

»
5 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

I think D is easier than C