Codeforces Round 914 (Div. 2) Editorial
source link: https://codeforces.com/blog/entry/123160
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.
Sorry for the weak pretests on A :(. We hope you enjoyed the round nonetheless.
Idea: Apple_Method
Preparation: Apple_Method/oursaco
Analysis: lunchbox
Idea: oursaco
Preparation: oursaco
Analysis: lunchbox
Idea: lunchbox
Preparation: lunchbox
Analysis: lunchbox
1904D1 - Set To Max (Easy Version) / 1904D2 - Set To Max (Hard Version)
Idea: oursaco
Preparation: oursaco
Analysis: oursaco
Idea: Apple_Method
Preparation: oursaco
Editorial 1:
Analysis: oursaco
Thanks to errorgorn for the solution!
Editorial 2:
Analysis: willy108
Idea: Apple_Method
Preparation: oursaco
Analysis: Apple_Method
4 days ago, # | after this contest i realised, that chess tasks are not for me)) i solved B easily, mb im stupid for A idk |
-
Lol, I could say the same about math tasks. My suggestion would be for you to go onto chess.com and practice in your free time :)
-
i don't think the problem is that you are not good at chess enough, this is really just a brain teaser, i might suggest instead to get familiar with those type of problems, a good book about this is "The art and craft of mathematical problem solving", an interesting one full of problems, although it barely talks about math, just skip the math ones since the book structure is designed for so :3
-
-
and who can explain why this 236632847 doesn`t work ?
-
Try this sample:
Correct answer would be
1
instead of2
(from your solution)The reason is that when you use
upper_bound
, it give you the first element that is considered greater than your number. You should get theprev
of that element for calculating difference. In the case above,1006 - 1000
give you6
andupper_bound
give you8
, but you should look for5
-
4 days ago, # | Got TLE in B on system testing. Did two wrong submissions also on B. I was hoping to be blue today. But missed the chance. |
4 days ago, # | What's wrong with this solution for A? 236554300 |
-
Don't do that, if you check all cases by it makes your code so long and sometimes missing cases lead to WA. Instead of using you can make 2 vectors Move_x, Move_y then For from 0->7 (a knight can move 8 cases) from the Queen and King, If a cell can be moved by King and Queen your Ans++. You can refer to my code: 236529329
4 days ago, # | I liked D2 on how simple its implementation really was. Even though I implemented sparse table and range update segment trees, realizing it only required monotonic stack was pretty cool. |
4 days ago, # | can anyone tell me why did I get TLE here ? https://codeforces.com/contest/1904/submission/236554358. I think the complexity here is O(N*N*log(N)). Am I wrong? |
-
Quite strange that commenting out the map gets it accepted because the map itself should run in O(N*logN)
-
thats why I'm asking. I really didnt understand the issue in that part of the code.
-
- Your set h contains at most N ^ 2 elements. Then u lower_bound in that set for every i in array a, and run the pointer back to the beginning of the set, so the time complexity is O(N ^ 3 * logN)
-
Should the time complexity not be O(N^2 logN). As logN is required to find the upper/lower bound in the set for an element. Why there is an additional N factor in TC. Could you please explain?
-
-
4 days ago, # | Thanks for contest |
4 days ago, # | Can someone try hacking this solution to D2? |
-
This test will TLE, courtesy of porker2008
print(1) print(200000) ans = [200000 - i for i in range(200000)] print(" ".join(map(str, ans))) ans = [min(200000, 300000 - i) for i in range(200000)] print(" ".join(map(str, ans)))
4 days ago, # | Loved this competition! My solution to problem C first failed on system testing, but then suddenly the verdict changed) Also, my friend’s solution failed on the same test, but it changed the verdict after the final results! Can someone please explain how this could be, because I just don't understand how system testing works on Codeforces. Sorry for my poor language...) |
4 days ago, # | can somebody help me with the reason of tle on d2(hard version) on test case 25 .here's my submission — https://codeforces.com/contest/1904/submission/236593367 |
4 days ago, # | Cool Contest! |
4 days ago, # | For D1/D2, I had a solution I'd like to share. Firstly, if any position exists such that a[i] > b[i], then obviously there's no solution. Then, I iterated over the numbers from 1 to n, and for each i, I tried to find all the intervals centered around a position j such that a[j] = i. I then tried to extend it as much to the left and right as possible without messing any conditions up. I found that it you did this for all numbers from 1 to n in increasing order, then you'll either construct a valid solution or find that it's impossible to do so. You can optimize this a bit for D2 by binary searching how far to the left and right you'll extend your current position to and using range assignment and range query operations to check if the intervals you're using are okay (You can do that with a lazy segment tree). In essence, it's similar to the official solution except you actually construct the solution in this case instead of determining if it's possible. Here's my submission: 236596139 It barely passes in time lol |
4 days ago, # | It will be better if F offers stronger samples. I finished coding and passed samples in 15 min but got WA on #3, and failed to debug in remaining 30 min. Anyway, A~D are enjoyable. |
4 days ago, # | In problem E, how are we handling the case when path is outside of current subtree? |
4 days ago, # | Was the TL and ML for problem F a little tight in this contest? I see a lot of submissions here which have taken > 3 seconds. I have roughly the same solution as the editorial, except that my graph is built with edges denoting >= relationships (instead of > relationships), then I find the SCCs of the graph, and the remainder of the construction is roughly the same. Or is there something else extremely slow about my code? I could get it to pass very narrowly with pragmas though. |
4 days ago, # | E is a great problem, thank you for such a masterpiece! |
4 days ago, # | 236621743 can someone please give me any idea to improve this code as iam getting time limit exceeded for test3 of B. |
4 days ago, # | Can someone help me understand the solution for D.Why does there always exist a valid sequence of operations if we can satisfy the conditions for each element independently |
3 days ago, # | How to solve problem E if the queries given online? |
3 days ago, # | Nice Solutions. |
3 days ago, # | Can someone help me in C? The first test gives me MLE and WA but in my computer gives me a correct answer 236711122 |
In Problem F, can anyone explain how they are achieving this exactly: "Given a path and a node, add a directed edge from the node to every node in that path"? I can't understand how they can add edges to (or from) all the nodes in the path, won't that take linear time? Also, in this sentence "we can repeatedly add an edge from that node to the largest node we can" what does "largest" node mean? |
-
Imagine creating a binary lifting on the tree. You have , , etc. Here, is an auxiliary node that has edges to and . is an auxiliary node that has edges to and . Note that this is equivalent to having edges to , , and . Similar to how you always jump up the largest power of 2 that fits when you perform binary lifting, you will always add an edge to the auxiliary node with the largest power of 2 that fits. This will always require at most edge additions.
3 days ago, # | There is also a online sol for E (although with high constant). Take the euler tour of the tree (the version where you insert again every time you go to a new node, exactly like this image taken from https://cp-algorithms.com/graph/lca.html ): Lemma: the length of the diameter of a tree is for , being the height of the node in the euler tour. In that case, if is the node in the euler tour, the endpoints of the diameter will be and and their lca will be . Proof is an exercise to the reader ;) Using that lemma, we can ban segments like the solution 1 and if is the source node of our query, the answer will be for or for , which can be done with a segtree. You just need to remember to rollback your updates after every query. Code: https://codeforces.com/contest/1904/submission/236721097 |
3 days ago, # | Hi can someone help me in figuring out why my two pointer approach for problem C is failing? |
2 days ago, # | In problem C should I pick different (i,j) each time? |
2 days ago, # | Or can someone share their two pointer approach for problem c? |
46 hours ago, # | Direction of the edges in the explanation for the solution for F are backwards |
40 hours ago, # | can someone please explain what does if so, why sorting array in this problem doesn't violate the condition of |
-
You are correct.
|a|
means the length of the arraya
.Essentially, in each operation, you can pick two different elements (can be equal) from the array and compute the absolute differences and put the result back to the array.
So the order of the elements in the array does not matter and you are free to reorder the array (including sorting it).
32 hours ago, # | Can anyone explain me how edges are created in "problem F" in simple way and why are they created in that way(thought process)? |
32 hours ago, # | why do we need to find smallest ai satisfying ai≥v and greatest ai satisfying ai≤v in C why can't we go over all combinations of dif[i]-a[j] (where dif is the difference array of a of length n-1) failed submission : https://codeforces.com/contest/1904/submission/236901057 |
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK