Codeforces Round 930 (Div. 1, Div. 2) Editorial
source link: https://codeforces.com/blog/entry/126513
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.
Thank you for participation and we hope you enjoy this round :)
D2A — Shuffle Party
Idea : chromate00
Video editorial by aryanc403 https://www.youtube.com/watch?v=lLmVzA49BRM
D2B — Binary Path
Idea : wuhudsm
D1A — Bitwise Operation Wizard
Idea : wuhudsm
Video editorial by aryanc403 https://www.youtube.com/watch?v=jfcx1Rs8I28
D1B — Pinball
Idea : wuhudsm
UPD: It conflicts with https://mirror.codeforces.com/contest/733/problem/E. This is a coincidence. There are no excuses. Very sorry for any inconvenience caused to everyone.
D1C — Pokémon Arena
Idea : wuhudsm
Video editorial by aryanc403 https://www.youtube.com/watch?v=ysdozposXkQ
D1D — Bitwise Paradox
Idea : Psychotic_D, MagicalFlower
D1E — Yet Yet Another Permutation Problem
Idea : wuhudsm
D1F — Grand Finale: Circles
Idea : chromate00
UPD: The TL was a bit too loose, and unintended solutions with complexity passed during the round. For the sake of the problem itself, I suggest that you try to solve assuming a second time limit.
2 weeks ago, # | fast editorial |
-
kindly help me in this DIV2 -B
int n;
void solve(){
cin>>n;
string u, d; cin>>u>>d;
string s = u[0] + d;
string c=s;
int cnt=0;
for(int i=0;i<n;i++){
s[i] = u[i]; s[i+1] = d[i]; if(s==c) cnt++; if(s<c) c=s, cnt=1;
cout<<c<<'\n'<<cnt<<'\n'; }
It is giving TLE -- but it is running in O(n) time
-
If in terms of string comparison, you can use a hash plus binary search, binary search to find the longest length of the same prefix, the next position is the first different position, and then compare the characters at that position, this only requires O(logn), preprocessing requires O(n). By machine translation, there may be errors,you can continue to ask me.
2 weeks ago, # | Fast Editoral |
Fast editorial! Never seen one posted so fast after a contest. |
2 weeks ago, # | Great round ! I really enjoyed solving problem B and C. Congrats to the authors ! |
2 weeks ago, # | I don't know if I should be happy that I solved div1A+B fast or sad that I spent over an hour on C and didn't get it!! Either way, thank you for the amazing contest! I've just got to read the editorial for C now ^_^ |
2 weeks ago, # | fast editorial |
2 weeks ago, # | Interesting problems, but don’t you think that the difficulty of Div.1 is A > B > C? |
For problem F I didn't have enough braincells for solving the k=3 case so I simply used the idea from Radewoosh's blog number 5 https://codeforces.com/blog/entry/61710 (binary search for the radius + the blog for finding the intersection after shrinking circles + using golden-ratio search to optimize). Also didn't realize the k=4 case apparently didn't exist, hopefully it's not FST due to time seed. Edit: chromate00 idk if it was you that put that note for F, but doing binary search and ternary search while doing the rest as in the editorial seems fine to me. The expected number of retries in the algorithm is O(log^3N) I'm pretty sure, so in the end it's something like O(log^3N * log^2precision) + O(N). |
-
It should be fine if you do the rest of the blog along with one binary search. I haven't tested with two, though. The I was referring to was the nested golden section search where the is simply from calling the objective function. Do note though, that we do have a tester solution with complexity that passes in ~800ms.
-
hmm I just submitted and it's faster than everyone else's solutions ...
-
I believe it is one of the we intended to allow. Most of the I meant to block were the ones that do ternary search on both and , to maximize . In the meantime, a tester's solution using binary search on with a clever check function passes in about 800ms.
-
-
As far as I believe, the issue is in the precision of the type itself. It can be fixed by implementing a class for , so I will consult the coordinator about replacing the model solution with one that uses exact computations. The current version of data was cross-validated with BurnedChicken's binary search solution, which made me believe it is precise enough.
-
-
-
-
2 weeks ago, # | Is Div2B is possible by doing just simple dfs? |
-
No, it's too slow.
-
How?Shouldn't it be 4*10^5?Or I am making miscalculation here,can you give me the tc for a bfs for the test cases?
-
On each position in first string you will have 2 ways you can go, right and down, when you go right you do the same choice, but when you go down you have to go right to the end of the string, so in total you have O(n*(n+1)/2) time complexity, and because you have 10000 tests in one testcase you have n*(n+1)/2*10000 = 200'001'000'000'000 total operations which is obviously too much.
-
-
2 weeks ago, # | Interesting round! Really like it when there is an interactive problem in the round |
2 weeks ago, # | Div. 2 PROBLEM B (Binary Path) video Editorial : YOUTUBE EDITORIAL LINK Audio : Hindi |
2 weeks ago, # | Fast editorial, and...
|
2 weeks ago, # | Why is the system testing frozen? |
-
The first thing I can observe in your solution is that you should use
unordered_map
when the type of keys isstring
. It uses hashed keys so that the problem due to the comparison time ofstring
values can be resolved.Edit: Similarly, you can use
unordered_set
instead ofset
-
Also you are deleting first charachter of a string and you are doing that n times so only that is O(n^2) which is too slow.
2 weeks ago, # | I love D1A = D2C. Very Beautiful problem! |
-
Why do we try step 3 in Div2 C? Do we need to find the smallest one?
-
Yes.
A xor B = (A or B) - (A and B)
, and the candidates obtained after completing the step 2 satisfy the condition that the bit in a particular digit has a value of 1. It is because maximal value ofpi or pj
is111...111(2)
form.-
Yeah, I see. But I think when I finished the step 1, I can get the position of n-1. And then I don't understand why step 2 is needed. Assum that the position of n-1 is x. I think we can get the position of candidate that can make px^pk maximum without step 2. What is the mistake? This is my code but I got wrong answer. https://codeforces.com/contest/1937/submission/248971409 Please let me know the reason.
-
2 weeks ago, # | Super fast editorial |
2 weeks ago, # | This is hard! |
2 weeks ago, # | In Div 2 B, how to prove that if a=b, then it's optimal to move to the right? |
2 weeks ago, # | why is ffush giving idleness, but changing all to cout.flush() is AC |
2 weeks ago, # | for problem D2B — Binary Path ... you can also use dp for counting number of paths. Submission |
-
also possible with 2d dp
-
The first dimension is just the combination of two arrays
the array for visited checking
dp[0]
and the array for the answer itselfdp[1]
This doesn't increase the time complexity of the code; in fact, it optimizes the time complexity by avoiding the need to reassign the entire
dp
array as not visited for each test case. Instead, I only need to check whether theid
of the current state is equal to the current test'sid
. If it is, then the current state has already been visited during the current test case.This is why there's a difference between our time complexities of our codes
SpoilerI use
array
instead ofvector
and I don't reassign it at each test case
-
2 weeks ago, # | F: "Using nested ternary searches does not help very much. The time complexity will be , but the constants are large due to multiple function calls and floating point operations" lol 3 out of 4 accepted submissions use nested ternary searches |
2 weeks ago, # | Problem B can also be solved by dp. My submission https://codeforces.com/contest/1937/submission/24898172.First we create most optimal string and then apply dp for how many ways we can create this string.(Basically number of paths). |
2 weeks ago, # | I used a similar approach to solve problem D2B: I'll explain it here to hopefully help someone. There are only n possibile way we can go from
Time complexity: O(n). My submission as reference: 248990348. |
2 weeks ago, # | Please can somebody tell me why this is giving TLE?
|
2 weeks ago, # | There is a square-root decomposition solve for bitwise paradox in , assuming DSU is . By breaking the array down into sqrt blocks, we can merge in ascending values of in each block and store the maximum prefix, suffix, and subarray OR in each block for such . We can now simply binary search for a value , merging blocks from left to right, keeping track of the current longest suffix and checking if the maximum subarray OR . Submission: 248991851 |
-
I tried same solution for Div1D, but I got some memory trouble and failed to solve within the contest time..... (I used 4 * 4 * N * sqrt(N) 8bit integers, which seems too large) My submission: 248971206
2 weeks ago, # | Can B be done with string hashing? After getting the best possible string, we can just try all possible paths in O(1) each? |
2 weeks ago, # | Thanks for the organizers, hated this contest |
2 weeks ago, # | At div1 C, can't you just have edge from X[rank[i]] to i with cost 0, meaning that you defeat the pokemon i? |
2 weeks ago, # | The solution to problem 1D is really similar to problem 1004F. I modified about 3 lines of code and added a ST table and got accepted :( |
For problem D1A — Bitwise Operation Wizard, we can actually reduce the number of queries needed to at most . Here's how. From the editorial, we can see that we have steps, where the first step is finding first number (the editorial encourages us to find the maximum for this one) with queries, the second step is finding candidates for second number by finding maximum OR value with queries, and the third step is finding minimum from the candidates (since the minimum produces maximum XOR with the first number, the proof is left to the reader as exercise) with queries, where is the number of candidates and . This optimization mainly focuses on the first step. Now, let for some integer (since is pretty trivial lol). If we do our observation correctly, we'll notice that . Funnily enough, we can reduce the number of queries in the first phase to queries. This can be done by realizing that any number from to are always valid candidates for the first number , since they always have a second number such that . And so, we only need to use queries to find any number that is (by knowing that the number is larger than at least other numbers). From my calculation, from all of the possible permutations of , the third phase actually uses at most queries if and at most queries otherwise, since the number of queries actually depends on the size of the candidates. I believe the worst case can only happened at and , where both only spent queries. And thus, this problem is solved using queries. Edit: I found this during the round testing and suggested to add it as a hard version of the problem, but they refused lmao. Edit 2: If anything seems wrong in this message, please let me know :3 Edit 3: Credit to MCYang for the concise upper bound for the step and some corrections to the comment ^w^ |
-
Interesting idea overall, though I think one of the steps needs some clarification.
In the explanation of step 3, when you mentioned that " is the number of active bits in the number ," actually comes out of nowhere. Does it mean a number we found at step 1? If so, why do you restrict the range of to (instead of ?) If not, what does refer to? You may want to describe what means more clearly.
By the way, I have a more concise expression for the upper bound on number of queries on step 3.
- If , there will be at most queries.
- Otherwise, there will be at most queries.
This also explains why the worst case of your idea happens only when or . (Also they both only spend queries. This is a resubmission of your code except that I added runtime checks on the number of queries.)
-
you did string assigning
ans = temp
times, which results in complexity since string assigning is .-
Thanks! Is there any way i can optimise that approach?
-
hint: notice that everytime, you only need to change one character inside the temp string, which means that when you need to change ans, you can do so by only changing one character inside of it
-
-
13 days ago, # | can anyone help me in this DIV2 -B int n; void solve(){ cin>>n; string u, d; cin>>u>>d; string s = u[0] + d; string c=s; int cnt=0; for(int i=0;i<n;i++){ s[i] = u[i]; s[i+1] = d[i]; if(s==c) cnt++; if(s<c) c=s, cnt=1; } cout<<c<<'\n'<<cnt<<'\n'; It is giving TLE -- but it is running in O(n) time |
13 days ago, # | Can you help me? I am getting TLE. But my code is supposed to be in NlogN time only. |
13 days ago, # | can anyone prove/justify Step 3 of editorial of D2C/D1A.why minimum need to be choosen. |
13 days ago, # | I will share my solution for D1F. First, binary search for . The maximum circle has radius at least is equivalent to the circles with their radius decreased by have a non-empty intersection. If the intersection is non-empty, the intersection is convex. Then do binary search for . For , one of the following is true:
The first case is true if and only if
Otherwise, there exists two circles such that . The second case is true if and only if the intersection of the circles is entirely in the half-plane. There are many ways to check this. |
13 days ago, # | Problem D can be done in per query of type 1 and per query of type 2. The idea is to maintain all minimal good intervals (good intervals such that neither and are good) in sorted order using a BBST.
|
13 days ago, # | My Screencast for A and B problems: https://youtube.com/live/IU6Zqy5LGB4 This was private during the contest. Hope it helps someone. |
-
Bro no one is interested in seeing you struggling in problem A, so stop spamming the commemt section under every blog post
-
I apologize, bro. I understand that my struggle with problem A, taking 3 minutes to solve (which may seem slow to you for someone "green"), might not be of interest to everyone. I acknowledge that I need to improve, and I'll work harder in the future.
Regarding your statement that 'no one wants to watch,' I must respectfully disagree. I get over 30 (sometimes 100) watch hours on these videos in total, indicating that there is indeed interest. However, if my content doesn't resonate with you, you're welcome to unsubscribe and find content that better suits your preferences. Criticizing someone's honest efforts without constructive feedback isn't fair or productive.
-
Round 930 div 2 problem C: code -> 249045846 Idleness limit exceeded on test 1 why? what's wrong? Please identify the mistake and let me know |
13 days ago, # | Problem D1B Pinball can be done in |
13 days ago, # | In the editorial for D2B , I think the initial value of 'max_down' should be (n-1). correct me if I am wrong |
13 days ago, # | The influence of clash of D1B is quite big. it appears just following the beginning problem and people soon finds the clash, as you can see a originally *2400 problem(733E) passed by a lot of people. my advise is just make this round unrated if possible. |
13 days ago, # | Good idea hh |
In F I solved the 3-circle case like this: I applied an inversion at one of the intersection points of 2 circles and found a circle inscribed between an arc and 2 segments with Sawayama theorem. Unfortunately after inversion the picture becomes heavily dependant on the point configuration, and I think my code that passed doesn't quite work (though I don't understand how), as it sometimes finds no circles between the given 3 at all Edit: Also now it works insanely fast without hypotl calls |
13 days ago, # | How to get pupil rank? |
13 days ago, # | For the problem D, at the end of the editorial, they said : It is not difficult to observe that we can use prefix sum to store the sum of indices, and then quickly calculate the time when the pinball moves. And to calculate the pinball moves the precalculate two arrays: IDr[i]=IDr[i-1]+i*(s[i-1]=='>'); IDl[i]=IDl[i-1]+i*(s[i-1]=='<'); and for case s[i-1] == '<' && countright(1,p) > countleft(p+1,n), the ball should go at the end, from leftk to boundary. But the moves was got in such a way: 2*((IDl[n]-IDl[i])-(IDr[i]-IDr[k-1]))+i+(n+1) with k the last movemement before go out. |
12 days ago, # | In D1C,why add Y node? edge x -> Pokémon node with a value of 0? |
12 days ago, # | Can someone please help me in finding the mistake in the following code? Here , I have first calculated the index , which means that the substring b starting from index to n-1 is lexicographically smaller or equal to the substring a from index+1 to n. |
12 days ago, # | Can someone pls review my code and tell me in which test code my code is getting error :) https://codeforces.com/contest/1937/submission/249344544 |
10 days ago, # | Can someone please explain how do we derive the formula for Problem D? I'm so confused! |
10 days ago, # | What is line segment tree mentioned in div 1 D? |
31 hour(s) ago, # | Did the tutorial of Div.1 E missed some factorial notations in the final transform formulas of ? For example , I think it should be . And if this is correct, how can we do D&C + FFT with in the formula? |
-
Thx,typo fixed.
You can read https://mirror.codeforces.com/blog/entry/18842 for D&C + FFT tricks(in DIV1E).
20 hours ago, # | Thanks wuhudsm for the great tutorial for problem div2 E (Pokemon Arena). However, I think there's a typo in the first line of the tutorial. It makes more sense to be like that, Then the problem is essentially finding the shortest path from to and not from to as written in the tutorial. Please correct me if I am wrong. |
3 hours ago, # | D1E, am I right that last_i = max(j<i)(P_j!=P_i)? Or j can be greater than i? |
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK