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

Автор snowysecret, 4 года назад, По-английски

Thanks for participating, hope you enjoyed the problems! Implementations for the problems are chosen randomly among testers, and I made some changes to their codes (for example, deleted meaningless comment lines). Please do not hesitate to provide feedback in the comments, so I can improve in setting problems next time.

UPD: Sorry but there is a checker bug in problem E. All submissions of problem E will be rejudged soon.

UPD2: Rejudge done, the round remains rated.

Statistics

1617A - Forbidden Subsequence

Hint
Solution
Implementation (C++, I_Love_YrNameCouldBeHere)
Fun fact

1617B - GCD Problem

Hint
Solution
Implementation (Solution 1, Java, SecondThread)
Implementation (Solution 2, C++, dbsic211)
Implementation (Solution 3, C++, anthony123)

1617C - Paprika and Permutation

Hint 1
Hint 2
Solution
Implementation (C++, physics0523)

1617D1 - Too Many Impostors (easy version)

Hint 1
Hint 2
Hint 3
Solution
Implementation (C++, dbsic211)

1617D2 - Too Many Impostors (hard version)

Thanks must be given to arvindf232 and generic_placeholder_name for the solution.

Hint 1
Hint 2
Solution (Step 1)
Hint 3
Hint 4
Solution (Step 2)
Implementation (C++, dbsic211)

1617E - Christmas Chocolates

Hint 1
Hint 2
Hint 3
Solution (Step 1)
Hint 4
Solution (Step 2)
Implementation (C++, physics0523)
Разбор задач Codeforces Round 761 (Div. 2)
  • Проголосовать: нравится
  • +425
  • Проголосовать: не нравится

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

ooh fast editorial :)

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

omg fast editorial

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

Today B screwed me.

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

    It was easy but very observational, if you can observe quick it's pretty easy otherwise it screws.

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

    There must exist a solution for c=1 under the given constraints.

    I still don't exactly see why that is the case....

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

      Assume $$$c = 1$$$, you are left with $$$n - 1$$$ which must be divided in two groups, $$$a$$$ and $$$b$$$.

      Dividing by $$$2$$$ will either equally distribute the amount or it won't.

      In the second case, one value will always be $$$+1$$$ than the other and $$$gcd$$$ of two consecutive numbers is $$$1$$$.

      In the first case, both numbers will either be odd or even. If both numbers are even then simply subtract $$$1$$$ from one value and add it to the second value, by doing this both numbers will be odd now with a difference of $$$2$$$, hence $$$gcd = 1$$$. If both numbers are odd, subtract $$$2$$$ from one value and add it to the other value. By doing this you will have two odd numbers with a difference of $$$4$$$, hence $$$gcd = 1$$$

      Maybe this is a complicated way to think about it but that's how I did it

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

Great contest! I especially enjoyed solving problem D, thanks :)

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

Great contest! Great problems! Great editorial! Sad orange can’t play._.

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

Lightening fast editorial :)

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

Time complexity of editorial: O(1)

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

In the solution of problem C, the observation will be $$$x$$$ $$$mod$$$ $$$y$$$ $$$ \lt \lceil \frac{x}{2} \rceil$$$ if $$$x$$$ $$$ \gt =$$$ $$$y$$$

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

Problems were good and so the quality of the editorial. All editorials should have hint spoilers.

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

    I like how the author split the editorial into hints, solutions, and code snippets, and had them spoilered separately, which would be helpful for beginners who are learning cp;) (But it’s also extra effort, so I wouldn’t go as far as to ask for having this in particular, rather, I’ll just treat it as a bonus)

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

As a tester, I have some fun facts about problem D:

Originally, D had only one version, which is the current D1. Then I tested D and came up with a $$$\frac{4n}{3} + O(1)$$$ query solution. (Actually, originally, $$$n \bmod 3 = 0$$$ wasn't a thing, and the lower bound was $$$4$$$, so getting that to AC was a lot of pain :v) That solution became D2 — except that later, arvindf232 came up with the $$$n + 2$$$ query solution. Then we had a problem, which was that we couldn't decide which of $$$2n$$$, $$$\frac{4n}{3}$$$, or $$$n$$$ should be the official D1/D2. In the end we decided that $$$2n$$$ for D1 and $$$n + O(1)$$$ for D2 would be best for balance.

We (or at least I) thought that D2 was more difficult than it ended up being. We had the idea of changing the distribution to 1750-1250-2500, but it never came to pass. In my opinion, the original distribution turned out to be better. :v

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

I'm curious, how many participants actually proved their solution of B?

EDIT: I'm not looking for proofs of this solution or that solution. I'm more interested in the ratio of "guessed/hoped" vs "solved". Actually in some sense it's more interesting to hear from people who didn't prove their solution.

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

139546379 I don't know why I get TLE on D2, I think my time complexity is $$$O(n)$$$.

Edit: I know where was wrong. I didn't handle the case when query return -1

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

Thank you so much!!!

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

Can we do D2 in $$$\leq n$$$ queries?

It can be done is $$$n + 1$$$ by reducing $$$1$$$ query from the editorial's solution using the fact that the two people between the impostor and crewmate we detected, are of opposite type, so we can just ask for one of them.

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

Nice problems great editorial with hints. overall great contest!!! Well done snowysecret.

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

Was totally confused at C. Luckily understood the meaning of k range to solve D1 and that saved my rating for this contest or else whoooooosh it would have gone

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

Problem D in n+1 queries: 139550123

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

How to think the solution of problem B during the contest....

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

    Actually, first observation is gcd(a,b)=c so a=cx and b=cy where x and y are mutually prime. So the given equation becomes c*(x+y+1)=n . so c is a factor of n. Now you think that if n is a prime number, then it's only factors are 1 and the number itself. if c=the prime number itself, then x+y+1=1 ===> x+y=0 which is not possible according to the given problem. So c=1 for prime numbers. On the other hand the equation will be holding for composite numbers as well so, you can proceed with c=1. therefore the equation becomes x+y+1=n or x+y=n-1. Now, we have already said that x and y are mutually prime. So the immediate thing that should come to mind is that two consecutive numbers are equal . if n-1 is odd, then you should know that an odd number can be written always as a sum of two consecutive numbers (if x is odd, then x=x/2+x/2+1 ...x unrelated to the explanation above) . otherwise,n-1 is even, so a possibility is x=(n-1)/2 and y=(n-1)/2 . But x and y are coprime, so probably, we can go one step forward for y and one step backward for x .Then x=(n-1)/2 -1 and y=(n-1)/2+1 .Now if originally x and y were even numbers, then the new x and y must be odd numbers. These two odd numbers with a difference of one will always be coprime. Otherwise,if both new x and y are even, then decrease x one more time and increase y one more time .Again we end up with two odd numbers and these two with a difference of 4 will always be mutually prime .

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

Great problems, fast editorial with hints, I hope more of these contests will be held :)

Thanks snowysecret

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

Superfast editorial!

What's more, with hints!

I enjoy the contest very much, the problems are fabulous, thank you!

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

For anyone looking for video editorial you can check mine out

It's only up to D1 tho

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

Problems were nice, although I could try only up to D1.

Hoping to see you in another round :)

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

borked checker rejudge time

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

Can anyone tell me, for problem D1 why I am getting the wrong answer verdict on Test Case 1?

Any help would be appreciable. Thank you :)

Submission

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

SIUUU!

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

In problem B , why Brute force solution is working

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

My more complicated, less elegant solution to D1:

  • Make queries of the form (1, 2, i) for i in [3, 2n/3 + 1]
  • If the results are not all the same, we immediately know 1 and 2 are different, and we easily have the answer ans[i] = query(1, 2, i).
  • Otherwise, if all of the results are the same, then we know 1 and 2 are whatever the result is. Proof: assume that 1 and 2 are different but all the queries [3, 2n/3 + 1] returned the same result. Then there are a total of (2n/3+1 — 3 + 1) same results, plus 1 for either 1 or 2 matching, for a total of 2n/3 of the same, contradicting the constraint.
  • WLOG, say 1 and 2 are imposters. Now, query all the disjoint triplets that haven't already been queried (i.e. all but (1, 2, 3)). We know one of the triplets must return 1 (same reasoning as in editorial solution), having >= 2 crewmates. Let the triplet be (a, b, c).
  • Of the queries (1, a, b), (1, a, c), and (1, b, c), at least one of them will return majority crewmate, and the two people that aren't 1 are crewmates. This step takes at most 2 queries (since after 2 failures, there is only one option left).
  • By now, we've identified 1 crewmate and 1 imposter, and can determine the remaining (n-4) people with the simple queries.

So in the worse path, we use (2n/3-1) + (n/3-1) + 2 + (n-4) = 2n queries.

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

Very nice trick to solve D2

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

can anyone help me with this code :

139558441

a lot of thanks to anyone who can help me

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

can someone please tell why this is giving me RTE on the first test case? it is working fine on my compiler https://mirror.codeforces.com/contest/1617/submission/139558421

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

I like the A question which made me an orgasm

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

can anyone please explain this? in problem B solution 3 if (n%2==0) cout<<"2 "<<(n-1)-2<<" 1\n";

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

If you are interested in video solutions, here are the solutions for the first 4 problems.

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

Whyyyyy.... your mistake on E checker cost me 140 rating :(

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

.

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

I tried to hack my solution but I got "Unexpected verdict". Is there a problem with the solution to that problem?

Screen-Shot-2021-12-16-at-14-38-46

The test is

2

7 9

The particular thing about that test is that the diameter of the tree shouldn’t consider the node 0, (just nodes 7 and 9 in this case) my solution didn’t consider that and that is the reason of the wrong answer. This happens when all the nodes in the input lie in the same path from the root to the farthest node. Please consider adding a similar test.

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

I've implemented the idea of D2 on D1(6 queries), but wasn't aware that same way I can solve D2. And i also missed the simple idea of D1!!

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

Nice Contest snowysecret

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

Fast editorial! Thanks!

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

Problem E is really nice, good job!

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

Is there anyone can solve D2 in n queries? I can just solve it in (n+1) queries!

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

I used Trie to solve E. Submission link

(I know it's overkill but the logic is somewhat different from the one in editorial)

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

for Problem D1,why we need query $$$(n-1,n,1)$$$ and $$$(n,1,2)$$$ ?

It seems that query $$$(1,2,3)$$$ to $$$(n-2,n-1,n)$$$ can find one pair of crewmate and impostor.

can give me a counter-example?= ^ =

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

Could someone please tell me whats wrong with my d2 solution? I am getting the same output as testcase 1, but its showing "Incorrect set of impostors"?

Here's my code

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

Since the number of impostors k and crewmates n-k satisfy k>n/3 and n−k>n/3, there must be one pair of adjacent queries that are different.

Can someone explain why?

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

    You know that n is divisible by 3. So you can split it into x intervals of 3 each, such that x*3=n. So assume x=n/3.

    Now, k>n/3 =>k>x and k<2*x. so k belongs to [x+1,2*x).

    Applying pigeon hole principle, you have x intervals and a minimum of x+1 impostors to fill, so at least one interval will have 2(or more) impostors.

    With this, it wont be difficult to see that ~~~~~ for any n and k, that satisfy the constraints, the number of impostors k and crewmates n-k satisfy k>n/3 and n−k>n/3, there must be one pair of adjacent queries that are different. ~~~~~

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

    According to the pigeon hole principle, As long as one adjacent 0-majority tuple and 1-majority tuple exists, there is exactly 4 cases of one kind of tuple.

    0-major -> {0, 0, 0}, {0, 0, 1}, {0, 1, 0}, {1, 0, 0}; 1-major -> {1, 1, 1}, {1, 1, 0}, {1, 0, 1}, {0, 1, 1}.

    for the {0-major} + {1-major} and {1-major} + {0-major} cases, brutally select each tuple, pair them up, try all 2 * (4 * 4) = 32 cases, we can see there will always be at least one 4-consecutive indices {id, id + 1, id + 2, id + 3} from all 6 places for each case, for which query {id, id + 1, id + 2} and query{id + 1, id + 2, id + 3} differs.

    For example check 2 tuples {0 1 1} + {0 0 0}, start with the second index, {1 1 0 0} meets our need.

    The method may be kind of tedious, I wonder if other elegant proofs exist.

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

In problem D, I wonder what "The jury is adaptive" means. Why there are still feedbacks of "wrong set of impostors"?

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

Problem D is pretty amazing. Loved to upsolve it.

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

Can anyone explain me the meaning of "FST","AK"?

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

I have a solution to problem E which does not involve graphs in any way.

At the beginning, our array values fit in range $$$[0, 2^{30}]$$$. Let's now divide the array into two parts $$$L$$$ and $$$R$$$, where $$$L$$$ will contain all values $$$\le 2^{29}$$$ and $$$R$$$ will contain all larger values.

Now suppose $$$(x, y)$$$ is the optimal pair we are searching for. Here comes a crucial observation. If both $$$(x, y)$$$ are in $$$R$$$ they are both larger than $$$2^{29}$$$ so we cannot use any $$$k \le 29$$$ operation on them. The only way to continue is to use $$$k = 30$$$ and make them both less than $$$2^{29}$$$.

Also suppose $$$x \le 2^{29}$$$ and $$$y \gt 2^{29}$$$. In this case we have to transfer one value to the other side by using $$$k = 30$$$, but transferring $$$x$$$ is never optimal. Let's prove it.

Case $$$x = 2^{29}$$$ is trivial. Otherwise $$$x \lt 2^{29}$$$ so $$$2^{30} - x \gt 2^{29}$$$ and since also $$$y \gt 2^{29}$$$ we arrive at the previous state when we are forced to decrease both of them using $$$k = 30$$$. This means that it is always better to do an operation on $$$y$$$, again reducing it to some value $$$ \lt 2^{29}$$$ and continue from there.

All the reasoning above means that all values $$$R$$$ have to be reduced in one operation to become less than $$$2^{29}$$$ and after that we can merge those values with $$$L$$$ and repeat our algorithm again with a threshold $$$2^{29}$$$.

We can repeat this process until we arrive at a simple case when all values are in range $$$[0, 1]$$$. Here we can just consider a transition $$$0 \rightarrow 1$$$ and we are done.

This solution can be implemented in various ways. One I can think of is to store $$$L$$$ and $$$R$$$ as sorted vectors and merge them using two pointers. But I personally think that maps are the most simple and elegant way. Maps introduce an additional $$$\log n$$$ factor, resulting in a $$$O(n \log n \log 10^9)$$$ solution overall which is still fast enough considering a very generous time limit.

Here is my submission: https://mirror.codeforces.com/contest/1617/submission/139683868

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

[My Submission](https://mirror.codeforces.com/contest/1617/submission/139840155

Can someone tell me why my code to Problem D1 is getting Idleness limit exceeded even though I flushed wherever required. Thanks in advance.

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

Sorry if it's obvious, but why is the graph formed in E connected? I see that there are no cycles but how do we know that we can get from any $$$x$$$ to any $$$y$$$?

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

I think this is not the intended solution for 1617B - GCD Problem...

Link : 141021665

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

can someone tell me why i am getting WA on testcase 2 in this solution : https://mirror.codeforces.com/contest/1617/submission/141883310

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

Can anyone tell me what's wrong with my code? I've coded differently, but the approach is same as given for problem C.
142936588

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

In Problem C, According to Editorial Solution I found -1 as output when I provide array = {1, 2, 7, 8} as Input. But here the output should be 2. Like for array[3] = 7 we can choose x = 3 and 7 % 3 i.e. 4 lies in [1, n], similarly for array[4] = 8 we can choose x = 5 and 8 % 5 i.e. 3 lies in [1, n]. hence we can obtain the permutation as {1, 2, 4, 3} which should be acceptable. May be I am wrong if anyone found the proper solution please reply ASAP.

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

Really, Great Editorial :)

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

There exists a completely different and overcomplicated reasoning for the solution of problem E:

Notations:

  • $$$lsb(x)$$$: least significant set bit in binary representation of $$$x$$$.
  • $$$msb(x)$$$: most significant set bit in binary representation of $$$x$$$.

Firstly, let's visualize the effects of an operation $$$x = 2^k - x$$$ on the binary representation of integer $$$x$$$.

  • In the trivial case, if we choose $$$k$$$ such that $$$2^k = x$$$ then $$$x$$$ just turns $$$0$$$.
  • When we choose some $$$k$$$ such that $$$2^k \gt x$$$, observe that the operation is essentially equivalent to flipping the bits in the range $$$[k + 1, lsb(x))$$$ of the binary representation of $$$x$$$.

Observations
Optimal strategy for making two arbitrary integers equal
Finding the two integers which require the maximum number of moves to equalize

Implementation: link