11

Codeforces Round #869 (Div.1, Div.2) Editorial

 1 year ago
source link: https://codeforces.com/blog/entry/115586
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client
By jeroenodb, 16 hours ago, In English

1818A - Politics

Problem idea: adamant
Preparation: adamant

Editorial
Solution

1818B - Indivisible

Problem idea: adamant
Preparation: adamant

Editorial
Solution

1817A - Almost Increasing Subsequence

Problem idea: dario2994
Preparation: jeroenodb

Editorial
Solution

1817B - Fish Graph

Problem idea: jeroenodb
Preparation: jeroenodb

Hint 1
Hint 2
Hint 3
Editorial
Solution

1817C - Similar Polynomials

Problem idea: adamant
Preparation: adamant

Editorial
Solution

1817D - Toy Machine

Problem idea: adamant
Preparation: jeroenodb

Editorial
Solution

1817E - Half-sum

Problem idea: adamant
Preparation: adamant

Editorial
Solution

1817F - Entangled Substrings

Problem idea: adamant
Preparation: adamant

Editorial
Solution

10 hours ago, # |

Thanks for fast tutorial!

10 hours ago, # |

Light speed tutorial sheeeesh!

10 hours ago, # |

so fast

10 hours ago, # |

So fast! Noice

10 hours ago, # |

Why is it impossible for a python solution to pass div1C/div2E?

9 hours ago, # |

For Fish Graph, can you do a DFS-Tree like thing with which you can find the node with degree >=4 in a cycle and get to O(N+M) or am I missing something?

  • 9 hours ago, # ^ |

    degree >= 4 won't ensure that that the tail of fish don't lie inside the cycle.

    • 9 hours ago, # ^ |

      Refer to editorial, if you still think it is not enough then try to make a counterexample and prove that it is impossible

      • 9 hours ago, # ^ |

        Sorry. The editorial came so fast that I thought I was replying on announcement blog.

    • 9 hours ago, # ^ |

      It does. If a fish tail is inside the cycle, then use that tail to make a smaller cycle instead. The edge that used to be in the old cycle but isn't in the new cycle will be a correct tail outside the cycle.

    • 47 minutes ago, # ^ |

      Rev. 2  

      0

      i don't know what is wrong here, firstly i found every cycle and then check if it can be used as fish graph. but getting WA every time. Can anyone tell me what is wrong here? https://codeforces.com/contest/1818/submission/203991640

  • 7 hours ago, # ^ |

    What if we form a bridge tree ( biconnected component decomposition) and then do dfs on the new tree and find a node with degree >=3 (as here we squeezed all cycles into a single node).

9 hours ago, # |

For problem Div2.D I don't know this approach is correct or not:

For each vertex with degree >= 4, find the shortest cycle through it, add those edges to answer, find another 2 vertices that are not in the found cycle, include those 2 edges as well.

The wrong submission, the system verdicted WA, wrote that I'm using an edge twice, while I check again the output, it doesn't seem like that. 203958546

  • 9 hours ago, # ^ |

    Nvm, I forgot to output the number of edges, dumb mistake, thank you the board for answering my question

9 hours ago, # |

1818B - Indivisible seems to be repeated question

  • 6 hours ago, # ^ |

    i felt the same.

  • 3 hours ago, # ^ |

    what is the original problem?

9 hours ago, # |

Problem Similar Polynomials

...and for the coefficient near we should note that , thus...

What happenes on the next line?

  • 9 hours ago, # ^ |

    Understood

    Get back to Lagrange formula. Write it as . We have only in first product — . We want to get its . Its minus sum of its roots. So we get .

9 hours ago, # |

Rev. 2  

+8

Alternative solution for 1817D - Toy Machine

If the bottom left part of the toy is full, and it contains , you can win using LDRU. To get this configuration, use DLUL times, then simulate random moves.

AC submission: 203960705

9 hours ago, # |

Little note: for E, you can tighten the bound to (possibly with some off-by-one).

9 hours ago, # |

For problem Similar Polynomials

I changed the input from scanf() to getchar().

The running time changed from 4000+ms (203942742) to 1590ms (203961795).

Can I request to skip this TLE result 203942742?

  • 8 hours ago, # ^ |

    TLE results that were non-trivial, i.e., you had to change ur code even the slightest, they don't regrade it.

    • 8 hours ago, # ^ |

      Well, you remind me.

      I tried the same code and got AC now, it's really a judge fault.

      • 7 hours ago, # ^ |

        Well, my fault.

        I tried the same code with different compiler.

        GNU C++17 for AC, GNU C++20 (64) for TLE.

        Bad luck for me :(

9 hours ago, # |

Toy Machine was fun. The web page was a great addition!

9 hours ago, # |

Really enjoyed the problems. Good work by the authors!

9 hours ago, # |

Is there a constructive way to figure out B? Or was it just observation?

  • 8 hours ago, # ^ |

    I have used the brute force approach to generate all possible answer to see any answer for each test case follow some pattern.

    bool check(vector<int>& a,int n){
    	for(int i=0;i<n-1;i++){
    		int sum=a[i];
    		for(int j=i+1;j<n;j++){
    			sum+=a[j];
    			if(sum%(j-i+1)==0){
    				return false;
    			}
    		}
    	}
    
    	return true;
    }
    
    void solve() {
    	int n;cin>>n;
    	cout << "n: " << n << '\n';
    	vector<int> a(n);
    	loop(0,n-1){a[i]=i+1;}
    
    	do{
    		if(check(a,n)){
    			print(a);
    		}
    	}while(next_permutation(all(a)));
    	cout << '\n';
    }

    if you run this code for small test, like from 1 to 11, you will observe that answer exist if n is even and if n==1, and for each n(keep in mind that it is even) there is permuatation which follow some pattern like

    2 1 4 3 6 5 ..... n-2 n-3 n n-1

    you can try the above code and check it out yourself

    The only problem is that this brute force will work till n=11, after that it will take very long time to produce answer. So, we cannot check it for large test cases.

    Also n=1 is the only odd number that produce valid answer which is 1 only.

    • 8 hours ago, # ^ |

      After 1 hour of trying, this is what I did to find the pattern.

9 hours ago, # |

F can be solved with suffix automaton in .

  • 8 hours ago, # ^ |

    Hi, could you share some details please?

9 hours ago, # |

Rev. 2  

+10

what is the point from problems like div2B ? problems that depends on a pattern/sequence is pointless

9 hours ago, # |

I believe D could be solved in O(n+m) Via DSU. To check if it is possible to reach a node from another would be O(1). And to erase edges, we would simply connect the nodes to a virtual node that sits independent from the graph. But I am not sure. .

  • 9 hours ago, # ^ |

    You can also solve in by finding bridges and running one BFS or DFS to print the cycle.

    • 9 hours ago, # ^ |

      Thank you, could you please elaborate on the bridges part? I am not really familiar with bridges and articulation points

9 hours ago, # |

Nice contest! Although my B failed the system test.

9 hours ago, # |

I used the same approach you mentioned in problem d fish graph , but it shows wrong answer. Here's my solution https://codeforces.com/contest/1818/submission/203940101 , I can't find wats wrong

9 hours ago, # |

Rev. 2  

0

If there were no constraints that required the club president to remain in the club (that is, if we were just trying to maximize the number of remaining members), would problem div2 A still be solvable?

  • 7 hours ago, # ^ |

    Wouldn't it then be the max number of strings that are the same?

9 hours ago, # |

Problem Div1A can be solved another way. Let’s think how the subsequence is organized. It can be created greedy: let the last included integer be a[i]. 1) if a[i+1] > a[i], so the next subsequence’s number will be a[i+1]. 2) else we need to find the first j such that a[j] < a[j+1], and the next subsequence’s numbers will be a[j] and a[j+1]. This observation can be used to calculate next[i]. So the answer is built by jumping from l to next[l], next[next[l]]… while <= r. To answer queries fast we can just count binary jumps on next[] array.

9 hours ago, # |

Rev. 2  

+14

i think there's some problem in Problem D test cases. according to the statement, 1 <= m, n <= 2000 but in test 12, m = 0 in many testcases, that makes my submission 203956585 got WA.

9 hours ago, # |

Why is the leading coefficient of B(x-s) in 1C equal to 1? I think it's k.

  • 9 hours ago, # ^ |

    On the third line of the editorial.

9 hours ago, # |

Rev. 3  

0

In the tutorial of D1C,

Indeed, if we denote by S an operator such that SA(x)=SA(x+1)

It should be "SA(x)=A(x+1)"

  • 8 hours ago, # ^ |

    Thanks for noticing! I will fix it soon.

8 hours ago, # |

Rev. 2  

+1

jeroenodb thank you very much for interesting problems !

I would like to share the solution of problem D in O(N + M). We can divide all vertices according to the components of the edge biconnection, and solve the problem for each vertex (v) in 3 cases:

1) Check that V has 2 or more edges to the vertices of other components (take them as 2 tails), and at least 2 edges to the vertices of its own component (find a cycle)

2) Check that V has 1 edge to the vertex of the other component (take as 1 tail), and at least 3 edges to the vertices of its own component, taking one vertex as the tail, and find a cycle between the remaining two.

3) Check that V has at least 4 edges to the vertices of its own component and select 2 of the 4 vertices as parts of the tail and check that removing them from the component can find a path between the remaining two.

Link to my solution: https://codeforces.com/contest/1818/submission/203962283

7 hours ago, # |

Rev. 3  

0

For C, it can be observed both polynomials have to be in the form . The problem can then be rephrased as finding . Taking the derivative gives us which means we can get or the answer by finding the differences.

6 hours ago, # |

Rev. 2  

0

For Div1C, does anybody know why this submission is giving WA on test 5? Staring at code with no luck :) Many thanks.

Edit: I found it. sumd % mod should be sumd %= mod. Just took 4 hours.

6 hours ago, # |

Can anyone give a testcase in which the following code is giving wrong answer . Problem C div 2 Submission link Thanks

4 hours ago, # |

Thanks for Div1D/Div2F.

3 hours ago, # |

Very frustrated that my div2D submission (203945910) only failed because of a stack overflow. I wrote in Python, so a possible solution to this situation is to increase the stack limit using the method sys.setrecursionlimit() which allows to set the maximum depth of the Python interpreter stack to the required limit. Thus, adding it to the code (203980915), all tests were passed successfully. Definitely worth considering this experience in the future.

97 minutes ago, # |

Can someone tell me why my binary search submission for Div 2 C is wrong?

Thanks!


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK