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 | 4009 |
2 | jiangly | 3821 |
3 | Benq | 3736 |
4 | Radewoosh | 3631 |
5 | jqdai0815 | 3620 |
6 | orzdevinwang | 3529 |
7 | ecnerwala | 3446 |
8 | Um_nik | 3396 |
9 | ksun48 | 3388 |
10 | gamegame | 3386 |
# | User | Contrib. |
---|---|---|
1 | cry | 164 |
1 | maomao90 | 164 |
3 | Um_nik | 163 |
4 | atcoder_official | 161 |
5 | -is-this-fft- | 158 |
6 | awoo | 157 |
7 | adamant | 156 |
8 | TheScrasse | 154 |
8 | nor | 154 |
10 | Dominater069 | 153 |
Name |
---|
Editorial will be 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 own
baby giant: see how radewoosh and tourist solved
finally : editorial is missing
Really 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]).
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 2 after 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
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.
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 generatecnt
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.
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.me/blog/entry/68775?#comment-531293
Thanks!
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.
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.me/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?
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 :(
can anyone tell me in DIV2E/DIV1C how to greedily do matching stuff.
is there any algorithm which i need to learn in order to solve this.
Thanks for reading out :)