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

Автор atcoder_official, история, 2 года назад, По-английски

We will hold Hitachi Vantara Programming Contest 2024(AtCoder Beginner Contest 368).

We are looking forward to your participation!

  • Проголосовать: нравится
  • +69
  • Проголосовать: не нравится

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

It really feels like A<B<C<D<F<<G<<<E

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

Bring back 'Aoki' and 'Takahashi'.

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

I got cooked in this contest.

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

How to do F?

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

    Imagine if you replaced every element of the array by its prime factorization. Then, replacing a number by a divisor just means that you take away some prime factors. Now, replace every number of the input by the number of prime factors it has, and the game is basically just a nim-game.

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

    Consider a sequence $$$( A_1, A_2, \dots, A_n )$$$. For each prime $$$( p )$$$, let $$$( v_p(A_i) )$$$ denote the $$$( p )$$$-adic valuation of $$$( A_i )$$$, which is the exponent of the highest power of $$$( p )$$$ dividing $$$( A_i )$$$.

    By calculating this $$$ \sum_{\text{prime } p} v_p(A_i)$$$ over all primes $$$( p )$$$ for every $$$( A_i )$$$, the problem becomes equivalent to the classic Nim game.

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

    Use Grundy Theorem ( short explanation ) :
    Consider a graph, in which from node x you can go to node y then, the grundy function for each node = MEX of the grundy function of child nodes. and the xor of all grundy values determines the winning or losing state.

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

Can someone please explain E problem?

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

    I don't know if this is the intended solution, but it is how I upsolved it.

    For each station, you can store the trains ending there, sorted by their original end time.

    You can also have a max segment tree of the trains ending there in this sorted order. This segment tree will store new end time (end time + delay).

    You then delay the first train and process the trains in order of their start time. For each current train, check the other trains ending at the current train start station. Look up in the segment tree the max end time+delay of all trains that end before the current train starts. Use that to delay the current train and update the segment tree for its end station.

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

      By the way, you can replace a segtree with a monotonic map: code. This data structure is similar to monotonic stacks and queues but supports arbitrary insertions. It also can be used to construct and maintain convex hulls, for example in the line container.

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

        why we can't just sort trains by A and after that we do a recursive call for each train (by that order) and for each node that node is going to start from from, we keep an index of the last X trains used (that are in an indegree with that node) , and we get the maximum time that they ll reach that Node, and this way we will process each indeg train for a node just one! this is my idea but I don't know why it TLES (on two tests) ( my complexity I assume is O((n+m)*log(m)), this is my submission sumbission link

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

      A (multi)map is enough to store the arrival times. When looking at the arrival times, merge the entries into one, that have a scheduled arrival time lower than the departure time of the current train. Trains are processed in increasing order of departure time, so the merging is unproblematic for the future trains.

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

In my opinion, the order of the problems shouble be ABCDFGE

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

first time i solved F in an atcoder contest, very nice contest!

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

Problem E is so impressive !

At first, I thought that it is based on some algorithm associated with graph, like Dijkstra or something else, but kept getting WA or TLE.

Then, I convinced myself that "solving it based on graph algorithm" is just my mindset, which in fact I didn't have any proof.

Finally, I came up with another solution, which almost has nothing to do with graph. Note that a train TR1 can only be affected by another train TR2, if TR2's T <= TR1's S, where S and T are the time mentioned in the problem. So, we can deal with the "time" in an increasing order. For each time, at first, we deal with the trains that arrive at this time, and then deal with the trains that leave at this time. For any train that arrives at some city at this time, we update the maximum "arriving time" of this city, and then for any train that leaves some city at this time, we update its minimum "delay time" according to the city's maximum "arriving time". Note that as we handle everything in an increasing order of the time, the solution is always correct.

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

    that makes so much sense actually, thank you.

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

    I think in theory it could be solved by Dijkstra, if you build a graph where the nodes are trains and there is an edge between two trains A, B if A ends where B starts, and before B starts. The weight of the edge is the waiting time between A and B.

    Then compute shortest paths from the first train node. The delay for train X_i is max(0, X_1 — d(i)).

    This is just too slow as the train graph can have too many edges.

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

      I did it using a similar graph method. You can reduce the number of edges by instead creating a new node for every $$$(a, s)$$$ and every $$$(b, t)$$$ pair, then add edges of weight $$$0$$$ from $$$(a, s)$$$ to $$$(b, t)$$$, and add edges from all $$$(i, x)$$$ to $$$(i, y)$$$ such that $$$y$$$ is the smallest time after $$$x$$$ for node $$$i$$$, with weight $$$y - x$$$. The number of nodes and edges is then $$$O(n + m)$$$ and you can run some kind of Dijkstra on that graph. The solution given above is a lot cleaner though.

      Accepted submission

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

    I think that I have the same solution as you but it tle!: submission link

    my calculated complexity is O((n+m)*log(m)) I don't know why it tles

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

Can anyone provide counter case for my solution in D?

Simply Root the tree at $$$1$$$, We can see for any two nodes to be in minimal tree, we must keep the vertices along their path to their $$$LCA$$$, If we had to add another vertex we must find the Common $$$LCA$$$ of our previous $$$LCA$$$ with the new vertex.

So simply, Find The common $$$LCA$$$ of all $$$K$$$ vertices, then count nodes starting from each needed vertex to the common $$$LCA$$$ by iterating over the parents, and keeping $$$visited$$$ set to avoid double counting, and revisiting the same vertices.

The submission

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

Does someone use Systems of Difference Constraints to solve Problem E?

My submission