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

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

1780A - Школа и Хаято

Идея: AndreyPavlov
Подготовка: AndreyPavlov
Разбор: AndreyPavlov

Разбор
Решение (Python)
Решение (C++)

1780B - НОД разбиение

Идея: 74TrAkToR
Подготовка: qualdoom
Разбор: qualdoom

Разбор
Решение (Python)
Решение (С++)

1780D - Битовая угадайка

Идея: AndreyPavlov
Подготовка: qualdoom, AndreyPavlov
Разбор: qualdoom, AndreyPavlov

Разбор
Решение (Python)
Решение (С++)

1780E - Джоске и полный граф

Идея: IzhitskiyTimofey
Подготовка: IzhitskiyTimofey
Разбор: IzhitskiyTimofey

Разбор
Решение (Python)
Решение (С++)

1780F - Три стула

Идея: AndreyPavlov
Подготовка: AndreyPavlov
Разбор: qualdoom

Разбор
Решение (С++)

1780G - Вкусный десерт

Идея: IzhitskiyTimofey
Подготовка: IzhitskiyTimofey, AndreyPavlov
Разбор: IzhitskiyTimofey, AndreyPavlov

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

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

Ну и где решение C? Очень хочется узнать решение NP-сложной задачки :D

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

Can't wait for the solution of C. Show us guys, how to solve NP-hard problems!

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

How come I see ACs still on C? No hacks were made on the problem?

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

Has no one made a hack for C yet?

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

Problem D was very interesting :) ,one mistake and whole efforts of problemsetters and testers got ruined.

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

Weren't the incorrect greedy solutions for C O(n)? Why was the constraint on the problem O(n^2) then?

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

Weren't the incorrect greedy solutions for C O(n)? Why was the constraint on the problem O(n^2) then?

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

I don't understand why problem C was unsolvable?

this is my code please give me a counterexample.

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

On the last row of Tutorial of B:

"Let $$$s$$$ be the array $$$a$$$"

should probably be

"Let $$$s$$$ be the sum of the array $$$a$$$"

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

delete

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

problem E & F are so interesting. i enjoyed..

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

My solution failed system tests on C because it got a better result than the author's one, lol

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

Problem G is quite similar to this problem. I had to modify my solution for the Educational round problem a bit to get AC on this round's G.

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

A brief tutorial to problem E, for people like me who cannot follow the official one:

Value $$$x$$$ will appear in one of the edges iff: $$$L \leq px \lt (p+1)x \leq R$$$, where $$$p=ceil(\frac{L}{x})$$$.

Now we enumerate every value of $$$p$$$ and count the number of possible $$$x$$$ for each $$$p$$$.

For $$$p=p_0$$$, the above inequality gives range of x: $$$\frac{L}{p_0} \leq x \leq \frac{R}{p_0+1}$$$.

Note that there is a hidden constraint of $$$ceil(\frac{L}{x}) = p_0$$$. This translates to $$$\frac{L}{p_0} \leq x \lt \frac{L}{p_0-1}$$$.

Combine the two ranges above, we get, for $$$p=p_0$$$, possible values of $$$x$$$ satisfies: $$$\frac{L}{p_0} \leq x \leq min(\frac{R}{p_0+1}, floor(\frac{L-1}{p_0-1}))$$$.

And we use sqrt decomposition to solve this counting problem: For $$$p\leq sqrt(L)+1$$$, we compute the range of $$$x$$$. For $$$p \gt sqrt(L)+1$$$, we have $$$x \leq sqrt(L)$$$, so we can just iterate through all $$$x$$$ values.

Complexity is $$$O(sqrt(L))$$$.

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

In C question greedy solution fail on test case-

1

11 3

1 1 1 1 1 1 2 2 2 2 2

5 4 2

correct answer for above testcase = 11, but greedy solution gives answer = 10

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

Can anyone explain what was the intended solution for C, which turned out to be incorrect.

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

    Group people by what they like, and while there are groups of people and tables left, try to put the largest group on the largest table. If they don't fit, just use as many as you can and subtract that amount before deleting the table. If they do fit, delete the group of people and the table. "Answer" is however many people this process gives a table. The original might've been slightly different, but this is the silly wrong solution I got AC with.

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

In Problem D, in 2nd Tutorial (by qualdoom), for the condition (pt.2) where "$$$cnt-cnt_{new}\not=1$$$", can someone kindly explain the part, how this below equation is formed?

$$$m - k - 1 = cnt_{new} - cnt$$$

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

    Consider the real number is 24 its binary representation is 11000, and you need to guess this number. also, you can't subtract a number greater than the real number so if we subtracted 1 from real number which was 24, we will have 23 which its binary representation is 10111 so the number of unit bits has been changed and become 4-unit bits instead of 2 how this happened? hence, we now have 23 which has 4-unit bits and previous has 2 so the LSB at index (4-2+1) 0-based we add 1<<lsbIndex to obtain the real number. I hope that helped you.

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

Who can explain me, how to use mobius function in problem F?

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

I don't know why. I want to comfort the author. qnq

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

Can someone give a test case where this approach gives a wrong answer to C?

  1. Calculate how many meals of each type and how many tables of each size there are.

  2. Go through the meals, if there is a table with the same size as the count of that meal, then put those people to that table.

  3. Put remaining meal and table counts to two priority queues. While there are still some empty tables or not all people has a spot: take the top of meals and put them at the biggest empty table, if some people who like that meal are still left, check if there is empty table with that amount of spots, if there is put them there, otherwise put that number back to priority queue.

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

    Ok, here's a counterexample: tables are 2 2 3 and people are 1 1 1 1 2 2 2. The second step goes as no-op, so you will take ones into the third table (which has 3 seats) and then twos are placed in the remaining first/second table, which is not a correct strategy since you could have placed ones into first and second table and then remaining twos into the third table.

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

My approach for D (similar to the second tutorial solution, it seems, but it doesn't explicitly need flags and might be easier to understand for some):

To determine whether the last bit is 0 or 1, we can simply subtract 1. If the last bit was a 1, then it becomes 0 and the $$$cnt$$$ decreases by exactly 1. Now that the last bit is already 0, we can check the second-to-last bit by subtracting 2. In general, if the last $$$k$$$ bits are set to 0 while the rest of the bits are unchanged from the original, we can test bit position $$$k$$$ (from the right) by subtracting $$$2^k$$$ and seeing if $$$cnt$$$ decreases by exactly 1.

But what happens when the bit at the position we're testing (let's say position $$$k$$$) is actually a 0? In that case, $$$cnt$$$ either stays the same or increases, so we know that this position originally has a 0. However, this attempted subtraction of $$$2^k$$$ ruins our desired pattern, because the bit at position $$$k$$$ changed from 0 to 1 and at least one bit on its left has changed. We would have wanted the bits from up to position $$$k$$$ to all be 0 and everything else unchanged in order to test the next bit, at position $$$k + 1$$$...

We can deal with this by "undoing" the latest undesirable subtraction by instead treating it as part of the next subtraction. Normally, the next subtraction is supposed to be $$$2^{k + 1}$$$, but since we already performed an undesirable subtraction of $$$2^k$$$, we simply subtract another $$$2^k$$$ to result in a overall subtraction of $$$2^{k + 1}$$$ as if the undesired subtraction never happened.

Note that there could be a sequence of undesirable subtractions, in which case, we just keep track of the total of the undesirable subtractions and treat them all as part of the next subtraction. Eventually, we would have to find a 1, which resolves all these undesirable subtractions. Once we find the MSB, the $$$cnt$$$ should become 0, at which point, we are done.

My submission: 190561881 ($$$acc$$$ is the accumulation of undesired subtractions that we are trying to undo)

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

Simple implementation for F 190544353

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

    Can you explain your solution if it's different from the editorial?

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

      I have similar solution. Mine is: calculate $$$dp[x]$$$ -- number of ways to choose a triple which value of gcd is $$$x$$$. To calculate amount of such triples for every $$$x$$$ sort an array then for every $$$x$$$ consider only numbers which are divisible by $$$x$$$, let their indices be $$$ind$$$, we should calculate sum over all $$$i \lt j$$$ of $$$ind_j - ind_i - 1$$$, we can calculate it by iterating over these indices storing sum of considered indices and their cnt. Then you have a $$$dp$$$ where you should substract from $$$dp[x]$$$ $$$dp[2 * x], dp[3 * x], ...$$$ to obtain correct answer.

»
3 года назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится
  1. What is the correct solution for problem C then, if it exists?
  2. In the editorial for problem E, it is mentioned that for g<L, ceil(L/g) will have O(sqrt(L)) values, how?
»
3 года назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

I did the same thing in problem B yet kept getting TLE. Can someone point out my mistake. Thankyou!

while(test--)
    {
        int n;
        cin >> n;
        int * arr = new int[n];
        int * cuml = new int[n]; //Cuml is for cumalative sum
        for (int i = 0; i < n; i++)
        {
            cin >> arr[i];
            if(i==0)
            {
                cuml[i] = arr[i];
            }
            else
            {
                cuml[i] = arr[i] + cuml[i-1];
            }
        }
        int ans = 0;
        for(int i = 0; i < n-1; i++)
        {
            if(cuml[n-1]%cuml[i]==0)
            {
                ans = max(cuml[i],ans);
            }
            else
            {
                int temp = gcd(cuml[i],cuml[n-1]);
                ans = max(temp,ans);
                cerr << temp << '\n';
            }
            
        }        
        cout << ans << '\n';
    }

Please help !

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

What is the time complexity in F and why is it quick? IMHO we have O(N * 2^(an average number of prime divisors)) so it doesn't seem like a quick solution.

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

    lets think like this. you know the number of divisors of a number n is O(log(n)). now you are only iterating on SOME of these divisors.

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

    Let $$$preres_x$$$ be the number of ways of choosing the triplets where the $$$gcd(a_i,b_j)$$$ is a multiple of $$$x$$$ and $$$res_x$$$ be the number of ways of choosing the triplets where $$$gcd(a_i,b_i)$$$ is exactly $$$x$$$. You can calculate array $$$res$$$ from $$$preres$$$. If you know the values of $$$res_y$$$ for all $$$y$$$ (where $$$y$$$ is a multiple of $$$x$$$) and $$$preres_x$$$, then you can calculate the value of $$$res_x$$$ and finally, $$$res_1$$$ will be the answer. You can do this by iterating from $$$3*10^5$$$ to $$$1$$$.

    The time complexity is sum of harmonic sequence $$$\sum_{x = 1}^{N} \left \lfloor \frac{N}{x} \right \rfloor$$$ which is equal to $$$O(nlogn)$$$.

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

Of all the rounds this had to happen in a round full of Jojo's references

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

Can someone please tell me what was wrong with C? My approach to solving C was: Group all the guests having the same liking. Now assign the biggest group to the largest table. If some guests are still left, insert them in the priority queue and continue this way.

How was C an NP hard problem?

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

Even though C couldn't be solved with given constraints during the contest I think it's better to lower constraints to make it solvable, write a proper solution and post the updated solution in the editorial, instead of completely removing it from the contest and archive. The problem is not bad at all, tbh.

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

    It's NP-hard, which means it almost certainly cannot be solved in polynomial time. Constraints would require $$$n$$$ to be about $$$20$$$, or maybe even less! The brute-force solution would be incredibly dull. There may be heuristics to speed it up and allow a little higher constraints, but this is not suitable for CP.

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

Can anybody tell me "correct" solution of C? or at least some ideas

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

Can anybody tell me "correct" solution of C? or at least some ideas

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

I would surely become a specialist after this round (rank 16) but...... It's unrated! And problem G is kind of rigid that almost everyone who has learnt sam before can solve it.

But anyway,the problems are excellent!

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

can someone explain what's wrong with problem C. Instead of posting correct solution why authors completely removed problem C

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

D was quite confusing cuz I have never solve interactive problems lol. F was easier than normal :V.

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

I don't understand the tutorial for problem G. Can anyone explain the idea of it?

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

Does any one know how to calculate the time complexity of G? More detailedly,the time complexity of find the number of x,which is a factor of n, that l<=x<=r? The solution implied that is almost nlog(n) in total , but I can't understand why.

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

how do we get the root L bound in problem E. Can someone prove