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

Автор gyh20, 6 лет назад, По-английски

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 Retired_cherry found the same problem, then we changed it to $$$k=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 $$$k$$$ to $$$5$$$. But we didn't know there is still a similar problem. Sorry again.

Tutorial is loading...

idea:gyh20 solution:gyh20 tutorial:TechNite

Jury solution:92671575

Tutorial is loading...

idea: feecIe6418 solution:feecIe6418 tutorial:feecIe6418

Jury solution:92671590

Tutorial is loading...

idea:gyh20 solution:gyh20 tutorial:feecIe6418

Jury solution:92671713

Tutorial is loading...

idea:isaf27 solution:gyh20 tutorial:TechNite

Jury solution:92671763

Tutorial is loading...

idea:gyh20 solution:gyh20 tutorial:gyh20

Jury solution:92671740

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

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

Thanks for the fast editorial! It was an amazing contest (besides problem B)!

UPD: Problem E editorial has a typo: tutotial -> tutorial.

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

    Hi, in 1406B — Maximum Product, after sorting in descending order, i think it is feasible to check only 3 values that are 5 entries from top and none from bottom, 3 from top and 2 from bottom, 1 from top and 4 from bottom and then simply find their max :)

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

Couldn't solve E, but it was interesting(atleast to me).

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

Auto comment: topic has been updated by gyh20 (previous revision, new revision, compare).

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

The solution link is not working sir!!!.. Please check it once. Thank you

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

Auto comment: topic has been updated by gyh20 (previous revision, new revision, compare).

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

nice problems, liked the centroid concept!! .... hope to see more like this

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

I used a different approach for C: 1. First I found the tree diameter. 2. Then I rooted the tree at one of the centres (if there are 2) and calculated the subtree sizes. 3. Then for each node of the tree diameter, I calculated the maximum subtree size that would be generated when I remove that node. 4. I found the minima over all these subtree sizes, the node/s which give this minima are the centroids. 5. If there is a unique centroid, I removed any edge and rejoined it. Else, I took a leaf, removed the edge between it and the parent, and joined it to one of the centroids. I don't know why my solution fails at test case 6. https://mirror.codeforces.com/contest/1406/submission/92644162 Thanks in advance.

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

A few typos in the first line of the solution explanation for problem D. It should be:

Since sequence $$$b$$$ is non-decreasing and sequence $$$c$$$ is non-increasing, we need to find $$$max(c_1, b_n)$$$.

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

I had a different and much simpler approach to B.

Firstly, sort the array from smallest to largest (no absolute value). After the sort, it can be proved that the answer is either a[n-1]*a[n-2]*a[n-3]*a[n-4]*a[n-5], a[n-1]*a[n-2]*a[n-3]*a[1]*a[0], or a[n-1]*a[3]*a[2]*a[1]*a[0]. Take the maximum of these three values as the answer. The logic is pretty self explanatory.

My submission: 92587656

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

    I had a slightly more complicated to code but really easy to understand.

    I took the first 10 numbers and the last 10 numbers of the sorted array(handling the case when $$$1 \le n \le 20$$$). Then I bruteforced through all the combinations of 5 numbers from the 20 numbers. I then took the maximum of all of those products.

    Link to submission 92660785. Please tell me if you don't understand my code because of all of the macros.

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

"maxinum component size of x" it should say "maximum component size of x" (for problem C)

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

I have a slightly different solution for E using binary search that might be more intuitive. First, brute force all prime factors which are $$$\leq \sqrt{n}$$$, for $$$n = 1e5$$$, there are only $$$65$$$ such primes, and we can check each exponent for all in ~$$$200$$$ queries(even less if we binary search on the exponent). Then, for the higher primes only one such prime can appear, so we binary search on the rest of the primes with the following algorithm:

Let $$$num$$$ be the amount of numbers left in the set.

Consider some search space of primes $$$[l, r]$$$

Ask B for all primes $$$[l, mid]$$$, subtract the result of the query from $$$num$$$

Ask A 1

If the result of A 1 and $$$num$$$ differ, the last prime is in the range $$$[l, mid]$$$, otherwise it is in the range $$$[mid+1, r]$$$

This part takes at most $$$m + log(m), m = \pi(n)$$$ queries so it easily passes.

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

I thought that there should be atmost most 2 centroids in a tree is it correct?

If it is how to prove it ? And if it's not then why, I was not able to find an example.

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

    Assume that node x is one of the centroids of the tree.

    Make x the root of the tree

    Here, we denote sz(a) as size of the subtree of a

    According to definition, sz(child of x) ≤ (n / 2). (1)

    We have another observation: The size of the subtree of a node < size of the subtree of its parent (2)

    If there are one centroid => We are done

    Else, let y be another centroid of the tree.

    When we delete y, the subtree that doesn't contain the subtree of y is connected, so its size must ≤ (n / 2) according to definition

    => sz(y) ≥ (n / 2) (3)

    From (1), (2) and (3), sz(y) = (n / 2) and y is a direct child of x

    If there is another node z which is another centroid of the tree (now we have 3 centroids), then sz(y) + sz(z) + 1 (node x itself) = n + 1, and since y and z are directed childs of x, their subtrees don't share any node.

    => The graph has ≥ (n + 1) node (contradiction)

    => There are at most 2 centroids in a tree (Q.E.D)

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

SpeedForces
GoogleForces
CopyPasteForces

B and C seemed rather standard. I recognized B as an E problem from a recent ABC round. However, I didn't bother to go looking for it and then copy and paste a solution. For D, I googled "how to find centroid of a tree" and "how many centroids are in a tree". The latter gave me

Spoiler

Which basically trivialized the problem.

Nevertheless, A, D, and E seem quite nice. I found this round rather interesting (especially problems D and E).

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

    We are sorry for making problem B.

    But for C, the point of the problem is not to find the centroids, but what to do next. So in my opinion, I don't think C is very standard.

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

Can anyone tell me why my code is giving runtime error on test 1?

https://mirror.codeforces.com/contest/1406/submission/92659872

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

In E I believe you should add $$$\sqrt{m}$$$ to your estimate. You do $$$\sqrt{m} \cdot \sqrt{m} + 1 \cdot \sqrt{m}$$$ and in at most 2 buckets you'll find a prime that divides $$$x$$$, so you need to add $$$2 \cdot \sqrt{m}$$$ for that. And later there is that $$$\log_2(n)$$$ and one for answer, so counting this way we get $$$m + 3\sqrt{m} + \log(n)$$$.

Also I don't understand why the first 3 paragraphs of its tutorial are there, in my opinion they are quite confusing.

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

Can someone explain this line from the editorial of question E. After finishing asking a group, ask A 1 and check if the return value same as it supposed to be without x.

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

First, if all numbers are less than 0, then you should print the product of the five biggest numbers of them. Otherwise, the maximum product must be non-negative. Its false. How about -1 1 2 3 4?

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

Problem D. Three Sequences Youtube Video Explanation in Hindi. Solution Explanation Youtube Link

If SomeOne is Upsolving Problem D and needed some help in solution explanation in hindi. please watch above video and give feedback to improve quality. Thanks

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

can anyone explain solution of 3rd problem? I can't understand why dfs is used here?Can it be solved without dfs like if we can find out 2 centroids by checking the largest component which is smallest by removing each vertex one by one and than if there are 2 or more centroids we can remove one edge from one centroid and connect to other centroid??

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

I think the problem C and E is interesting,but problem A is not easy enough to put it on A.It can be B.

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

Can anyone tell me why my code is wrong?(Problem E)

https://codeforces.ml/contest/1406/submission/92640804

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

About centroids. Editorial says "If not, choose any other vertex on the path from x to y and the size of the largest connected component after cutting it will be smaller than x and y". Looks like this is impossible and centroids are always connected. If I am correct, please remove this confusing comment

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

I cannot see the Jury's solution for E. It shows "You are not allowed to view the requested page".

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

I think there are some typos in the editorial of problem D:

  • sequence $$$b$$$ is non-decreasing and $$$c$$$ is non-increasing (as in the problem description).

  • and then, it should say $$$\max(c_1, b_n)$$$.

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

About problem E:

I didn't notice that $$$1\le a\le n$$$!

What a pity!I almost made it to the top 20!

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

Auto comment: topic has been updated by feecIe6418 (previous revision, new revision, compare).

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

I can't view pC's solution(submission), does it only happen to my account or is it private ><

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

Though I've lost so many ratings,I enjoy the contset very much.

THX for such a wonderful contest!!!

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

Does anyone have a neat proof that definition of the centroid given in C matches the standard definition of centroid (disconnecting it separates the tree into connected components all <= n/2 in size)?

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

    Let us root the tree at centroid (curren't problem's definition of centroid), and sz(x) be the size of subtree of vertex x, now sz(x) is the smallest possible largest connected component upon deleting a vertex s, now assume sz(x) > (n/2), now the largest connected component upon deleting x would be max(n-sz(x), max(sz(y1))) where y1 are x's children, sz(y1)<sz(x) and n-sz(x) < n/2 (as sz(x) > n/2), so either way the sz(x) would not be the smallest possible largest connected component and hence s is not the centroid, hence a contradiction. We can extend this to say that both the centroids should by adjacent, with the equation sz(x) + sz(y) = n (where y is another centroid)

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

      Excellent. Although hard to wrap my mind around "We can extend this to say both centroids must be adjacent". Could you explain a bit more? Thanks!

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

        Tree is still rooted at s, there is some other centroid out there y, let it's children be yi, now the largest component upon deleting y is max(sz(yi),n-sz(y)), now sz(yi) < sz(x) so if this also centroid, then n-sz(y) = sz(x), as both produce the smallest possible largest component, hence sz(x) + sz(y) = n, but sz(x)<=n/2, and sz(y)<=sz(x) as upon deleting the root, the largest component we get itself is sz(x), the only scenario where the above eqns can be satisfied is sz(x) = sz(y) = n/2 and y is child of s, but if y!=x then sum of subtree's of child itself becomes n, so the only way out is y equals x. So there can be atmost 2 centroids, both adjacent.

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

Can someone find me a video editorial for problem C. Thanks in advance!

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

can anyone help ,where my logic get wrong for B. Maximum Product https://mirror.codeforces.com/contest/1406/submission/92678443

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

In Maximum Product(B) it is written that i<j<k<l<t .. then why sorting ? It will definitely change the order.

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

Can someone tell what is wrong in my solution for problem B. It is giving me WA on test 2 for the 143rd input.Thanks in advance.

https://mirror.codeforces.com/contest/1406/submission/92649674

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

There is another solution for problem B with dynamic programming. That approach seems not to be the easiest one, but I would like to share it just in case it may be interesting for someone.

Submission: 92600395.

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

Nice round! Thanks~

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

In Problem B, I am getting wrong answer on test 2, more specifically on 143rd input — answer is not matching . Can anyone please point me out where I am going wrong? Link to submission — https://mirror.codeforces.com/contest/1406/submission/92680690

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

My solution for C :

If there are two centroids, I pick one of the centroids and disconnect one of its non-centroid subtree and connect that subtree to the other centroid. Will this always work?

My submission : 92632074

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

Does anyone knows any good tutorial/blog for finding the centroid of a tree?

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

Hi, in 1406B — Maximum Product, after sorting in descending order, i think it is feasible to check only 3 values that are 5 entries from top and none from bottom, 3 from top and 2 from bottom, 1 from top and 4 from bottom and then simply find their max :)

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

Am I the only one who tried solving D using range updates and range maximum queries? I feel stupid.

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

For problem D, how to prove that this arrangement will be optimal and gives us the least possible max(c1,bn) ? For example say d = a(i) — a(i-1), when d > 0, b(i) = b(i-1) + y(aribitary y), c(i) = c(i-1) + d — y(arbitary y), how to prove that in the optimal solution y = 0 ?

isaf27 gyh20 TechNite

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

In a tree, the center of the diameter and the centroid are different points, right? Please give me an example, I am unable to come up with one... Thanks in advance

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

For question 3

can anyone give me an example tree with more than 2 centroids? my assert(n<=2) statement is failing.

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

I solved [problem:1460E] in another way: "B i" for every prime in (n/2, n], then "A 1", check is your cnt equal to this: if not: "A i" == 1 for every prime in (n/2, n] -> ans *= i; else take (n/4, n/2] ...

And in the end check primes from (1, n / ans)

I mention that primes in (1, n/2] > (n/2, n], that's why you won't have more than enough queries

But the author's solution with sqrt-decomposition is better and easier — Sorry for the waste of time ))) Wanted to let you know about other solution :)

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

I think the total number of operations for E is around $$$M + \sqrt{M} \cdot log(M) + log(M)$$$

UPD : sorry I was wrong.

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

Can problem D find legal arrays of $$$b$$$ and $$$c$$$? upd:Oh, yes, it can be done.

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

In Problem C in the case of 2 centroids, instead of finding a leaf in a centroid and attaching to the other centroid I found an edge from a centroid other than the one joining the two centroids and attached it to the other centroid. My solution passed system tests. Is it right or is there any test case for which my solution fails?

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

problem B's tutotial: while the maxinum component size of x is still $$$\frac{n}{2}$$$.

I think it should be: while the maxinum component size of x is $$$\frac{n}{2}$$$ or $$$\frac{n}{2}-1$$$.

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

I am not sure I completely understand problem D. I have been trying for past 3 days but the queries part is not clear to me and the solutions I refer to also are not understandable Can someone please explain the queries part, how are we updating the elements in the range l..r or if not, then why not? I understood why we need only the two adjacent differences in every query but what about updating the elements? Please help me.I would appreciate it.

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

Can someone please explain how the updates are being made in editorial's solution? I looked at many codes but I am unable to understand anything from them? Please help me!!! I understood the rest of the solution.

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

can anyone explain the editorial of problem A. and why i got runtime error herehttps://mirror.codeforces.com/contest/1406/submission/93185539

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

Is problem A wrong? Why not split the set (0 2 1 5 0 1) into (0 0 2 5) and (1 1) to have mex of 1 and 0 respectively?

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

Hi guys, this is our solution for problem A. We would be happy to hear your feedback regarding the format. Thank you!

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

feecIe6418 For the problem 1406B - Maximum Product, you have asked to sort the given array based on the absolute values from big to small. And still how can the time complexity be O(N)?

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

Can anyone tell me why there is a Compilation error with GNU 17c++ and not with GNU 14c++ for same code.

GNU 17 c++ code -193989828

GNU 14 c++ code — 193989946

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

Can Problem B be solved using DP ? let dp[i][j] be maximum possible product using first i numbers and choosing j numbers of them to product them , where (1<=i<=n,1<=j<=5)?