16

Codeforces Round #670 (Div. 2) Editorial

 2 years ago
source link: https://codeforces.com/blog/entry/82560
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Upd: fixed author's solution links.

Sorry for the slow Editorial, I am new using Polygon.

Special thanks to TechNite for his help.

About one hour before the contest _cherry_ found the same problem, then we changed it to k=4k=4 and he found another same one again. We are running out of time so we didn't have time for a new one, so we changed kk to 55. But we didn't know there is still a similar problem. Sorry again.

1406A - Subset Mex

Let us store the count of each number from to in array .

Now would be the smallest for which .Let this be . would be smallest for which . This is because one count of each number less than would go to therefore the element which was present initially once would now not be available for .

Overall Complexity: .

idea:gyh20 solution:gyh20 tutorial:TechNite

Jury solution:92671575

1406B - Maximum Product

First, if all numbers are less than , then you should print the product of the five biggest numbers of them.

Otherwise, the maximum product must be non-negative. Sort the numbers by their absolute value from big to small.

If the first five numbers' product is positive then print it. Then we can always change one of the five to one of the other numbers to make this product positive. Enumerate which one to replace, and you can solve this problem in time.

idea:tianbu solution:tianbu tutorial:tianbu

Jury solution:92671590

1406C - Link Cut Centroids

Let vertex be the root of the tree. If there is only one centroid, just cut any edge and link it back.

Otherwise there are two centroids. Let them be and , then there must be an edge connecting and . (If not, choose any other vertex on the path from to and the size of the largest connected component after cutting it will be smaller than and ).

Let be 's father. (If not, swap and ) Then just cut a leaf from 's subtree and link it with . After that, becomes the only centroid.

Proof: It's easy to see that the size of 's subtree must be exactly . After cutting and linking, the maxinum component size of becomes while the maxinum component size of is still .

idea:gyh20 solution:gyh20 tutorial:tianbu

Jury solution:92671713

1406D - Three Sequences

Since sequence is non-decreasing and sequence is non-increasing, we need to mimimize .

Now observe that if then and .Else if then but . Now we calculate .Let this sum be . Now lets assume is . So then is .And as observed before .

Now we just need to minimize . Now it is easily observable that should be .

For the changes, since we only need to know , so only and will change.

Total time complexity: .

idea:isaf27 solution:gyh20 tutorial:TechNite

Jury solution:92671763

1406E - Deleting Numbers

If we know what prime factors x has, we can find just using bruteforce.

To find the prime factors, we can just do for every prime in ascending order, meanwhile calculate the numbers there supposed to be without , if it differs with the number the interactor gives, then contains the prime factor .

This way, we can find every prime factor except for the smallest one.

Let be the number of primes no greater than .

Then we can split the prime numbers into groups.

After finishing asking a group, ask and check if the return value same as it supposed to be without . If it's the first time finding it different, it means the smallest prime number is in the range, then just check every prime numbers in the range by asking .

After finding the prime factors, for each factor, ask , it can be proved this step will be done around times.

The total number of operations if around , the total time complexity is

idea:gyh20 solution:gyh20 tutorial:gyh20

Jury solution:92671740


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK