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

Автор cgy4ever, история, 9 лет назад, По-английски
  • Проголосовать: нравится
  • +89
  • Проголосовать: не нравится

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

Contest will start in 1 day. It is sponsored by Booz Allen Hamilton.

Registration will start 4 hours prior to the start time, and will close 5 minutes before it.

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

Update: Registration is open now.

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

Your login request timed out !

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

I am not able to log in. It keeps redirecting me back to the homepage everytime I try.
Anyone else facing a similar problem?

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

How to solve Div.1 Medium?

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

    Do subsegment dp and always choose highest point first.

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

    If we take the highest ship and fix the cannon for this ship, we will divide our plane to left and right part. So, DP state is [segment of cannons][set of ships]. I don't know why is it fast enough, I have O(n5) solution without maps: DP state [left][right][ship for left][ship for right] (the idea is the same, but for my solution complexity is obvious).

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

      What do 'ship for left' and 'ship for right' mean in your DP state? Are them the two pointers of a ship subsegment? And do you sort the ships by x then y? If so, after separating the plane in two parts will we have a guarantee that the subsegment is indeed contiguous (let's say a non-vertical line separated the plane)?

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

        No. (left, ship for left) and (right, ship for right) are two segments which enclose current part of plane. Ships that are inside this part can be found in O(n) time (check for each ship in O(1)). Please read my code if you don't understand yet.

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

How to solve Div2 Medium?

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

I used some heuristic in 1000 which doesn't rely on the constraint on the number of edges at all. I'm wondering if I just got lucky and there's a test that breaks it or if for some reason it works correctly if the number of edges is between n+1 and n+5.

What I did was:

0) Initialize hashes of all vertices with their degrees.

1) Find a hash of each vertex by repeatedly doing the following (600 times, before the first iteration do it 5000 more times): for each vertex take hashes from previous step, sort them in ascending order, append its own previous hash and then map this vector to an integer from 0 to n-1 (distinct vectors get distinct integers).

2) Pick any unused vertex V, let C be the number of vertices with the same hash. Multiply the answer by C, mark V as used and set its hash to be equal to N (i.e. make it unique).

3) If there are no more unused vertices, return the answer, otherwise go to step (1) and use the current hashes as init values.

This solution will work if the hashes are always computed correctly and I guess in the general case the hash computation part will break. I'm wondering if there exists a counterexample for the constraints from problem statement.

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

How to solve Div2 1000 ?

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

    I haven't coded this but I guess this should work. We run a single DFS. For each vertex, we store the max 2 distances from that vertex to any leaf in its subtree, diameter of that subtree and the number of anti-podal pairs in that subtree.

    Suppose you are at vertex u. You have all the above values calculated for its children v1, v2,...vk. Let d be the max length of a path passing through u and in its subtree. Note that diameter_of_subtree[u] >= diameter_of_subtree[vi]. diameter[u] = max{d, max{diameter[vi]} }. So, diameter[u] > max{diameter[vi]} only when d > max{diameter[vi]}.

    You can use this to split the problem into cases.

    When diameter[u] == max{diameter[vi]}, then anti-podal[u] will be sum of anti-podal[vi], where diameter[vi]==diameter[u] and to this number add the number of anti-podal pairs whose path passes through u.

    When d > max{diameter[vi]}, then it is simpler. Just count the pairs of leaves in subtree of u, between which length of path is d.

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

    Solution: http://ideone.com/1woxtj
    There are 2 cases — diameter of optimal subtree is odd or even. If even, then there exists a unique center. If odd, there exists an unique center edge. Try all possible combinations: Both cases can be done via simple dfs once for each node.

    1. Try each node V as center of subtree — count d[i][j] = number of nodes at distance j from ith child of V then if tot_j = sigma_j(d[i][j] for a fixed j) then ans = for all j, max(ans,sigma_over_all_children_i_considering_V_as_root(d[i][j]*(tot_j-d[i][j])/2);
    2. Try each edge(i,p[i]) as center of subtree — count d[0][j] and d[1][j] = number of nodes at distance j from each of two ends i and p[i] then ans = for all j, max(ans,d[0][j]*d[1][j]).

      Total Complexity: O(n^2) since j varies to max n and each edge is considered once over all V in first case and once in second case.