chokudai's blog

By chokudai, history, 5 years ago, In English

We will hold AtCoder Beginner Contest 139.

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

We are looking forward to your participation!

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

| Write comment?
»
5 years ago, # |
  Vote: I like it -91 Vote: I do not like it

Why such worse time? There's going to be a football match here in Nanjing, China but because of this contest I can't watch it.

  • »
    »
    5 years ago, # ^ |
      Vote: I like it +79 Vote: I do not like it

    No one gives a fuck about Chinese football matches.

  • »
    »
    5 years ago, # ^ |
      Vote: I like it +27 Vote: I do not like it

    Seems that you're not very experienced in football, Chinese football matches aren't worth watching...

    • »
      »
      »
      5 years ago, # ^ |
        Vote: I like it +3 Vote: I do not like it

      i don't think so, It's just that it's not as fascinating as it is in Europe

  • »
    »
    5 years ago, # ^ |
      Vote: I like it -36 Vote: I do not like it

    I can understand your pain, guy. Chinese football matches are much better than foreign ones, and taking part in such a shitty contest is totally a shame! So all those who says "Chinese football matches aren't worth watching" please go away, far away!!!!!!!!

»
5 years ago, # |
  Vote: I like it +24 Vote: I do not like it

Website is very slow today

»
5 years ago, # |
  Vote: I like it +40 Vote: I do not like it

Congratulations to everyone who was able to understand the problem statement of 'B' . First study English, then write problems, I request!

Lesson learnt:- Never give an AtCoder Beginner Contest,because mortals like me still can't understand what was asked .

»
5 years ago, # |
  Vote: I like it -41 Vote: I do not like it

What a fuck thing! Problem F has a same problem in BZOJ......

  • »
    »
    5 years ago, # ^ |
      Vote: I like it +26 Vote: I do not like it

    I think to publish it after the contest would be better.

  • »
    »
    5 years ago, # ^ |
    Rev. 2   Vote: I like it +36 Vote: I do not like it

    As a writer of this contest, please refrain to write some hints about the problem during the contest. The fact like "this problem can be solved with DP" or "this contest is already published 3 years ago" should be written after the contest. It might cause BAN or some bad thing.

»
5 years ago, # |
  Vote: I like it +50 Vote: I do not like it
»
5 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Can anyone please help in finding the error in my code on Problem E? I was getting TLE on last case. I used binary search. https://ideone.com/hiB9kP

Please Help!

»
5 years ago, # |
  Vote: I like it +46 Vote: I do not like it

As usual, I've posted my solutions, which you can now find at this link.

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

How to solve F?

I Tried all possible combination of coordinates... At an index either select it or don't. similar to knapsack dp

https://atcoder.jp/contests/abc139/submissions/7287492 — WA

»
5 years ago, # |
  Vote: I like it +1 Vote: I do not like it

Does AtCoder run properly on mozilla?Website and questions were not loading in mozilla.

  • »
    »
    5 years ago, # ^ |
      Vote: I like it +10 Vote: I do not like it

    Maybe a connection or cache issue, I had no problem with atcoder and mozilla rather than at the begin of the contest.

»
5 years ago, # |
  Vote: I like it 0 Vote: I do not like it

That's a very bad thing, to have problems " copy-paste " from other judges, it makes the round a test for googling skills

  • »
    »
    5 years ago, # ^ |
    Rev. 2   Vote: I like it +43 Vote: I do not like it

    Not really, nowadays it's almost impossible to know all the problems from all platforms. In Poland, we're spending some time trying to find similar problems using Google. If we cannot find anything, then the task is fine.

»
5 years ago, # |
  Vote: I like it 0 Vote: I do not like it

How to solve F

»
5 years ago, # |
Rev. 5   Vote: I like it +25 Vote: I do not like it

Unofficial editorial by me. All solutions here I verified got AC by the judge.

A. (Tenki) Explanation
A. Code
B. (Power Socket) Explanation
B. Code
C. (Lower) Explanation
C. Code
D. (ModSum) Explanation
D. Code
E. (League) Explanation
E. Code
F. (Engines) Explanation
F. Code
  • »
    »
    5 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    For C, another approach is to let dp[i] be the number of moves you can achieve if you start from i.

»
5 years ago, # |
  Vote: I like it +1 Vote: I do not like it

imo C and D are swapped :d

»
5 years ago, # |
  Vote: I like it +14 Vote: I do not like it

I use randomize + greedy + soting and PASSED F!

This is my code

But I don't know how to solve it properly . I think I'm a little lucky

  • »
    »
    5 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    I'm not so lucky like you. QWQ

    I also used randomize + greedy, and I got WA.

  • »
    »
    5 years ago, # ^ |
      Vote: I like it +15 Vote: I do not like it

    Just maybe your sorting function is so good.

    I actually generated testcase which naive hill climbing algorithm may fail. I think it's the case of chenxiaoyan.

    However, I expected that simulated annealing algorithm may pass. Within this constraints, I don't think that there exists a killer case for SA algorithm. SA is so powerful that even solves a problem in AGC.

»
5 years ago, # |
Rev. 2   Vote: I like it +29 Vote: I do not like it

I am really sorry that problem F was already published to some other contests. I published this because I thought to be both original and high-quality.

While I was already solving 4,000+ problems in competitive programming, there were no instance of this problem, including similar problems. I attempted many times to search "maximum distance vector subset sum"-like keywords in google, but didn't find the same question.

P.S. We created pretty tricky testcase for problem F, so only 1/10 of solutions passed, while we prepared extraordinary 7 sample testcases :)

»
5 years ago, # |
  Vote: I like it +3 Vote: I do not like it

In problem E, after checking for cycle in the directed graph formed between the matches, I found the length of the longest directed chain in the graph.I got WA with this approach.Can anybody help me where I am wrong please?

  • »
    »
    5 years ago, # ^ |
      Vote: I like it +4 Vote: I do not like it

    Nevermind, It worked, messed up the cycle check back then :( Check out my solution if anyone wants : https://atcoder.jp/contests/abc139/submissions/7293559

  • »
    »
    5 years ago, # ^ |
      Vote: I like it +1 Vote: I do not like it

    Can you please explain the logic behind your approach, thank in you advance

    • »
      »
      »
      5 years ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      First after we make the directed graph, and check the absence of cycles in it, to find minimum days, you must understand that the graph will be overlaps of some directed chains, and if you take the length of largest such chain, there's no other chain larger than it, and hence in those many days the rest of the chains can be allocated a day easily because at any point of intersection the topologically higher part will be contributing iff it is the longest subchain compared to the other chains and hence day assignment won't be a problem. Although I believe such is the solution, I cannot completely confirm it for any edgy test cases.

      • »
        »
        »
        »
        5 years ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

        rohit_goyal, Thank you for your explanation ... I got some questions. How are you storing the graph (as adj lists or matrix) ? Can you send some links (tutorials, editorials and questions related to this problem) ?

        • »
          »
          »
          »
          »
          5 years ago, # ^ |
            Vote: I like it 0 Vote: I do not like it

          I am storing the graph as adjacency list (instead of using pair as an element in list, I use compressed index for denoting pair (l, r) ). The only tutorial I can provide you is about how to check for cycle in graph : Link But if you want to check out another approach or more detailed solutions, check out this link below: Link

»
5 years ago, # |
  Vote: I like it +3 Vote: I do not like it

Please elaborate the problem B, what exactly we need to do in this and how to do:)

  • »
    »
    5 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    From what I could comprehend, after you apply a socket wire ( or whatever it was called, having parameter A), the old socket is converted to a multi — socket of size A. So how many minimum we need to apply to at least get B sockets? You can refer the image for A = 3 and transitions: Link : https://ibb.co/bXcss0W See the numbererd nodes?They are our sockets after adding each wire at each step of size A.

  • »
    »
    5 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Initially, you have only 1 plug which is open. You want "B" open plugs. You have only "A" sized boards (which means each board has A open plugs.) Target is to find the minimum number of "A" sized boards required to get "B" open plugs.

    The key idea is Whenever you use a brand new board, you will have to use an empty plug from previous to connect this.

    So essentially whenever you add a board you add "A-1" open plugs and not "A". Just simulate this by adding boards until you reach B or more.

»
5 years ago, # |
  Vote: I like it +16 Vote: I do not like it

My approach for F:

Keep track of the convex region we can reach. This can be described as a set of points. For each incoming vector, apply it to every point on the boundary, and keep only the convex hull of the resulting set of points.

I was concerned this would TLE if the hull got too big, but surprisingly this passed in 2ms. Are there any countertests for such an approach when n = 100? The POI version where n=200,000 seems like it would break this.

  • »
    »
    5 years ago, # ^ |
      Vote: I like it +5 Vote: I do not like it

    Useful conclusion: a convex hull on integral points with $$$x$$$ and $$$y$$$ coordinates both in range $$$[1,A]$$$ contains at most $$$O(\sqrt{A})$$$ points. In this problem, the maximum absolute value you can reach is $$$N \cdot maxX \leq 10^8$$$, so at most $$$O(\sqrt{N \cdot maxX}) \leq 10^4$$$ points.

    Thus, even if you brute-force the convex hull after each vector, the total complexity will be $$$O(NP \log P)$$$(Let the size of the hull be $$$P$$$), which can fit the time limit.

    Of course this won't work for $$$N=200,000$$$. In fact, we can scan the vectors with a half plane. Update the answer when their is a vector go into/out of the half plane. The total complexity is $$$O(N \log N)$$$(imo).

    Maybe you can share your convex hull code here, because I didn't implement it :D

    • »
      »
      »
      5 years ago, # ^ |
        Vote: I like it +10 Vote: I do not like it

      I think the convex hull on integral points with $$$x$$$ and $$$y$$$ coordinates both in range $$$[1, A]$$$ contains at most $$$O(A^{2/3})$$$ points, not $$$O(\sqrt{A})$$$ points.
      That's because there are $$$O(n^{2/3})$$$ pair of $$$(x, y)$$$ which is $$$1 \leq x, y \leq O(n^{1/3})$$$ and $$$gcd(x, y) = 1$$$.

      • »
        »
        »
        »
        5 years ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

        Can you link some proof regarding this claim, I am not able to find on google..

    • »
      »
      »
      5 years ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      That is a very useful conclusion! While the result seems intuitive, is there a constructive proof?

      Here's my code from the contest: https://atcoder.jp/contests/abc139/submissions/7268385

  • »
    »
    5 years ago, # ^ |
      Vote: I like it +5 Vote: I do not like it

    Wow, grats for actually thinking of this in contest fairly quickly. I saw it and immediately thought of https://codeforces.me/contest/995/problem/C, remembering that even though there was an elegant solution, randomization + greedy heuristic solved all cases and was hard to break.

    Turns out same was true for this one.

»
5 years ago, # |
  Vote: I like it 0 Vote: I do not like it

The sample code of problem F in official editorial returns 404.

»
5 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Can Some one please explain E: League and F:Engines solution.

  • »
    »
    5 years ago, # ^ |
      Vote: I like it +3 Vote: I do not like it

    Let's create a directed graph. Where each node is a match played between two players. Now let's add edges to this digraph. For an ith person's required order we add a directed each for each adjacent positions. That is for j in range (1..n-1) add directed edge from (j-1) to j. Also since match played between a&b and b&a is similar we merge these edges into one.

    Now we have a directed graph. We just check the topological ordering of this graph. If it's cyclic then we don't have an answer.

    Now to find the minimum days: For a node who has not yet finished (is still waiting on some nodes to finish), this node can only finish when the max days taking node it is still waiting for finishes and then it takes 1 more extra day to finish.

    Obviously, the nodes which don't wait for others to finish end on day 1. For other nodes, we update them using the previously done. And maintain maximum throughout.

    • »
      »
      »
      5 years ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      What I have done is create a vector of set where each set in a vector represents the team that played on that particular day and at last output the size of vector (the number of days). How I did it? Iterate through all the existing sets of vectors, if neither of the two element(i and Aij) are present in that set, add both the elements to that set and if none of the set satifies this condition then add a new set to vector. Also, I have kept a value = temp1 which is equal to the kth vector(the vector in which last pasir of elements were added), this also helps to know if any two cases are contradicting.Can someone please help me out in finding error as I am getting WA in some test cases.

      Here is my solution:- https://atcoder.jp/contests/abc139/submissions/7296021

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

    In E : first observation was to see, among all the possible matches , which would be the first match . if we say the i th player played the first match with the j th player. then in the column of i , j would be the first element and in the column of j , i would be the first element . Now since on day 1, i th and j th player has played , so they can't play more matches on day 1. so we try to find some more pairs for day 1, if they satisfy the above criteria . we can do this while traversing the first column. after finding all the pairs which played on day 1 , we can start to find pairs who played on day 2. for finding the pairs what i did was to initialize n pointers to 1. if some pair satisfy the criteria , I incremented their respective pointer by 1.when we find no pair , we break out of the loop. at the end, if all pointers are at n , which means all have played , we simply print the number of days , else we print -1 . Hope it helps. for more clarity, you can see my code : Link

    • »
      »
      »
      5 years ago, # ^ |
        Vote: I like it +3 Vote: I do not like it

      What is the time complexity of your solution? To me it looks O(n^3) in case where only one match is played in each day because your while loop will run n^2 and inner loop i O(n) or am I wrong?

      • »
        »
        »
        »
        5 years ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

        Yup ,you are absolutely correct. It is my bad that i didn't calculate the worst time complexity of my solution. On a little thought , it can be optimised by using containers like map or set where finding such a pair is relatively easy.

»
5 years ago, # |
  Vote: I like it 0 Vote: I do not like it

F was well-known, but I didn't know it.

I hope there will be no well-known problems next round.

  • »
    »
    5 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    well, an well known problem appearing in any contest doesn't destroy the fun of problem solving as long as the problem is elegant/crafty, right? if someone knows the solution beforehand they can just solve it quickly and go rewatch some rick and mortys. On the other hand, it might turn out to be a wonderful contest with cool problems :)

»
5 years ago, # |
  Vote: I like it +3 Vote: I do not like it

An observation for F: we always choose a vector forming an angle with the previous vector in range (-pi/2; pi/2). Therefore, F can be solved in O(nlogn) by sorting and two pointers.

»
5 years ago, # |
  Vote: I like it +1 Vote: I do not like it

how can i solve E-league with topological sort? I've figured out that if it contains cycle than answer is not possible. In all other cases we have to output maximum depth of that tree. Is it right approach? My WA solution

»
5 years ago, # |
Rev. 2   Vote: I like it -10 Vote: I do not like it

in E why numbering of node for (x,y) is min(x,y)*N+max(x,y)?

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

    Assuming you are asking 0-indexed numbering: First of all taking minimum and maximum is to avoid distinction between pairs like (1,2) and (2,1) or you can say we need unordered pairs in the problem. Secondly the numbering is one of possible numbers you can take. This numbering is just indicating, say in a grid, you are at (1,5) and grid size is 6*6, so the assigning numbers from first cell to the required cell, starting with 0,you get number 1*6 + 5(only for 0 based indexing ), so think it like this, at (i, j) cell, you need to move n*i number of cells along rows and then the jth cell is your requirement, hence the number n*i+j.

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

Why English editorials are not linked on englsh website, they are available on Japanese one?

»
5 years ago, # |
  Vote: I like it +1 Vote: I do not like it

Problem "D" should be swapped with problem "B" or "C".

»
5 years ago, # |
  Vote: I like it -7 Vote: I do not like it

Aside from simulating, there is a one liner solution for B:

Spoiler
»
5 years ago, # |
  Vote: I like it +1 Vote: I do not like it
  • »
    »
    5 years ago, # ^ |
      Vote: I like it +6 Vote: I do not like it

    you guys must have some kind of magic wand!

»
5 years ago, # |
  Vote: I like it +1 Vote: I do not like it

Problem E:

Can someone speed up my solution?

I'm using deque and finding possible matches between players, and combining if it's possible. For some reason it's TLEing in one test :- Submission

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

Here's my solution code for F. Notice that the solution set of vectors will consist of those vectors which are all in one half of the plane so that they all add positive components toward the final destination vector. So we need to pick contiguous vectors (sorted by angle) with the max difference of angles being 180 degrees. However, we need not worry about the 180-degree difference limit as while checking for all possibilities, the extra vectors will only reduce the answer. The answer remains unaffected. So our task is reduced to finding some set of contiguous vectors so that the final answer is maximized. This is easily done by prefix sum in O(n^2). Make sure to consider the original vectors twice, so that the conditions such as (i, i+1, ..., n, 1, 2 ) are considered while constructing the solution. We pick anywhere from 1 to n vectors to check for a possible solution.


#include <bits/stdc++.h> using namespace std; #define fastIO \ ios_base::sync_with_stdio(false); cin.tie(NULL); #define endl "\n" #define ll long long #define MOD 1000000007 #define pb push_back #define ff first #define ss second #define mp make_pair #define pii pair<int,int> bool compare(const pii &a, const pii &b){ return atan2(a.ss,a.ff) < atan2(b.ss,b.ff); } long double dis(pair<ll,ll> a, pair<ll,ll> b){ long double x = abs(a.ff-b.ff), y = abs(a.ss-b.ss); return (x*x + y*y); } int main(){ int n; cin >> n; vector <pii> v(n); for(int i=0;i<n;i++) cin >> v[i].ff >> v[i].ss; sort(v.begin(), v.end(), compare); vector < pair<ll,ll> > prefix(2*n); prefix[0] = v[0]; for(int i=1;i<2*n;i++) prefix[i] = mp(prefix[i-1].ff + v[i%n].ff, prefix[i-1].ss + v[i%n].ss); long double ans = 0.0; for(int i=0;i<n;i++) for(int j=i;j<i+n;j++) ans = max(ans, dis(prefix[j], i>0?prefix[i-1]:mp(0LL,0LL))); cout << fixed << setprecision(50) << sqrt(ans) << endl; return 0; }
»
5 years ago, # |
  Vote: I like it 0 Vote: I do not like it

I wonder why use cross product to sort can not pass? But atan2() is ok...

»
5 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Went over AtCoder Problems and found that the difficulty of D in this contest is extraordinarily low.. Thought I'll give it a try. Surprised of how I came up with the solution instantly. Normally I could only solve problem A, B and C. Even problem C could be tough to me.