XXI OpenCup GP of Nizhny Novgorod
source link: http://codeforces.com/blog/entry/87510
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.
9 months ago, # |
How to solve L, E, C?
-
C: The answer is ϕ(n)⋅(n−1k−1)ϕ(n)⋅(n−1k−1), which you can compute in O(k)O(k) time (note that k≤n4k≤n4 so it's barely fast enough.
E: Compute a maximum matching (of size MM) using Edmond's Blossom Algorithm. Basically, you can reduce the problem of whether there is a vertex cover of size MM to 2-SAT (because the vertex cover must contain at least one vertex per edge in the matching), which you can solve in O(m+n)O(m+n) time. For the case M+1M+1, try all extra unmatched vertex to take into the vertex cover as well as all edges in the matching where both endpoints are taken.
9 months ago, # |
How to solve H?
9 months ago, # |
Thanks for participation! Link to the editorial in the post, it should be clickable, but if it isn't, please write me.
9 months ago, # |
How do you solve B?
I'm not sure if it's intended, but problem I can also be solved using the observation that to get minimum cost to buy ii souvenirs it always makes sense to keep all the i−1i−1 souvenirs from before, and buy one extra ( not necessarily at time ii ). So, one can solve it by iteratively picking the next cheapest souvenir and updating the costs. Fast simulation of this procedure can be done with sqrt decomposition and CHT. Complexity is O(NN−−√)O(NN). Code
-
If that holds, then you can also solve the problem in O(nC1/3)O(nC1/3) without assuming that all pipi are distinct, by grouping items with equal pipi, and noticing that if we have a group of elements with equal pipi, and in the optimal solution to dp[i][k]dp[i][k] we take mm of them, then in dp[i][k+1]dp[i][k+1] we take mm or m+1m+1 of them.
I didn't notice that all pipi are distinct during the contest, so this was what I did. I don't know how to prove that that observation holds, though.
9 months ago, # |
What could be any unproven algorithm of your choice in problem E? Before, I usually used "many times take any unmatched vertex and match it with the random neighbor", but it let me down this time.
-
I'm pretty sure you can't just solve max matching just by trying random matchings; there are graphs with few max matchings, so finding one randomly is probably impossible.
I think the editorial is referring to randomized algorithms like https://github.com/kth-competitive-programming/kactl/blob/master/content/graph/GeneralMatching.h.
9 months ago, # |
In fact, L can be solved much simpler in Python. Extended Stirling formula ln(n!)=12ln(2π)+(n+12)lnn−n+112n+O(n−2)ln(n!)=12ln(2π)+(n+12)lnn−n+112n+O(n−2) works like a charm even for n=104n=104, as the coefficient in O(n−2)O(n−2) is really small (I believe it is something like 11441144). The only problem is that we can't calculate lnln precise enough in C++, so we need to use Bigdecimal type
18 hours ago, # |
The editorial for problem L says that while multiplying by the factor 2(R+1)B+R+12(R+1)B+R+1"If we skip first B−−√B operations, each next B−−√B operations will multiple the answer by at least 2". Why does this condition holds?
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK