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

Автор harsh__h, 2 года назад, перевод, По-русски

1934A — Слишком Мин Слишком Макс

Решение
Код (C++)
Код (Python)

1934B — Еще одна задача о монетах

Решение 1
Решение 2

1934C — Найдите мину

Подсказка 1
Решение 1
Решение 2

1934D1 — Разбиение XOR — сольная версия

Подсказка
Решение
Код

1934D2 — Разбиение XOR — игровая версия

Подсказка 1
Подсказка 2
Решение
Код

1934E — Weird LCM Operations

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

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

first so ez

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

Thanks for the fast System test and fast editorial. It was a great contest and I liked problem C. I think every contest needs an interactive problem at least.

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

English editorial pls ?

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

I just refreshed the page and the text changed from English to Russian. Please fix it,thanks.

UPD:It was fixed,thanks!

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

E: First time a problem need to hardcode from n=3 to n=13

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

Problem C seems to essentially be a duplicate of a problem which I wrote in a previous DMOJ round, but with one fewer step. This is probably just a coincidence though.

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

whats the reason behind this? If coins of value 1, 3, 6 and 15 were only present the greedy logic of selecting the higher valued first would work.

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

Another solution for B is to do greedy by picking the highest possible denomination each time, but finally decrease the above answer by 0,1 or 2 depending upon the value of n mod 15.

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

https://mirror.codeforces.com/contest/1934/submission/249187805 I am not getting why is it giving idleness limit exceeded verdict

»
2 года назад, скрыть # |
Rev. 2  
Проголосовать: нравится +3 Проголосовать: не нравится
good contest..I loved C but I solved after Contest
from now...I wonot skip any interactive Problem when I practice general
»
2 года назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

The third test case of $$$D2$$$ really confused me. Why are we moving first, and why is Bob not splitting $$$10$$$ into $$$8$$$ and $$$2$$$, which should be optimal according to Bob?

Also, what is classic classic in the input?

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

For $$$D-2$$$, you can also bruteforce/precalculate the states by checking every $$$n$$$ : $$$a$$$, $$$b$$$ transition since $$$n$$$ is atmost $$$60$$$

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

Problems from this contest made me realize how low my IQ is...

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

Задача D2.

мы снова сможем выбрать число с нечетным количеством

Как раз наоборот. Мы должны сохранять инвариант, что на нашем ходе всегда четное количество.

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

E: Are there any cute approach for $$$n$$$ is small?
I used randomized brute force(and easily found a solution, 249183723 (commentout code)), but I'm looking for simpler approach.

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

    This isn't exactly an answer to your question, but I came up with a solution that does not require brute force (but it did require a leap of faith for smaller cases):

    The basic idea is exactly as in the editorial, we only care about $$$x \gt \frac{n}{2}$$$.

    We will try to make tuples with these numbers starting from $$$\frac{n+2}{2}$$$, we will only consider consecutive numbers.

    Let $$$(x_1, x_1 + 1, x_1 +2)$$$ be the tuple that we are considering in this moment:

    If $$$x_1$$$ is odd, then we can apply the operation as in the editorial and continue with the next numbers.

    If not, then one of $$$x_1$$$ and $$$x_1+2$$$ is not divisible by $$$4$$$. Let's assume that $$$x_1$$$ satisfies this property. Then we will apply the operation to the tuple $$$(\frac{x_1}{2}, x_1+1, x_1+2)$$$. Notice that $$$\frac{x_1}{2}$$$ was not modified by other operations until now. Now, we can prove that we can generate the values of $$$x_1$$$, $$$x_1+1$$$, $$$x_1+2$$$ and $$$\frac{x_1}{2}$$$ with the new values generated, and $$$x_1$$$, that was not used.

    Finally, we have to consider the cases where we didn't handle the last numbers. If only two numbers were left, then the solution is equal to the editorial. But if one number is left, then we will use $$$(n, 1, \text{a number that is coprime with n and was not used})$$$

    You have to prove that there will always exist such number, for a big $$$n$$$ is reasonable, but for a small $$$n$$$ I just had faith.

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

Another approach of B: 2 * max >= 3 * 2nd max i.e. 2 * 15 >= 3 * 10, which means if n >= 30, always better to take 15s until n < 30, then for residual count (max 29), dp can be used.

submission: https://mirror.codeforces.com/contest/1934/submission/249116555

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

Can someone please explain how the formula was derived in problem A? Like how is |a−b|+|b−c|+|c−d|+|d−a| equal to 2∗d−2∗a? I'll be able to understand the next two if I only knew how to do this :(

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

    When the value in the mod is negative, we negate its contents while removing the mod.

    So as stated $$$a \leq b \leq c \leq d$$$, when we open the mods it becomes $$$(-(a-b))+(-(b-c))+(-(c-d))+(d-a)$$$ which on simplifying gives $$$b-a-b+c-c+d+d-a$$$ which equals $$$2*d-2*a$$$

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

include<bits/stdc++.h> include using namespace std;

void minCoins() { int n; cin>>n; int coins[] = {15, 10, 6, 3, 1}; int min1=INT_MAX, numCoins = 0; for(int i=0;i<5;i++){ if((n%coins[i])==0) min1=min(min1,n/coins[i]); } for (int i = 0; i < 5; i++) { numCoins += n / coins[i]; n %= coins[i]; }

cout<<min(min1,numCoins)<<endl; }

int main() { int t; cin >> t; while (t--) { minCoins(); }

return 0; }

This code is giving result 9 for 98(15*6+6*1+1*2) which is indeed correct right! but in problem the answer for 98 is 8.

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

You would never need more than 2 6s, 18=15+3 better than 6+6+6 and 24=15+3+6 better than 6+6+6+6

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

If you write C like this:

query a dot(x1,y1)

analyze which dot to query next (using many if-else)

and query (x2,y2)

and analyze all possible conditions...(using many if-else)

and query (x3,y3) ....

your code will easily become over 100 lines and have a very complex logic and also hard to write & debug. That's what I did in the contest.....qwq.

Maybe I should learn more. How to solve this kind of problem efficiently? Thanks for any ideas.

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

For question B, there seems to be a better solution. 249111275 I like this solution by Sugar_fan, because it's linear time per test case after a tiny amount of precalculation. Could Sugar_fan himself or someone who gets it please explain a little bit on the solution? About why taking the remainder between m and 2m works and 0 and m does not?

As for the value of m in his/her solution (= 2700), I intuitively expanded on this idea and figured that in general m = lcm(numbers) will also work. As such here is an accepted solution (I simply changed m from 2700 to 30 in the code): 249254380, with 0ms, signifying O(1).

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

    We need to prove this: for every $$$n \gt =30$$$ , the optimal choose must have a 15s coin.

    prove: Consider an optimal choose that don't have 15s coin.

    1. it have no more than 2*10s coin (3*10s coin->2*15s coin)

    2. 10s coin will not appear with 6s coin (10+6 = 15+1 , the optimal choose can have 15)

    3. it have no more than 2*6s coin (3*6s coin -> 1*3s coin + 1*15s coin)

    4. it have no more than 1*3s coin (2*3s coin -> 1*6s coin)

    5. it have no more than 2*1s coin (3*1s coin -> 1*3s coin)

    So , this optimal choose have sum of

    2*1s + 1*3s + 2*10s = 25 < 30 (don't have 6s coin)

    OR 2*1s + 1*3s + 2*6s = 17 < 30 (don't have 10s coin)

    So exactly if n>25 we can greedy choose 15s coin.

    In fact , 25=10+15 , 24=15+6+3 , 23 = 10+10+3 (if have 15s coin,it will be 15+6+1+1) , so the maximum n that we can't do greedy is 23.

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

      Thanks, got what's going on. So you do greedy till your remaining number is <= 23, then you add the pre-calculation of the remainder. Or I can say, it can be shown that [can it?] the lcm is always >= (the number till which greedy can't be applied) [remains to be proven], and thus following what is done in the code, the remainder will always be , rem >= lcm >= lowest non greedy number, and thus works. Do you have anything to add?

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

I think I've got pretty interesting solution for B. It was knapsack problem, but with cunning trick.

Let's remove all 15 from number N. I mean like, lets cnt = n/15, then n -= cnt*15. Then just do DP with vector a = {1, 3, 6, 10}. And the answer will be cnt + dp[n] (because n is less than 15 it will pretty quick).

But there's a catch. Sometimes it is better to not take last 15 coin. For example, 98. With our method, answer will be 9 (15*6 + 6*1 + 1*2). But the correct answer is 8 (15*5 + 10*2 + 3*1).

So we should write two dps, one for n -= (n/15)*15, and the other is for (n/15-1)*15, and then output the minimal one min(dp1[n] + cnt1, dp2[N] + cnt2).

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

Cool problems! Thanks! I loved them.

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

For the problem C, I queried (1,1), (1,m),(n,1) and (n,m).

Let the manhattan distances be r1,r2,r3,r4.

So as in the solution I guessed 2 possible values of (x1,y1).Let them be (x11,y11){assuming r2 is distance from (x1,y1)} and x12,y12{assuming r3 is distance from (x2,y2) and r2 is distance from x1,y1}. Now using r4 ,we know for sure that r4=n-x2+m-y2 since we assumed x1+y1=r1.

We calculate the possible values of (x2,y2) using r4 and r3 (assuming (x1,y1) is calculated using r1 and r2 i.e (x1,y1)=(x11,y11)). Then to check out of (x11,y11) and (x12,y12) which one is the correct (x1,y1) we apply the condition that

if(x11+y11<=x21+y21 && -y11+x11<=-y21+x21){
            cout<<"! "<<x11<<" "<<y11;
}
else cout<<"! "<<x12<<" "<<y12;

I think my logic is correct ,but still my code is giving WA.What am i doing wrong here?

Here is my piece of code for reference.

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

Very interesting problems, many thanks to the setters!. Just wanted to share my thoughts on problem A, as I thought it might help someone cuz it took a while for me to understand it well enough (or) intuitively.

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

For the problem D2, if the number p has an even bit count, can I break it into p1=2^(lsb of p) and p2=p1⊕p , where lsb means the least significant bit?

In the Code Part of Solution to Problem D2, on Alice's turn, why does the code set curr into p1? Why cannot Bob choose p2 instead of p1?

long long p1=(1ll<<pos);
long long p2=curr^p1;
cout<<p1<<" "<<p2<<endl;
curr = p1; // p2?
»
2 года назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Измените код на С. 1 решение

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

Could somebody please explain why is this solution giving TLE for problem D2??

The given below is the link to my submission :- https://mirror.codeforces.com/contest/1934/submission/249353586

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

My solution for B is a little interesting. https://mirror.codeforces.com/contest/1934/submission/249410271

  • Realise that when n grows, say n = 420, its 15 x 28 and 10 x 42, and 42-28 = 14
  • This means using the 15-value coin is a no-brainer as its using atleast 14 less coins than other combinations, so even if the remainder is non-zero, it will be less than 14 and we can use 1-value coin to fill the remainder, and it will still be optimal.
  • So I reduce large values of n, say 10^9 to a number between 420 and 435 by using only 15-value coins, then I rely on dp to tell me the minimal coins needed to consume the current number.
Here's the code
»
2 года назад, скрыть # |
 
Проголосовать: нравится +16 Проголосовать: не нравится

For problem E, how does jury check whether the answer output by the contestant is correct? That is, how to write the Special Judge for this problem?

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

Another solution for D1. Since we are allowed up to 63 operations, we can just do $$$\le1$$$ operation per bit. First let's assume there are at least 2 set bits in $$$n$$$.

For each bit $$$b$$$, if $$$b$$$ is the same in $$$m$$$ and $$$n$$$, then obviously we don't have to change it. Then we can break into two cases:

$$$1$$$: If $$$b$$$ is set in $$$n$$$ but not $$$m$$$, then we can add another operation flipping just that bit to $$$0$$$. Obviously, $$$b \lt n$$$ and $$$b\oplus n \lt n$$$, so this is valid.

$$$2$$$: If $$$b$$$ is set in $$$m$$$ but not $$$n$$$, then we can't have a separate operation, since then $$$b \oplus n \gt n$$$. Instead, let's combine this operation with an operation from case $$$1$$$, specifically the largest one. Note that since $$$m \lt n$$$, we will always encounter case $$$1$$$ before case $$$2$$$.

Now all we have to do is check if the largest operation is valid (because it may have been invalidated by case $$$2$$$ operations). There is an answer iff the largest operation is valid.

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

interactive problem for Problem C? That's not interesting.

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

Better approach for B, Pre-calculate Then the code checks if n is at least 15:

It calculates the remainder when n is divided by 15 and stores it in mod.

It adds this mod to 15 to get a number called check.

If check exists in the setz dictionary:

It prints the result of: (n — mod — 15) divided by 15, plus the value of setz[check].

Solution