chokudai's blog

By chokudai, history, 2 months ago, In English

We will hold AISing Programming Contest 2021(AtCoder Beginner Contest 202).

We are looking forward to your participation!

 
 
 
 
  • Vote: I like it
  • +67
  • Vote: I do not like it

»
2 months ago, # |
  Vote: I like it +45 Vote: I do not like it

The upcoming ARC , i.e. on this Sunday , clashes with Google Kickstart , Can't it be preponed or postponed?

»
2 months ago, # |
  Vote: I like it +12 Vote: I do not like it

First time I was able to solve more than 3 questions!!

»
2 months ago, # |
  Vote: I like it +1 Vote: I do not like it

How to solve D? Thanks.

  • »
    »
    2 months ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Suppose you're at i'th character and you have used z number of a's. You count the total number of combinations possible from (n-i) characters and z-1 a's. Let's call this c. If this count is more than k, that means you can afford to put 'a' at the current position, else you have to put 'b'. When you put 'b', reduce k by c.

    Submission: https://atcoder.jp/contests/abc202/submissions/22830270

  • »
    »
    2 months ago, # ^ |
    Rev. 8   Vote: I like it +6 Vote: I do not like it

    Here is what I believed to be a straightforward approach:

    Understand that kth lexicographically shortest string means that there will be $$$total — k$$$ strings that will be lexicographically greater than it. An alternate way of saying that is that you have to leave $$$total — k$$$ strings behind. Let us call this number $$$remaining$$$. It is not difficult to compute that,

    $$$total = nCr(a+b, a) = nCr(a+b, b)$$$
    $$$remaining = total - k$$$

    Now iterate over every position from 0 to n-1, and keep track of the remaining number of a and b. In every position, we have 2 possibilities. Putting either a, or b. Now if we put an 'a' in the current position, how many strings are we immediately getting ahead of? Those many in which there would be a 'b' in the current position, right? That number is,

    $$$nCr(a+b-1, b-1)$$$

    Now, if it is OK to leave behind those many strings, we put an 'a' here, and accordingly update the remaining Else, we put a 'b'. How do we understand if it is OK to put an 'a'? The condition is,

    $$$remaining >= nCr(a+b-1, b-1)$$$

    What if once remaining becomes 0? Well, that means we have no more strings to leave behind. We can then simply create the lexicographically shortest string possible from that position. That is by printing all b's first and then the a's. But it is also fine to go with the flow and check manually as I did.

    Here is my submission following this approach.

    • »
      »
      »
      2 months ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      Thank you, very detailed and understandable explanation.

»
2 months ago, # |
Rev. 3   Vote: I like it 0 Vote: I do not like it

this is my depth first search for E. I am maintaining a map for every node in which I have kept a count of number of having a distance x from the node.

But I am getting tle on few test cases to help me how to optimize it.

submission link : https://atcoder.jp/contests/abc202/submissions/22827434 vector<map<int,int>> l(nax); void dfss(int u , int p = -1){ for(auto x : edges[u]){ if(x != p){ dfss(x,u); } } l[u][0] = 1; for(auto x : edges[u]){ if(x != p){ for(auto y : l[x]){ l[u][y.first+1] += y.second; } } } }

  • »
    »
    2 months ago, # ^ |
    Rev. 2   Vote: I like it +1 Vote: I do not like it

    You can use a count array and solve the queries offline.
    All you need is the euler tour of the tree.
    The entire problem will be solved in linear time. code

»
2 months ago, # |
  Vote: I like it +37 Vote: I do not like it

Wow, I feel so lucky to get the first place! I recently came across a problem very similar to F, which I think might be the reason.

  • »
    »
    2 months ago, # ^ |
    Rev. 2   Vote: I like it 0 Vote: I do not like it

    could you explain your thought process for F, I got that we have to use DP somehow with triangle decompositions and the fact that triangle area*2 is integer, but what was the main cracking hint for you for this question.

  • »
    »
    2 months ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    can you please explain your solution and share the link to a similar problem?

»
2 months ago, # |
Rev. 3   Vote: I like it 0 Vote: I do not like it

Interesting technique for E in the editorial!

I wonder if anyone else answered the queries offline using small-to-large merging (https://codeforces.com/blog/entry/67696). For each node u, we can track the multiset of depths of descendents of u, and use this to answer the queries involving u. Then the multiset for u is the union of the multisets of its children, plus a singleton set with the depth of u. In fact this is almost exactly the same as the linked problem, where the colour of a node is its depth.

  • »
    »
    2 months ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    I did it offline with small to large merging — https://atcoder.jp/contests/abc202/submissions/22827419

    Code
  • »
    »
    2 months ago, # ^ |
    Rev. 2   Vote: I like it +6 Vote: I do not like it

    I did the same. Luckily, I had solved a problem with the same technique today itself. I think it can be done with Euler tour+ binary search as well but this way seemed much more easier to code.

    PS.-Just saw that the editorial has much more cleanly implemented the Euler tour method, contrary to my expectations.

»
2 months ago, # |
  Vote: I like it +19 Vote: I do not like it

Wow, there's already a detailed official English editorial (https://atcoder.jp/contests/abc202/editorial). Is that going to be the case for ABCs going forward?

  • »
    »
    2 months ago, # ^ |
      Vote: I like it +12 Vote: I do not like it

    For the last 10 contests I have seen that editorials are available as soon as contest ends.

»
2 months ago, # |
Rev. 5   Vote: I like it 0 Vote: I do not like it

Can somebody help me identify my mistake in E? My solution uses the same idea as the one from the editorial. https://atcoder.jp/contests/abc202/submissions/22829588

Edit: I found the issue — I was binary searching for "out[u]" on the out time array... but have to do both binary searches (in[u] + out[u]) on the in time array

https://atcoder.jp/contests/abc202/submissions/22839873

»
2 months ago, # |
Rev. 2   Vote: I like it 0 Vote: I do not like it

I solved E with the help of merge-sort tree. We can create a pair of entry time and distance for every node and sort them on the basis of entry time. Then after handling some cases (i.e when Di is less than distance of root from Ui.), we just have to count number of values equal to D in the range entry time[u] and exit time[u] for which I used merge sort tree.

  • »
    »
    7 weeks ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Hermit__OvO can you please share you submission, Thanks!

    • »
      »
      »
      7 weeks ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      sure, (A bit ugly code though)

      Spoiler
      • »
        »
        »
        »
        7 weeks ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

        Thanks!,It indeed is long, I will have to copy it in my editor to study :P

»
2 months ago, # |
  Vote: I like it 0 Vote: I do not like it

i Really dont understand D problem . Can anyone Elaborate more cleaarly . How can we put 'a' in ith place ?

  • »
    »
    2 months ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    You may follow this

    • »
      »
      »
      2 months ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      Bruh how toal is C(a+b,a) why not C(a+b,b). Also i didnt understand remaining>=nCr(a+b−1,b−1). How ?

      • »
        »
        »
        »
        2 months ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

        Ncr(a+b,a)== Ncr(a+b,b)

      • »
        »
        »
        »
        2 months ago, # ^ |
        Rev. 2   Vote: I like it 0 Vote: I do not like it

        Number of remaining positions including the current one is $$$a+b$$$, if I put a 'b' in the current position, remaining position becomes $$$a+b-1$$$, and we will have to place $$$a$$$ number of 'a' and $$$b-1$$$ number of 'b' in the next positions. So, that makes it $$$nCr(a+b-1, b-1)$$$ If I have more strings than this to leave behind, why not do it by placing an 'a'?

»
2 months ago, # |
  Vote: I like it +3 Vote: I do not like it

Was D harder than usual???

  • »
    »
    2 months ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    No. The idea is similar to finding the kth permutation which is quite a standard question.

    • »
      »
      »
      2 months ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      The question is standard.But are the constraints?I don't know.Anyway that was solvable for sure.No doubt about that.

»
2 months ago, # |
Rev. 2   Vote: I like it 0 Vote: I do not like it

I was able to solve E, A, B when I started contest 1 hour late that's why I think E should have been placed before C and D for correct order of difficulty.

For E I used euler tour then upper_bound-lower_bound in vectors of each depth which contains in_time of those node present at that depth.

here's the link for my solution of E

»
2 months ago, # |
Rev. 2   Vote: I like it +3 Vote: I do not like it

Is there any plan for atcoder rounds to be later in the morning (like 7). the usual times (4am, 5am, and at best 6am) are too early for me and presumably other west coasters.

  • »
    »
    2 months ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    probably set as per Japanese Standard Time. It's around evening for them.

»
2 months ago, # |
Rev. 2   Vote: I like it +8 Vote: I do not like it

Can anyone explain the solution of problem F based on Graham Scan? The editorial Atcoder provided says almost nothing detail about it.

  • »
    »
    2 months ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    This is my solution on F, hopefully it will be clear enough :)

    Sort the points from the top-most one to the bottom-most one (in case of same y, sort from the right-most to the left-most). Afterwards, apply a "custom convex hull" for each prefix of points in the sorted array (the last point in the prefix is the lowest point in the convex hull). Before convex hull, mind Pick’s theorem. This tells us that we are actually interested in the parity of the number of integer points on polygon’s perimeter.

    Sort the points according to Graham Scan. Afterwards, store dp[i][j][k] — the number of partial polygons starting from the lowest point and ending with the j-i segment, having k = (number of integer coordinates on the perimeter) % 2. In fact, there will be no Graham Scan, but a dp building which can be understood easier if you refer to Graham Scan.

    For building this dp, we will iterate 0 <= k < j < i < n, and update dp[j][i][nr % 2] += power(2, interior[i][j]) * dp[k][j][0] and dp[j][i][(1+nr)%2] += power(2, interior[i][j]) * dp[k][j][1], where nr is the parity of the number of integer coordinates on the j-i segment. Also, interior[i][j] is a coefficient which denotes the number of points which can be taken in the answer set without altering the convex hull containing the i-j segment. This can be precomputed at the beginning of the convex hull. Basically, any k such that i < k < j which is interior to the polygon should be counted.

    Finally, any dp[k][j] (0 < k < j < n), such that k-j-0 is a valid ending of the Graham Scan, can be considered in the final answer. The final complexity for this solution is O(N^4) with proper precomuputation.

    • »
      »
      »
      2 months ago, # ^ |
        Vote: I like it +9 Vote: I do not like it

      Wow, this is great! Thanks a lot bro ^v^~

»
2 months ago, # |
  Vote: I like it 0 Vote: I do not like it

How to solve F?