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

Автор dannyboy20031204, история, 5 лет назад, По-английски

1635A - Min Or Sum

Tutorial
Solution

1635B - Avoid Local Maximums

Tutorial
Solution

1635C - Differential Sorting

Tutorial
Solution

1635D - Infinite Set

Tutorial
Solution

1635E - Cars

Tutorial
Solution

1635F - Closest Pair

Tutorial
Solution
Разбор задач Codeforces Round 772 (Div. 2)
  • Проголосовать: нравится
  • +257
  • Проголосовать: не нравится

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

Thanks for your interesting round.

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

Thanks for the fast editorial. D was the most interesting problem for me.

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

LIGHTNING EDITORIAL

THANK YOU SO MUCH FOR PROVIDING THE ROUND!

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

thanks for good problems and fast editorial !

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

can anyone please tell me why this is wrong?problem -C

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

Was A harder than normal for a lot of people?

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

where $$$g(i)$$$ = number of $$$j$$$ satisfying $$$f(a_j) = i$$$

What is the intuition behind this and why it can helps the new dp value?

(Problem D editorial)

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

    Example array $$$a$$$ has 9, but 4 isn't belong $$$S$$$ you need count 9 and $$$2^3 \lt = 8 \lt 2^4$$$ so 9 counts in $$$dp[4]$$$.

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

    +1

    It feels like there's no way of coming up with the editorial solution. It uses some arbitrarily defined function that somehow happens to be ans to the problem. I feel there's some other intuitive solution that I'm missing but if this is the expected solution then that's pretty terrible problem.

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

    I think the tutorial is trying to explain things in a concise way but somehow also loses intuitiveness. Here's how I solved the problem.

    Observation I: Make the number binary. Then the problem will be like given a bunch of number, how much number under $$$p$$$ can be reached by adding a 1 or 00 at the back of those given numbers.

    Observation II: If a number $$$a$$$ can be reached from another number $$$b$$$, than a is useless because all number that a can reach can also be reached by $$$b$$$. Thus, we only take $$$b$$$ into consider.

    Observation III: If $$$a$$$ and $$$b$$$ cannot reach each other, than any number can only be reached by at most one of them.

    So, after we deleted all the 'useless' values, it's just solve for every number ad add the result together. And that's some simple DP from there.

    Hope this helps.

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

Could anyone help with my problem D submission? Submission

I basically used the fact that if one number can't directly be reached by another, all their children will be distinct. Submission passes the given pretests.

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

My algorithm for C was the exact same, but instead of using the last 2 elements and the current element, I used the last element, the current minimum, and the current element. Why does this not work?

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

in the editorial of the problem A Since, a1|a2|⋯|an≤a1+a2+⋯+an, the sum of the array has a lower bound of m why this statement is true and how did they arrive at this result

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

    If you have two numbers, taking their sum will make bits that are the same 'carry', but taking their bitwise OR won't. For example if you have $$$10_2$$$ and $$$10_2$$$, the sum will be $$$100_2$$$, but the OR will still be $$$10_2$$$. I'm sure there's a rigorous proof somewhere but this is how I came up with the observation.

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

Are the recent contests tough or I lack practice? I'm clearly having a hard time solving questions nowadays.

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

Can someone explain the proof of A like I am 5 ?

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

I don't think the $$$|a_x|$$$ in pC can reach $$$10^{18}$$$, it should grow in $$$O(n)$$$. Although I cannot give strict proof, I can say that the testers fear it happened. By asking them, as a friend...

Update, I'm wrong, abc864197532 does have code to hack it. \abcorz/

The operation is like (-2b) (-b) (a - b) a b

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

for problem B ..but the optimal way is to set ai+1 to max(ai+1,ai+2).. i think it should be ..but the optimal way is to set ai+1 to max(ai,ai+2)..

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

how would you rate c problem?

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

can anyone tell why it says array not sorted after all operations in this -https://codeforces.me/contest/1635/submission/147096553

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

Thanks to codeforces for this round

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

Problem D can be approached by considering all numbers to be binary strings. We can see that the two operations then look something like this: 2x+1 is equivalent to appending 1 to the binary string, 4x is equivalent to appending 00 to the binary string. Its still important to ignore the useless numbers from the array, useless means those who can be generated by elements already present in the array. One we have an element (a[i]) from the array which is usefull we need to append some bits and make it a string of no more than p characters, so we can subtract length of a[i] from p and that will give us the free places to work on. We can append string of length 0, 1, 2.... p-len to the end and that will give us new numbers everytime. So we can count the number of strings of length 0, 1, 2, 3...p made up of 00 and 1 and then add all possible strings of length atmost p-len, Prefix sum can optimize this operation.

Here is my code for the same, hope it helps someone: 147075092

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

I've solved only one problem during contest, but my overall rating got lower, why ?

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

    Well, I guess you answered your own question, you solved only one problem.

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

      But I've been thinking that for the 1st problem I must get from 260 to 500 scores. for the 2nd 1000, etc, depending on time and attempts.

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

        As far as I know your new rating is a function of overall standings, not the scores you obtain on a problem. The higher number of problems solved facilitates that but can not ensure it if many people are able to solve it before you.

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

          OK. My rating before contest was 1089, after the contest it become 1004 (-89). What should I do or how many problems I must solve during contest to make rating go up ?

          What does the scores of the problems determine ? I've solved the first problem and got 438scores. But it gave -89.

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

            There's a nice chrome extension cf-predictor. It tells you in real-time what your rating would be if your current standing is your final standing. You can use that. The score you obtain on a problem adds to your total score and your total score determines your rank which further determines your rating change. There is no hard rule of rating change on solving a certain number of problems, it's all relative scoring. For more info refer this blog

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

            Your rating change will be calculated based on your postion in the standings table, your rating and the rating of the other partitipants. Actually each rating point one looses is a won rating point for somebody else.

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

            The contest score doesn't directly determine your rating. The scores are used to rank you with other participants. Based on previous rating you'll be given an expected rank. If your actual rank is better than expected rank your rating goes up otherwise it goes down.

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

Hey, in editorial of B, ceil value should be used and not floor.

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

What rating range should problems B and C be?

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

A very well balanced contest,, Loved it..

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

Problem D with $$$p \le 10^9$$$ is also solvable.
For each "useful number" $$$u$$$, if $$$2^{k-1} \le u \lt 2^k$$$, we can generate $$$F_1+F_2+\dots+F_{p-k+1}$$$ elements ($$$F_i$$$ is $$$i$$$-th Fibonacci Number, begin with $$$F_1=1,F_2=1,F_3=2,...$$$) from $$$u$$$.
It is satisfied that $$$F_1+F_2+...+F_r = (F_3-F_2)+(F_4-F_3)+...+(F_{r+2}-F_{r+1}) = F_{r+2}-1$$$ , so we can just sum up it.
Time Complexity: $$$+N \log p$$$ instead of $$$+p$$$ in the editorial
code: 147068110

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

My solution to A seems to be a little different. I used the observation that for two integers x and y, to make sum as small as possible and at the same time not changing x OR y, you need to remove a 1 bit for every position that the bit is 1 in both x and y. This is equivalent to removing x AND y

Do this for all pairs and the answer is the total sum: Submission

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

Good Round

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

The solution of F is so wise!

I like the problem F!

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

147064757 any one please tell me why this puts("0") doesn't work...

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

I have a different approach for problem $$$D$$$.

Consider a value $$$x$$$. We have a set of possible values $$$ \lt 2^p$$$ which we must include if we include $$$x$$$. For example, we must include $$$2x + 1$$$ and $$$4x$$$. Call these set of values $$$S(x)$$$. Using this notation, the problem wants us to find $$$\cup_i S(a_i)$$$.

How can we examine $$$S(x)$$$? It's much easier if you consider it in binary — consider a binary string $$$s$$$ which represents some value $$$x$$$ in base $$$2$$$. $$$2x + 1$$$ appends a $$$1$$$ and $$$4x$$$ appends two zeroes. Therefore, if we start at some string $$$s$$$, we have to include anything that can be reached by adding "1" and "00" some number of times. For example, if we have some string $$$5$$$ or $$$101$$$ and $$$p = 6$$$, then we can have $$$101\mathbf{001}, 101\mathbf{111}, 101\mathbf{100}$$$.

Notice that the size of $$$S(x)$$$ is $$$F[p - \lfloor \log_2 (x) \rfloor] - 1$$$, where $$$F$$$ is the Fibonacci numbers. The reason we have that floor log2 expression is because some prefix of our string is fixed (in the previous example, our string length is $$$3$$$).

How the heck did Fibonacci get here?

But why isn't our answer the sum of sizes of $$$S(x)$$$? The answer is simple — we could have overlaps. Consider $$$100$$$ and $$$1\mathbf{00}$$$ for instance. In particular, we have overlap between binary strings $$$s_1$$$ and $$$s_2$$$ iff there is a way to reach each other via adding only "00" and "1". On naive approach is to brute force $$$\mathcal{O}(N^2)$$$ for each pair of binary strings and check if they can be reached from each other.

But there's a better way. Notice that two strings can only be reached via each other iff one of them is the prefix of the other (say $$$s_1$$$ is a prefix of $$$s_2$$$). Since we know that the numbers are small (at most $$$25$$$ bits), $$$|s_2| \le 25$$$, so we can iterate over all prefixes of $$$s_2$$$ and check if they have some match in the array. Only if they do, check if they can be reached via some sequence of moves.

How to check if they can be reached via some sequence of moves? One simple way is to ensure that each contiguous block of zeroes has even length. There are other ways too, like with a stack.

147131385

Note: Some constant factor optimizations can be made to my solution, but it still generously runs within the time limit.

Cheers!

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

In problem D why is dp[0] initialized to 1 ?

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

Getting WA on TC 5 in Problem D 147139694 Can anyone please point out my mistake?

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

First time giving a competition.Could not solve any one of the problems.I am Slowly working through editorials.

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

ProblemA, Sample TestCase : 5.

Can anyone please provide a way to achieve 7 for 3 5 6?

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

I made video Solutions (for A-E) in case someone is interested.

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

What can be the cause of getting WA 9 in E? 147171369

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

How to solve Problem C if we need to minimize the number of operations

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

Can someone explain This is actually a classic problem, which could be solved by sweep line trick + any data structure able to maintain prefix-minimum with single point updates, like BIT or segment tree. I am not able to understand the implementation in the solution as well.Is this some standard algorithm?

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

Hi, can a programming god help me figure out why my D is getting WA on test case 5? I basically eliminate the useless numbers, and then do some fib dp to find the answer. https://pastebin.com/ARt4ESMf

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

I have a question about the solution of problem d, regarding control flow

            if (x & 1) {
                x >>= 1;
            } else if (x & 3) {
                break;
            } else {
                x >>= 2;
            }

Doesn't x & 3 imply x & 1? Or should x & 3 be replaced with x % 3? I don't understand why x is not useful if x & 3. Could someone explain it for me?

Thank you so much in advance

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

    If the last two bit of the binary representation of x is 00, we need to continue finding possible parents. But if the last two bit is 10, we need to stop finding since the operation is * 4 and there are no parents that can generate it.

    So in my implementation, I use x & 3 to check whether the second last bit is 1 or not. It can be replaced with x % 4 or x & 2. The latter is because I have checked the last bit is 0.

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

if I do arr[i+1] = max(arr) in 1635B — Avoid Local Maximums, why it would not pass pretest2 ?

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

I think there is an important point to notice for Problem D: in dp[i] = dp[i - 1] + dp[i - 2], what if dp[i - 1] and dp[i - 2] contribute to duplicate numbers in dp[i]? Fortunately, this will not happen because dp[i - 1] only generate odd numbers in dp[i], and dp[i - 2] only generate even numbers in dp[i].

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

For problem D, how are we so sure that two numbers that are not related (i.e., one is not a parent of another) cannot generate the same number some steps later?

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

Could anyone for [Problem C] [My solution is](https://codeforces.me/contest/1635/submission/263651690)explain why my solution is wrong ??