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

Автор chokudai, история, 5 лет назад, По-английски

We will hold AtCoder Beginner Contest 218.

The point values will be 100-200-300-400-500-500-600-600.

We are looking forward to your participation!

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

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

Hi chokudai I am interested in setting up the user editorials , if I can (ooops!!). How can I ?

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

My parents would rather let me participate in AtCoder contests than let me participate in Codeforces rounds, but they allow me to participate in both kinds of contests.

Imagine you're in UTC+8 and then you can figure it out ;)

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

Nice problemset, any hints on problem H?

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

    How to solve G?

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

      Do dfs traversal over the tree, now you need to keep track of the median for the entire path you're in, which can be done in several ways, i used ordered sets. Supose you want to know the best posible score for a node X, if depth of node X is even, is your oponent turn, so he will get you to the lowest possible outcome, otherwise is your turn, so you maximize it, run a top-down dp and print the value for node 1.

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

      I skipped the contest this week to prep (w/ sleep) for hacker cup round 1. I'm getting around to solving these now.

      As I have primarily been using python for these (although might switch to Go once I've finished building up a reasonable library), multiset wasn't available, and I didn't think to use a Fenwick tree. I'm solving it with 4 heaps. It is a bit slow (near 1.0s), but it does the job. (2 heaps for left and right insertions, and 2 heaps for left/removals) and just do the bookkeeping to cancel out the addition/removal heaps when the heads of each match).

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

    The problem statement is equivalent to placing $$$min(R,B)$$$ 2x1-Dominoes on $$$A$$$ and adding the covered $$$A_i$$$ s. But that's as far as I could get...

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

To be honest, I don't think the difficulty C of this contest is suitable for the difficulty of ABC's usual problem C. Otherwise, a lot of people, including me, won't do D first or even other later problems before doing C. At least for me, the implementation difficulty of D is simpler than that of C :(

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

    I am so depressed with a C ... It made me feel incompetent :(

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

      It's a thing that's popular on AtCoder (geometrical transformations), I usually get very mad when I see them, but they occur every once in a while. It's just about simulating rotations 4 times and writing a check function with the restricted canvas, but that in itself gets very implementation heavy and ugly. There's probably a better way to solve it, but this is how I usually get AC withing ~100 lines of code.

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

        Actually, I got AC with an about 40 lines and only 1.44kb code.

        Click to see the code
        • »
          »
          »
          »
          »
          5 лет назад, скрыть # ^ |
           
          Проголосовать: нравится 0 Проголосовать: не нравится

          Thats a lot code for a C in abc.

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

            Expecting for a shorter solution then...

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

      Seems like it makes sense to have some code templates for 2D array rotation and maybe other simple transformations to avoid wasting extra time on problems like this. It's not the first problem of this kind.

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

    For me G was easier than C , as it required a good amount of code and had much less points than C ( Unluckily I missed G as I had value of infinity as 998245353 rather than 10^9+7)

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

    I think my answer is wrong for problem C, but It has been accepted.

    Those test cases are giving me : Yes.

    3
    . # .
    # . .
    . . .
    . . #
    # . .
    . . .
    
    5
    . . . . .
    . . . . .
    . . # . .
    . . # # #
    . . # . .
    . . . . .
    . . . . .
    . . . # #
    . . . # #
    . . . # .
    

    Am I wrong ?

    Most of the people in the first page of the standings are getting "Yes" you can check if you want : https://atcoder.jp/contests/abc218/submissions/25773980

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

plz explain C,D

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

    check out the editorials

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

    For C, First, if only 90 degree rotation is considered, there may be only 4 patterns s at most. Then consider the translation. It can be found that you only need to see which of the four patterns mentioned above can be translated to completely match t. Specifically, we list the positions of all characters # in S and T in sequence, and then compare them one by one. Let set pattern $$$S$$$ have a amount of $$$c_1$$$ #, the position of the $$$i$$$-th # is $$$(x_{0,i},y_{0,i})$$$; pattern $$$T$$$ have a amount of $$$c_2$$$ #, the position of the $$$i$$$-th # is $$$(x_{1,i},y_{1,i})$$$, and then we just need to find out whether the following conditions are met:

    • $$$\forall i\in[2,n],x_{0,i}-x_{1,i}=x_{0,1}-x_{1,1}$$$
    • $$$\forall i\in[2,n],y_{0,i}-y_{1,i}=y_{0,1}-y_{1,1}$$$
    • $$$c_1=c_2$$$

    Just follow this implemention. It may be a bit hard.

    Code(C++)

    For D, we only need to enumerate two points, not four. Let the two points we enumerated be $$$i$$$ and $$$j$$$, and then you just need to see whether the two points $$$(x_i, y_j)$$$ and $$$(x_j,y_i)$$$ exist. Be careful not to repeat the enumeration.

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

I assumed that alien trick is applicable in H and it worked lol.

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

In problem E — Destruction, I got 13 tc passed and 10 wrong, can you please help me with what's wrong with my code. (When I submit, I assumed it will give me TLE)

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

    Just find the minimum spanning tree for E(be careful while dealing with loops and multiple edges), your answer will be $$$max(0,total\ cost-cost\ of\ MST)$$$.

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

    I got 4 penalty's because I removed all edges even those which had negative weight. I guess that's your error too. Sort edges in non-decreasing order of weights and form a graph. If the edge forms a cycle and doesn't have weight <= 0, remove it, else add to the graph. Final answer is (Total sum of edge weights — sum of weights of included edges of graph).

    Submission

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

Is F brute force?

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

C was the hardest for me :_:

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

I use "divide and conquer" + "max,add convolution " to solve H. Bug why the answer is convex QwQ?

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

I'm pretty sure that once upon a time I've seen the problem like today's F with a weighted graph and $$$ N, M \leq 2 \cdot 10^5 $$$. Does anyone remember a similar problem and has a link to it? I think that it was at Hackerrank, but not sure.

UPD: It's basically this problem. Thanks to this solution from AtCoder :)

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

    True , I too think I have seen something very similar to this somewhere.

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

    Do you know how to solve the question for your constraints ($$$N, M \le 2 \cdot 10^5$$$)?

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

      I do! Let's take any shortest path $$$ P = ( e_1, \dots, e_k ) $$$ between $$$ s $$$ and $$$ t $$$. Obviously, we already know the solution for the edges not in $$$ P $$$. Now, for every $$$ i $$$ we want to omit the edge $$$ e_i $$$ in the shortest possible way. Let's take a moment to think what does it actually mean "to omit" $$$ e_i = (v_1, u_1) $$$. It means that there should exist another edge $$$ e = (v_2, u_2) $$$ such that $$$ d(s, v_2) \leq d(s, v_1) $$$ and $$$ d(s, v_2) + len(e) \gt d(s, v_1) $$$. Between all such edges we want to find one that minimizes $$$ d(s, v_2) + len(e) + d(u_2, t) $$$. We can calculate the distances from $$$ s $$$ and to $$$ t $$$ at the beginning of the algorithm and create a sweep-line-like algorithm which will be solving the problem for all edges $$$ e_i $$$ one by one by maintaining all the "good" edges $$$ e $$$ at a given moment in time. We can do that with a segment tree (probably, an ordinary set is enough but I didn't bother much). The final complexity would be $$$ O ((N + M) \log N) $$$.

      My explanation is probably horrible, so I implemented the solution. Enjoy!

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

    Link

    I solved this problem few days back. I copied my code to find the edges that will always be in the shortest path.

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

      Thanks! Although your problem is similar and uses a lot of related ideas, I don't really see how it implies the today's F. How do you proceed after you found the edges that always are in a shortest path?

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

        There can be atmost n-1 such edges.

        For each such edge, I ran a bfs from 1 and didn't use that edge. The shortest distance of n (if n is reachable) will be the answer for that edge.

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

          Yes, but this gives us $$$ O(N + M) $$$ per edge, so the total complexity is $$$ O(N \cdot (N + M) ) $$$, right?

          UPD: I probably misread your comment and thought that you used the linked problem to solve today's F. But I was wrong and you just used a part of the solution to identify the "critical" edges. If I understand you correctly, you could have used the edges in any shortest path and get the same complexity theoretically. Anyway, thanks for sharing your solution!

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

            Yes, actually I found ABC's F pretty much similar to this problem except one idea. So I shared it. But it seems you are looking for same problem with different constraints. So this problem isn't that relevant.

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

en_translator is still working on translating today's editorial for H. Great thanks!

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

Problem D is exactly same as this problem on Codechef.

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

problem E difficulty has gone down by a lot recently.

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

I think my answer is wrong for problem C, but It has been accepted.

Those test cases are giving me : Yes.

3
. # .
# . .
. . .
. . #
# . .
. . .
5
. . . . .
. . . . .
. . # . .
. . # # #
. . # . .
. . . . .
. . . . .
. . . # #
. . . # #
. . . # .

Am I wrong ?

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

I am getting AC on 19-TC and WA only on one TC (Case name — hand_04.txt) in problem C. either give me this TC from somewhere TT or please debug my code.

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

Please, can somebody help with my solution for G. I did everthing as in the editorial but used ordered_set instead of multiset or BIT. I spent almost an hour trying to find problem, but I couldn't.

UPD: I found problem. It was because erase in ordered_multiset doesn't work. So if you want to erase you need to erase using iterator of lower_bound, but I forgot that in ordered_multiset the lower_bound and upper_bound functions are swapped.

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

Here is a way to solve problems C and D on ABC 218.


Problem C can be solved as a geometry problem, where you basically:

  • find the figures' outline boxes,
  • rotate the first figure's box,
  • compare the resulting boxes for all rotations.

Here is my submission for C with neat organization & comments.


Problem D can be solved by using DFS to find the four points.

  • for every point, store all points that have the same X in one vector, same Y in another vector,
  • use DFS on every point to find the next point with the same X or Y (alternating between finding X or Y),
  • make sure the four points we find aren't repeated by:
    • finding the same X for the first point,
    • making sure the X and Y coordinates are increasing for the first 3 points (left-top, left-bottom, right-bottom).

My submission for D using DFS.