Tutorial is loading...

Tutorial is loading...

Tutorial is loading...

Tutorial is loading...

Tutorial is loading...

Tutorial is loading...

Tutorial is loading...

Tutorial is loading...

# | User | Rating |
---|---|---|

1 | tourist | 3735 |

2 | MiFaFaOvO | 3681 |

3 | Um_nik | 3553 |

4 | Benq | 3376 |

5 | ecnerwala | 3295 |

6 | maroonrk | 3229 |

7 | TLE | 3223 |

8 | Radewoosh | 3216 |

9 | scott_wu | 3209 |

10 | Petr | 3205 |

# | User | Contrib. |
---|---|---|

1 | Errichto | 204 |

2 | antontrygubO_o | 190 |

3 | pikmike | 187 |

4 | Monogon | 185 |

5 | vovuh | 184 |

6 | Ashishgup | 182 |

7 | Um_nik | 180 |

8 | SecondThread | 174 |

9 | Radewoosh | 172 |

10 | ko_osaga | 161 |

Tutorial is loading...

Tutorial is loading...

Tutorial is loading...

Tutorial is loading...

Tutorial is loading...

Tutorial is loading...

Tutorial is loading...

Tutorial is loading...

Tutorial of Codeforces Round #576 (Div. 1)

Tutorial of Codeforces Round #576 (Div. 2)

↑

↓

Codeforces (c) Copyright 2010-2020 Mike Mirzayanov

The only programming contests Web 2.0 platform

Server time: Aug/12/2020 01:05:57 (h1).

Desktop version, switch to mobile version.

Supported by

User lists

Name |
---|

Editorial

willbe published.Editorial had published*

`Now we have to choose no more than K consecutive values in such a way that they cover as much elements as possible`

Shouldn't it be

`Now we have to choose no more than K consecutive values in such a way that they cover as less elements as possible`

No

The more elements it cover, the less it has to be changed.

Could any one please explain (Div1 F) more clearly because I find it actually hard for me to get the proves for those observations.

also (Div1 D) the same thing.

any help would be appreciated.

thanks,

Isn't it better to use kuhn's algorithm for problem Div 1 E if we want to find max matching?

Ups I am probably wrong

It's not a bipartite graph and kuhn munkres only works on bipartite graphs. Plus kuhn munkres will probabably TLE. Correct me if I am wrong

"...we will build a bipartite graph "

We can not build a bipartite graph if the graph contains odd cycles...

Left part — columns Right part — rows

The graph you are building is bipartite and what you want is indeed max matching, but when you compress vertices you turn $$$m$$$ edges going into $$$m$$$ equivalent vertices into a single edge with capacity $$$m$$$. So the problem you actually solve in the compressed representation really is maxflow and not just max matching.

Thanks

For div1 A doesn't the N change every time you compress?

No, the n is the length of the array, not the amount of different values in the array.

My alternate solution for C:

Consider the DFS Trees of the connected components in the graph, we can pair the nodes in such a way that only nodes left unpaired are leaves by pairing each unpaired node with a random child, so in worst case we have got a matching of (3*n-x)/2 edges where x is the number of leaves. if (3*n-x)/2 >= n, output this otherwise x must >= n , so output any n leaves. Note that the leaves form an independent set because in DFS tree all non-tree edges go to an ancestor.

Are the top 6 solutions really of only of 3 — 4 lines and rest 6-8 lines or you did a huffman coding on them ?

very short. one can write editorials like :

basically we can do it in O(n^5) by using our mind.also it can be written as :

AA! this is easy , look other solutions for it.morover :

It can be solved in O(N)a step forward :

you can use any langauge to solve this problem. solve it on your ownbaby giant:

see how radewoosh and tourist solvedfinally :

editorial is missingReally no intention of writing editorial. wrote just for formality

Let's do subset DP — our state is what primes are still alive. This solution has complexity O(n^2 2^k).__ what about transitions. You can write it like : No need to look at editorial, solve using dp.He explicitly gives you the dp states and the transition is just naive. He may assume that people who read this editorial have a basic sense of how dp works (bcs it's a Div1 pF), and the transition is just an (and trivial) exercise. If you really have no idea what he says, then do some exponential states dp problems first, or just simply ask for details here instead of complaining.

This is absolutely true

I wanted to say exactly that

Editorial is perfectly fine. He gave the crucial observation required for the recurrence(_Of course, we can cover all rectangle with itself for cost W. To get something smaller than W we have to leave at least one column uncovered — otherwise we pay at least sum of w over all rectangles which is at least W._). If you want everything comprehensively for the simple things, you just destroys that problem for yourself instead of gaining something from it.

in div1C/div2E can you prove the line : "Either matching or independent set has size at least n"?

You keep choosing edges for a potential matching, as long as there is an edge between two unused vertices. If the number of edges you find in this manner is at least n, you found a matching of at least n edges. Otherwise, you have used fewer than 2n vertices and there are at least n vertices remaining, which have no edge between any two of them. Therefore the unused vertices form an independent set of size at least n.

Got it! Thanks!

Thank you so much!

I'm getting time limit exceeded on div1C, even though my solution is O(n+m) like the tutorial says. Is 1 second too short given the input constraints or am I missing an easy way to improve my solution?

Update: Accepted when I added

`ios::sync_with_stdio(false);`

Could you please explain what does this do

Solution got TL on tests with large input, so the problem is how to read a lot of data fast. You can read how the thing above optimizes the time here: https://en.cppreference.com/w/cpp/io/ios_base/sync_with_stdio (Using of printf and scanf usually fixes all the issues connected with input/output, so by using them you can protect yourself from stupid TLs)

The time constraints do seem rather tight in this set given the input sizes and expected time complexity...

Can someone plz explain for Div2/D How can we do it in O(n+q)?

You can use count sort and two pointers, but that wasn't needed. My solution is $$$O(q + n \cdot log(q))$$$.

Loop from the last query to the first. If we get query type 2, save the maximum type 2 from the last query to the moment. Otherwise, if we get query type 1, update the value at index x with max(max_type_2_now, value from query) and flag it so we will never update it again.

After the query done, loop through the entire array. If the cell is not flagged, update the cell with max(max_type_2, A[i]).

Got it! Thanks for your explanation.

I used another approach in div1-C / div2-E. I'm not sure if my idea is correct. Can someone give me a counterexample (or hack my solution) ?

Submission : 58029374

Idea : sort all the nodes with respect to their degree. First let's try to form an independent set. So we iterate through the nodes and if it isn't marked, then we add it to our list and marked all its neighbours. If the list has size >= n , we're done . If size < n , we do almost the same in order to find a matching. In the same order we iterate through the nodes and if it isn't visited we try to find a neighbour that is not visited. If we find such a pair, we add it to our list of matching and we visit both nodes. But I'm not sure if this matching has size >= n in all the cases.

Done

Thank you very much

tourist orz

A smaller case click here (idea from tourist)

@Um_nik Please provide code implementations of problems DIV 1:C,D,E.it would be 25 min work for you, but it would be of great help in understanding the code details of the solution.

1198B — Welfare State

Could someone explain efficient way of finding

maximum of all x for queries of type 2after latest query of type 1? I can't invent fast solution unless using sparse table. Thank you in advance.It is quite simpler than that, just maintain a suffix array lets call it maxSuff of size q and for each query of type 2 assign maxSuff[i] to x, where i is the index of that query

and then run a loop through i from q-1 to 0 and assign maxSuff[i] to max(maxSuff[i], maxSuff[i + 1])

solution for better understanding 58077496

Quite an interesting idea. Thanks :)

May someone please explain how the formula was derived in Div2 B? Thanks.

Note that the length of the flower will remain constant. When the flower was straight the length = depth of river(d) + H. When the flower is tilted then you can apply Pythagoras theorem where the hypotenuse= length of the flower.

First of all, you have to notice that green lines are equal.

Pythagorean theorem for triangle: Ans^2 + L^2 = (Ans + H)^2

Solve the equation above.

Got it, thanks.

How is the following solution wrong?

https://codeforces.com/contest/1199/submission/58065770

At worst I would have got an TLE. I think I am doing something similar to the tutorial, simulating the entire problem.

It is hard to understand your code. Can you explain your approach? Here's my submission where I just checked for every day in summer whether the rain is minimum on ith day as compared to x days before and y days after. Plz note that it may be possible that and can be i<=x or i>=n-y day since days before 0th day and after n-1th day are not a part of summer and hence will not be observed by citizens.

From a position, i, I am checking if there are enough days to its left segment which are all greater, and to its right segment which are all greater. The first instance of such a situation is when I output i+1(i is 0 based) as a valid day. The two segment represent left x and right y positions form i for the condition in the question to be satisfied.

Thank you.

Note that for indexes i<=x it is enough to check that a0,a1,..a_{i-1} are all greater than ai. So, your segment can be of length less than x for i<=x and same goes for i>=y.

Look like that is where I messed up. Gonna sleep now. Will fix it taking into your recommendation into account. The editorial looked pretty similar to simulating the problem which I seem to be doing. Thanks.

The time limit + test size for 1198A — MP3 is really tight. My Kotlin solutions pretty much match the tutorial solution but this one didn't pass, and this one only barely passes (2 ms to spare!) after I switched to a TreeMap for the counts and an IntArray for the prefix sums. I wonder if anyone could pass this with something like Python.

Edit: And when I tried to bypass storing the values in an

`a`

List or IntArray and generate`cnt`

straight away it won't pass test 13, with significant slowdown on test 12. Optimization is a fickle business...F: Did you include complexity of choosing pair in the final complexity? In my solution, it raises a factor of $$$k$$$ in a determined way. If we are given such pair, mine works in $$$O(2^{2k} + kn)$$$. For each prime in at most $$$2k$$$ primes, choose an element that kills it and is not selected. Now we have at most $$$2k + 2$$$ numbers to consider. Simple bitmask results in $$$O(2^{2k})$$$.

Edit: It is wrong and test cases are weak :). There are $$$O(k^2)$$$ numbers to consider. Another way: $$$dp[mask]$$$ is the earliest time to reach $$$mask$$$ will result in $$$O(k2^{2k})$$$.

Number of pairs to check is constant

The editorial is too concise to be understood. It's perfunctory.

yeah, Editorial won't be published, but there is a surprise when clicking the link:)

Can someone explain 1198A — MP3 in detail?

please anyone explain div1 D how take base condition and How do we perform transitionss?

For Div2E/Div1C, Can someone please help with a formal proof for always having at least n matching or independent set?

https://codeforces.com/blog/entry/68775?#comment-531293

Thanks!

I'm struggling to find the mistake in my code for problem "1198A — MP3" and my approach continues to fail on 13th test case. Here is the link to my code: https://codeforces.com/contest/1199/submission/58130722. Can somebody look over it please? Thanks.

Understood the mistake, no need for help anymore.

problem c did the same thing and got WA during the contest

div2D (div1B) is easier than div2C (div1A), and not only for me.

Um_nik, sir why there aren't any solution in the tutorials? I mean one could have a better understanding of the your tutorial after looking at a solution implementing the same idea as provided in the tutorial, I guess.

https://codeforces.com/contest/1198/standings/friends/true

hi, can anyone help me with painting rectangle 1. i dont understand why there is x1,x2,y1,y2 and i saw alot of coder using recursive solution, i dont know where that came from.. thanks

In Div1-F, You don't need to randomize the algorithm for choosing two numbers from different groups. If $$$n \geq 10$$$ and there is a solution, then there is also a solution in which the first number is in a different group from one of the next $$$9$$$ numbers, so you only need to check these $$$9$$$ pairs. This is true because otherwise, all $$$10$$$ numbers would need to be in the same group, but then you can just remove one of them because $$$k=9$$$.

You don't need to, but it is faster

For Div1 E, O(n^5) seems to be too expensive to pass. Can anyone explain why it would fit into the time constraint?

Use pragmas

Is it ok for u to elaborate more?

$$$50^{5} = 3.125 \cdot 10^{8}$$$, how can it be TL? Moreover, it is divided by 6 because left border is smaller than right and similar things.

I would say that 10^8 is a pretty dangerous bound.... Plus is it ok for you to explain why this number is devided by 6? I know it is pretty intuitive for you but it is kindda hard for me to see.

$$$10^{8}$$$ is nowhere near dangerous.

If we are trying all $$$x, y, z$$$ such that $$$1 \le x \le y \le z \le n$$$, there are ~$$$\frac{n^{3}}{6}$$$ such triplets.

Thanks for explaining, that helps a lot!

For problem 1198A — MP3: First, I sort the distinc numbers array and I use binary search to find out how many distinct numbers we should keep exactly. We know that these numbers must be consecutive so I use prefix sum to get the answer. https://codeforces.com/contest/1199/submission/58250549

Can you explain your code after you've assigned the n*ceil(log2(i)) to arr[i]?

What is savNum? Can you explain that line?

Can Any one give me the code for the problem A

1199A — City Dayor give me any hint please?I am not understanding this portion

The mayor knows that citizens will watch the weather x days before the celebration and y days after. Because of that, he says that a day d is not-so-rainy if ad is smaller than rain amounts at each of x days before day d and and each of y days after day d. In other words, ad<aj should hold for all d−x≤j<d and d<j≤d+y. Citizens only watch the weather during summer, so we only consider such j that 1≤j≤n.Thanks in Advance

what is wrong in my code it is giving wa on test case 9 ..in div2 c MP3 ...my submission is https://codeforces.com/contest/1199/submission/58339875

guys can soneone help me to understand the problems???I am a beginner

Could somebody help me understand my mistake in problem C-MP3 DIV2 ??

My idea

I choose the right K the number of distant elements in the vector that I shouldn't go beyond if I have already less in my vector ---> 0 Otherwise I sort the vector and I use a map to give me the number of occurence of each element I use two pointers i and j one from beginning and one from the end I compare between these two elements and I change the ones having minimum occurence 58923419 :))

Can someone explain me welfare state problem in detail

for

MP3problem, i am getting WA on test case 11, i can't find out the reason. can anybody help? my solution : https://ideone.com/nxUse4It's probably too late. But I had made the same mistake and was stuck on it for about a day. If you are still curious, the problem will arise in the case where the number of elements on both sides are equal. Make a couple of cases and you'll get the issue.

I found this guy flashmt use an algorithm with $$$O(n^4)$$$ in this submission 58039307. I had a hard time finding out why it is correct, and finally, I found it could be hacked by this input

The output should be $$$7$$$ while his output is $$$9$$$.

Yeah, my solution is wrong and it was already hacked here. Sorry for wasting your time trying to understand it :(

Need help 1198A-MP3 in my submission

Deleted