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

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

We will hold AtCoder Beginner Contest 187.

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

We are looking forward to your participation!

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

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

For anyone interested, I'll be doing a post-contest stream on Twitch.

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

Bump. Contest Starting!

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

How to solve F? Is the answer minimum number of clique in graph?

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

How to solve D. I tried to sort on the basis of a[i]+b[i] value but kept getting WA.

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

Please anyone point out the mistake in my code or logic? Task D https://atcoder.jp/contests/abc187/submissions/19154830

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

Can anyone tell me how to approach the problem E? https://atcoder.jp/contests/abc187/tasks/abc187_e

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

    The idea is that of segment tree instead of adding all the numbers just add to b[i] or a[i](In the second cases you should add the number to the root and subtract from a[i] b[i]) Now run a lazy propogation like operation(adding the value on the node to its childs) using dfs.

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

      Segment tree is overkilled here. Just using simple dfs as the comment below! My ugly code: https://ideone.com/PAEUDp

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

      Yes, we basically Find the case according to the distance of a and b from the root, and since a and b are connected by an edge we see if a is near root then we add to root subtract from b otherwise we simply add to a. And then we do DFS from the considered root in my case 1 to find all the final answers.

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

    Imagine a rooted tree with the root being any vertex (say, vertex 1). Now, consider a query $$$q_{i}$$$ such that $$$t_{i}$$$ = 1 and $$$e_{i}$$$ = ($$$u$$$, $$$v$$$). If $$$u$$$ is the parent of $$$v$$$ in the rooted tree, it means we can visit every vertex apart from vertices lying in the subtree of $$$v$$$. Otherwise, we can visit only the vertices lying the subtree of $$$u$$$. If $$$t_{i}$$$ = 2, the situation is the same with the vertices swapped. Rest is the implementation part of how to compute the overall values in $$$O(n+m)$$$ which can be done using a simple DFS.

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

How to solve Problem E ?

Thanks in advance!

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

    for processing queries assume 1 is root of tree if (u,v) is a edge and u need to update u. There are two cases if u is parent of v (in this case update root of tree with x and v with -x) and if v is parent of u (simply update u with x).

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

      I did the same thing, except when v is the parent of u, I updated the node below v that is the parent of u. My logic being:

      say the tree is like:

      v -> p -> q ->u -> r (rotate by 90deg)

      now if we need to update ci for all nodes reachable from u but not doing through v, the nodes are: p, q, u, and r. (that's what I did, and got WA) but if we just update u, only u and r are updated in end(that's what u did and got AC, I changed my code to this and got AC too) but I don't understand why am I wrong?

      Can you please point out the mistake here

      Edit: actually got it, it's because u and v are connected by 1 edge.

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

        first of all your test case is invalid as u and v will always be connected by an edge. Read the Question. I also thought like that and kept getting TLE until i figured this out.

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

    I made a euler tour array and just updated the suitable ranges with segment tree

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

    Select any node with 1 edge as root. Then use bfs and store level wrt root for every node. Now, idea is to use to prefix sums. For every query, you have to add cost of one side of a vertex. Now, parse the input as per the type and find which node's value gets incremented. Lets call this node "node1". Compare the two nodes now and if node1 is at a higher level, add cost to root and subtract it from node2, otherwise just add cost to node1. Now run dfs and for every node, cost[node] = cost[node] + cost[parent]. I wasnt able to implement it completely during contest tho.

    Submission

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

is there any greedy solution for D?

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

    Yes

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

    When you pick a town, you get all the A votes from it, and all the B votes from it, additionally you deprive the other from all of A votes he would otherwise get. So the value of picking a town is A+B+A = 2*A + B, sort the towns by it and keep picking until you have enough votes.

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

    Yes, Let us assume initially she didn't go to any town. So Aoki score is sum of all A[i], let us denote it by s and Takahashi score is 0. So initial difference is s. Now consider if she chooses any city i to make a speech, what will be the new difference ?

    Spoiler

    So, we want to choose cities in such a way, that we reduce this difference by selecting minimum cities. So, let's make a vector v, such that v[i] = 2*a[i] + b[i] , and sort it. Start by selecting the largest, second largest and so on, until this difference reduces to less than 0.

    Pseudo Code

    s = 0;
    for i=0 to n-1
    	s+=a[i];
    	v.pb(a[i]*2 + b[i]);
    sort(v.rbegin(),v.rend());
    p =0;
    ans = 0;
    for i=0 to n-1
    	p = p + v[i];
    	if(p>s)
    		ans = i+1;
    		break;
    cout<<ans<<"\n";
    
»
5 лет назад, скрыть # |
Rev. 2  
Проголосовать: нравится 0 Проголосовать: не нравится

How to solve D problem? I sort the pairs according to this comparator always choose the maximum pair sum and if two pair sum is equal then choose the highest first element among these pair.

(a.first+a.second)==(b.first+b.second))?(a.first>b.first):(a.first+a.second)>(b.first+b.second)

Then greedily choose the elements if it's strictly greater or not.What am I missing? my sub

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

how to solve F?

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

how to solve Problem F? T_T

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

Is problem E related to segment tree or DSU?

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

Any hints on D? Tried solving by taking maximum (a[i]+b[i]) but it gave WA.

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

It is so painful to solve the problem (E) but fail to get AC because it is python and you get three TLE

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

I was able to solve $$$a,b,d,e$$$ but couldn't figure out what the statement of $$$c$$$ mean. Statement could be better. By the way what does problem $$$C$$$ meant?

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

The first thing I want to say is the problems are excellent! Some ABCs' problems are really easy and don't need to think. (I mean, A~D) But this one is different, I really like D.

By the way, how to solve F? I think about it for a long time but just can't fix it.

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

How to solve E? Thanks in advance!

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

    For solving E you can first think of a simpler case. If your have an array A and you are given Q queries where in you have to add x value to range [L, R] then you can build another array P and can perform operations like P[L] += x and P[R+1] -= x. Then you can do prefix sum on this array which will have the same effect as required by the question.
    Now you can think of same with this tree. For query of type 1 simply add x to root and subtract x from c[b]. For query of type 2 add x to c[b]. Then perform a dfs and simply push this accumulated value of c in all the children and do it like prefix sum.

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

    Root the tree in the node $$$1$$$. For each query of type $$$1$$$; I denote $$$x$$$ like $$$a_{e_i}$$$ and $$$y$$$ like $$$b_{e_i}$$$. Then there are two possibles cases:

    1. $$$x$$$ is parent of $$$y$$$
    2. $$$y$$$ is parent of $$$y$$$

    For solve the first case, note that I can reach to all vertices except the vertices of the $$$y$$$'s subtree

    In the second case, I only can reach to the vertices of the $$$x$$$'s subtree.

    For each query of type $$$2$$$ you can use the same approach.

    Now, you can use Euler Tour Technique and solve the problem easily. You can learn it in the next link: USACO Guide :)

    My submission for this problem: Submission #19155947. I hope that this is helpful!

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

Hi, guys. I defined comparator on problem D, but the first code keep giving me runtime error, I use $$$\leq$$$ in the return line.

bool cmp(pair<ll, ll> &a, pair<ll, ll> &b)
{
    ll first = a.second + 2 * a.first;
    ll second = b.second + 2 * b.first;
 
    return first <= second;
}

Then I try to use $$$ \lt $$$(the code below), and then it magically passed. (All other parts of code are the same).

Anyone has a clue why $$$\leq$$$ get a runtime error, but $$$ \lt $$$ gives AC?

bool cmp(pair<ll, ll> &a, pair<ll, ll> &b)
{
    ll first = a.second + 2 * a.first;
    ll second = b.second + 2 * b.first;
 
    return first < second;
}
»
5 лет назад, скрыть # |
Rev. 2  
Проголосовать: нравится 0 Проголосовать: не нравится

For D, I sorted in decreasing order on basis of {aoki[i]+takahashi[i] , aoki[i]} and then took prefix sum for first and suffix sum for second. So, when i get prefix[i] > suffix[i+1], ans is (i+1). The logic seems to be correct but I got WA. Can someone point out the fault in this method? Thank you. My Submission

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

How to solve F in less than $$$3^{n}$$$?

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

    We're trying to find the minimum clique cover of a graph. It's easy to see that an equivalent problem is finding the chromatic number of the complement of a graph. A bitmask DP / inclusion-exclusion algorithm exists for finding the chromatic number of a general graph in $$$O(n\cdot 2^n)$$$. More details can be found here

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

    I just use recursion and backtracking, and a little optimization.

    Assume we are processing the $$$i$$$-th vertex, and the first $$$i-1$$$ vertexs form a set of cliques. Note the set as $$$Cliques$$$.

    • if $$$i = n + 1$$$, then $$$ans = \min(ans, |Cliques|)$$$.
    • for each $$$clique$$$ in $$$|Cliques|$$$, if all vertexs in $$$clique$$$ has an edge to the $$$i$$$-th vertex, we could add $$$i$$$-th vertex to $$$clique$$$.
    • the $$$i$$$-th vertex can form a new clique itself.

    so far, the solution is not good enough to get an AC.

    Then I find that if $$$ ans \le |Cliques| $$$ ,it just no need to recurse any more, just cut it.

    After adding this optimization, the solution is good enough to get an AC and my submission only execs about 7ms.

    Submission #19164964

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

      I finally did the same. But I have doubt that it is weak test data that makes it so fast.

      What is the runtime complexity of our solution?

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

        qqwrwwv or spookywooky did you found the complexity of the solution ?

        Isn't the time complexity greater than $$$O(n!)$$$ in worst case ?

        Suppose we can divide vertices (1,2,3,4,5,6) only like (1,2),(3,4,5),(6) i.e contiguously and not like (1,5),(2,3,4,5,6) then complexity would have been $$$O(2^n*n)$$$ by using binomial theorem. But that's not necessarily true because vertices can form group like (1,5),(2,3,4,5,6) and thus we need to consider all arrangements of $$$n$$$ vertices before partitioning and there are $$$O(n!)$$$ arrangements and thus in worst case it can be around $$$O(n!*2^n*n)$$$.

        Not sure , but i think if such fast solution existed then they would mentioned in editorial because above solution is just brute force and writers must have thought about it.

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

          I think actually it is better than brute force.

          See two "extremes". If there are a lot of edges, then we most likely can form big components, leading quickly to good solutions.

          On the other hand, if we got not much edges there are not much components we can create, so the size of the brute-force tree is fairly small.

          Then, consider a single vertex. If it is completly disconnected (no edge) then the complexity is the same as that vertex would not exist. Else that vertex can be put into a component with at least one other vertex. This makes the complexity based on N in fact beeing based on n/2. Which makes a huge difference.

          In spite of not beeing able to tell how the complexity is calculated I am fairly sure that in this case it is better than the O(3^n) of the bitmask solution.

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

            I think that answer is made up by a lot of cliques with size 2 will be a bad case. So I write a generator to generate graph contains no clique of size 3 as subgraph. And it turn out to be a bad case I think.

            On my PC, it still execs only a few ms when $$$n \le 18$$$ , and it will cost seconds when $$$n \le 25$$$, and for $$$n \ge 26$$$ I have no patience to wait it to complete running.

            I still can not figure out what the time complexity exactly is, but I guess it will be something between $$$O(2^n)$$$ and $$$O(n!)$$$.

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

              As I implemented it, I do basically a dfs construction all combinations of cliques possible.

              But, I do create biggest possible cliques first, and I stop dfs if ans cannot get better.

              So, the solution where biggest cliques are created is near to the optimal solution. There can be better ones.

              Consider a graph where cliques possible of size [3,3,1,1,1,1], there could be a better solution with cliques of size [2,2,2,2,2]

              In this case we fairly quick find 6 as ans, and then traverse the searchtree not deeper than level 6.

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

On problem D

I want to ask

Why is my greedy strategy wrong

Can anyone provide a set of hack samples

struct node {
	ll x,y,s;
} a[maxn];
bool cmp(node x,node y) {
	return x.s>y.s;
}
int n;
int main() {
	cin>>n;
	ll num = 0;
	for(int i=1 ; i<=n ; i++) {
		cin>>a[i].x>>a[i].y;
		a[i].s=a[i].x+a[i].y;
		num+=a[i].x;
	}
	sort(a+1,a+1+n,cmp);
	ll s=0;
	for(int i=1 ; i<=n ; i++) {
		s+=a[i].s;
		num-=a[i].x;
		if(s>num) {
			cout<<i;
			break;
		}
	}
	return 0;
}

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

https://atcoder.jp/contests/abc187/submissions/19163293

Plz some java enthusiast find error in this submission for Problem D in java..i used long also , just getting RTE on 7 tests and all other AC .

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

What is the approach for solving C, I got 3 TC WA(so obviously WA), is there any corner case I'm missing, link to the submission: Link

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

Video Editorial, and also screencast.

You can also refer to the Source code and simple explanation.

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

My submission got runtime error on 3 tests for Problem D. Can someone help me with the reason for the Runtime error?

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

My solutions + explanations can be found here :)

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

Is there anyone who used segment tree in problem E??

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

I'm stuck with Problem-D. My Code

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

    In your code, you sort vt in .first(aoki) order, this is the mistake.

    If the testcase is like this:


    3 1 100 10 1 10 1

    Your code will output 2(1 in fact)

    The right method is to sort it in 2*Atoi+Takahashi order.

    You can see the detail here

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

If anybody is interested in watching a screencast of this contest you can have a lot at my YouTube video where I am solving the problems A to E. Link: ABC 187 Screencast

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

In F — Close Group Editorial, it is written that One can determine if each induced subgraph is complete in O ( 2^N*N^2 ) time for all S. Why so? I mean for any subgraph all I need to do is check if all there is an edge to other vertex or not. It will take O(N^2) only. Thank you for the help.

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

How to solve B, in time complexity of NlogN ?

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

    Rotate the plane by 45 degrees. For each point, we want to count the number of points with greater x- and y- coordinates. If we inspect them in the increasing order of x-coordinates, we can manage how many points are there on each y-coordinates, and find the sum of them within specific range with BIT.