8

XXI OpenCup GP of Nizhny Novgorod

 2 years ago
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.
neoserver,ios ssh client
By Um_nik, history, 9 months ago, In English

Time: Feb 7, 11:00 UTC+3

Link: Click (OpenCup login needed to participate)

Authors: Um_nik, Merkurev, KAN, WYOCMWYH with help from I_Remember_Olya_ashmelev, Ferume, fake123 and dario2994.

The contest was used for Petrozavodsk training camp and ICPC training camp.

Editorial

9 months ago, # |

How to solve L, E, C?

  • 9 months ago, # ^ |

    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, # ^ |

    Rev. 2  

    +1

    The contest is still running for Div.2 :) As it was postponed 3 times, and then started, but without problems(!), and so later it restarted again :)

    UPD. It's just finished. How to solve Div.2 Problem H. "Ending by 3"?

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?

9 months ago, # |

Rev. 2  

+38

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

  • 9 months ago, # ^ |

    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, # ^ |

      You can prove the observation by considering this as a min-cost matching problem. The addition of one new "slot" can only add one new augmenting path, which must consist of taking one new souvenir and shuffling some others around.

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.

  • 9 months ago, # ^ |

    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, # ^ |

      I think referring to some heuristic algorithms for finding augmenting paths which don't have good time bound in non-bipartite graph.

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)ln⁡n−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

  • 9 months ago, # ^ |

    Or use a "better formula" (courtesy of Wikipedia):

    Of course, with a brute force when kk is small.

  • 9 months ago, # ^ |

    The issue is not in calculation of lnln itself, the issue is in taking difference of them, which creates awful relative error.

    • 9 months ago, # ^ |

      But it's good enough if you use Python and tell its Bigdecimal to have, say, 50 decimal digits of accuracy.

5 weeks ago, # |

How to solve G,I,J?I don't know why so many people solve the problem G.

  • 5 weeks ago, # ^ |

    There is a link to the editorial in the post.

    • 5 weeks ago, # ^ |

      Thank you.

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?

  • 30 minutes ago, # ^ |

    Each multiplier is at least (1+1B√)(1+1B), there are B−−√B of them, (1+1k)k≥2(1+1k)k≥2 for any k≥1k≥1.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK