### flamestorm's blog

By flamestorm, 2 months ago,

We hope you enjoyed the contest! Sorry for the late editorial.

1760A - Medium Number

Idea: flamestorm

Tutorial
Solution

1760B - Atilla's Favorite Problem

Idea: SlavicG

Tutorial
Solution

Idea: Errichto

Tutorial
Solution

1760D - Challenging Valleys

Idea: mesanu

Tutorial
Solution

1760E - Binary Inversions

Idea: SlavicG

Tutorial
Solution

1760F - Quests

Idea: flamestorm

Tutorial
Solution

1760G - SlavicG's Favorite Problem

Idea: SlavicG

Tutorial
Solution

• +50

 » 2 months ago, # |   +8 Such a elegant implementation of problem G
 » 2 months ago, # | ← Rev. 2 →   +4 I believe C can be done in O(n). Read everything into array a Find two maximum values — max and pre_max Do a run: for (i in a) if (i == max) print(i - pre_max) else print(i - max) 
•  » » 2 months ago, # ^ | ← Rev. 2 →   0 Yes, this one is work. You can check my solution that use idea of remember max and pre_max: 181961801
•  » » » 16 hours ago, # ^ |   0 can you post it cause it says I'm not allowed to view it
 » 2 months ago, # |   +1 I had the exact same idea for G as the tutorial, But I screwed up the implementation in so many ways
•  » » 2 months ago, # ^ |   0 I find 'screwing up in so many ways' very relatable and funny, maybe this should be my spiritual quote!!
 » 2 months ago, # |   0 Why is this code for problem C, getting TLE? Code
•  » » 2 months ago, # ^ |   0 "Arrays.sort" has a bad worst case time complexity in Java and can be hacked. See https://codeforces.com/blog/entry/102175 and maybe some other blogs on this topic.
 » 2 months ago, # |   +1 Damn the problem ratings are so inflated
•  » » 2 months ago, # ^ |   0 I think only G and F are inflated, G should be 1500/1600, but then again, for some 1500s and 1600s I think trees are a new topic, so it is normally going to be inflated, while F is just a binary search with a few more steps, so I think it should be 1300/1400.
•  » » » 2 months ago, # ^ |   0 cap, SlavicG problems are proven to be $3500$
•  » » » » 2 months ago, # ^ |   0 It's actually a really nice problem, I just don't think it's that hard
 » 2 months ago, # | ← Rev. 2 →   0 In problem F, I also sort the array in descending order and then I made a prefix sum of n elements. (Let's call it p) We have 3 situations:1.If (c + p[1] - 1) / p[1] > d then there's no way that we can get c coins in d days.2.If there is p[i] (i <= d) such that p[i] >= c then any value k satisfies.3. Brute-force k from d to 0 as k >= d + 1 in this situation is not possible anymore.Time complexity is O(n log n + d)
•  » » 2 months ago, # ^ | ← Rev. 2 →   0 Hi, @TrendBattles, If the sum of the entire array is greater than the c coins needed, will that not result in infinity? In case 2: you wrote only for a particular element, why so.?? What if a particular element is not greater than c but the entire array sum is greater?
•  » » » 2 months ago, # ^ |   0 Well, I made a prefix sum of n elements and p[i] is the sum of the first i elements.
 » 2 months ago, # |   0 https://ideone.com/3eEgf3 whats the problem in this code. wa on test 2... problem D
 » 2 months ago, # |   0 For problem G，unordered_map will give you TLE
 » 2 months ago, # |   0 why does my code get TLE for problem G. #include using namespace std; int t; int n, a, b; void dfs(int u, int now, int father, vector>>& g, unordered_set& st) { if (father != -1) { st.insert(now); } for (auto [nxt, w]: g[u]) { if (nxt != father) { dfs(nxt, now ^ w, u, g, st); } } } bool dfs2(int u, int now, int father, vector>>& g, unordered_set& st) { if (st.count(now)) { return true; } for (auto [nxt, w]: g[u]) { if (nxt != father && nxt != b and dfs2(nxt, now ^ w, u, g, st)) { return true; } } return false; } int main() { ios::sync_with_stdio(false); cin >> t; while (t--) { cin >> n >> a >> b; vector>> g(n + 1); unordered_set st; for (int i = 0; i < n - 1; i++) { int u, v, e; cin >> u >> v >> e; g[u].push_back({v, e}); g[v].push_back({u, e}); } dfs(b, 0, -1, g, st); if (dfs2(a, 0, -1, g, st)) { cout << "YES" << endl; } else { cout << "NO" << endl; } } return 0; } 
•  » » 2 months ago, # ^ |   +3 I changed from unordered_set to set and it got accepted182220698
•  » » » 2 months ago, # ^ |   0 why unordered_set slower than set......
•  » » » » 2 months ago, # ^ |   0 While it's true that unordered_set is faster than set on average, the worst case time complexity of unordered_set can get to O(n^2) instead of O(log n) in a normal set (specifically on big prime numbers). It's likely that the test you got TLE on was deliberately constructed for solutions like yours
•  » » » » » 2 months ago, # ^ |   0 ok thx～
•  » » » » » 2 months ago, # ^ |   +1 Must be beethoven97 again
 » 2 months ago, # |   0 How does G solution take care of 2 things?1.) We may never need to teleport and just reach end node with value 0. In that case inside dfs2, we need to have a condition for that.2.) I don't see where is the condition to not go beyond end node in dfs2 when we don't get true before reaching end node.
•  » » 2 months ago, # ^ |   0 1.) We may teleport from a to a. Consider the following graph Let's say we start at node 1 and need to end at node 3.(n) node-w- connection with weight w (1) -2- (2) -2- (3) It isn't optimal to teleport to any node however we can compare path from 1 to 2 having XOR value = 2 and path from 3 to 2 having the XOR value equal to 2. In that case we don't teleport but if we had to, we would teleport from node 2 to node 2.Alternatively what the functions actually checks is all the possible XOR values starting from a and b. If there is a match answer is yes, else no. In our case we have 2 matches, 0 and 2.We get 0 at the start because that's our starting value and 2 by traveling from node 1 to 2. When starting from b we get 0 by traveling from node 1 to 3 and value 2 by traveling from 3 to 2.2.) dfs2 starts at node b  if(dfs2(b, -1, 0)) cout << "YES\n"; else cout << "NO\n"; It checks if it can hit any optimal values calculated in dfs1. In dfs1 all possible values are calculated where we have the limitation in place.
 » 2 months ago, # |   0 In problem C, I guess you do not need to sort the entire array. What you need is just to find out the largest and 2nd-largest element from the array. (2nd-largest element might be identical to the largest element if the largest value appears 2 or more times in the array)
 » 2 months ago, # |   +1 Awesome round.
 » 2 months ago, # |   0 any idea why I'm getting wa2 in e?
•  » » 2 months ago, # ^ |   +1 It getting WA because of two things:- You need to handle the case in which you will not do any operations. Function cal() needs to return long long, because in the worst case ans = (10^10), this will cause overflow of course.
•  » » » 2 months ago, # ^ |   0 I didn't notice that we can not use the operation thank you <3
 » 2 months ago, # | ← Rev. 6 →   0 "The minimum value of k is 0, and the** maximum value is n** (for larger k, we won't be able to do the same quest multiple times anyways, so it's useless to consider them). "Why the maximum value for k is n? Isn't it d? Then for larger k than d we won't be able to do the same quest multiple times anyways because there are only d days right? So the complexity should be O(n log(n) + d log(d)) ? Am i missing something or?
•  » » 2 months ago, # ^ |   0 maximum value of k depends on d and the entries supplied, it may also exceed dex: A=[3,2,1], d=1,c=3 k can increase infinitely, look, i have a single day to make profit and if i complete the first quest i get the sum>=c, i dont need to use that quest again or any other quest so you can increase k as much as you like
•  » » » 2 months ago, # ^ | ← Rev. 3 →   0 ofc if K can increase infinitly then you return Infinite, you dont infinite loop xd. What i mean is computationally, to find k, you work with order of d not n (or at least in my solution i do that)
 » 2 months ago, # | ← Rev. 2 →   0 can anyone tell me my mistake in problem D 181949662
•  » » 2 months ago, # ^ |   0 yes. you are right. The code shown is same as what you are saying
•  » » 2 months ago, # ^ |   0 Take a look at Ticket 16544 from CF Stress for a counter example.
 » 2 months ago, # |   0 can someone kindly point out error in my solution here for problem G? https://codeforces.com/contest/1760/submission/182250273
•  » » 2 months ago, # ^ |   0 test1 11 2 7 2 11 6 4 6 12 9 4 8 9 10 2 6 3 5 8 1 6 5 2 10 7 3 7 8 2 11 7 1 4 OutputNO answerYES
 » 2 months ago, # | ← Rev. 4 →   0 ..
 » 2 months ago, # |   0 someone please explain "Also, we cannot pass b on the path from a→c." in tutorial of G.
•  » » 2 months ago, # ^ | ← Rev. 2 →   +1 It refers to the fact we cannot pass through the node b (end node) when starting dfs from a. Because it's impossible to enter b without our value being 0.See the problem statementyou are allowed to enter node b if and only if after traveling to it, the value of x will become 0.In other words, you can travel to node b only by using an edge i such that x XOR wi=0.
•  » » » 2 months ago, # ^ |   0 okay:) Thank You
 » 2 months ago, # |   0 Can somebody please explain why i am getting WA 182023139 in G . I am storing xor from starting to ending node in a variable then from every node we can go to ending node . and xor will be xor of node from starting to xor of starting to end and then checking if it exists in our set or not.
•  » » 2 months ago, # ^ | ← Rev. 2 →   0 Made some changes in your code and got AC.Biggest change I did was the starting node in dfs2 and some changes in the functions themselves.Submission: 182291486
•  » » 2 months ago, # ^ |   0 Take a look at Ticket 16545 from CF Stress for a counter example.
 » 2 months ago, # |   0 In 1760D - Challenging Valleys you could also insert INF at the start and at the end of the processed array (without successive equal elements) to simplify the job with edges, then check every triplet inside for a[i-1]>a[i]
 » 2 months ago, # |   0 Can somebody help me with my problem G code. I am getting runtime error in testcase 20.https://codeforces.com/contest/1760/submission/182632177
 » 2 months ago, # |   0 I have submitted this problem like 20 times, but I keep getting wrong answer on token 162 on test 1. I've literally tried debugging every nuance of the code and compared it with the solution, but I don't know what I'm doing wrong. Here's my code: https://codeforces.com/contest/1760/submission/182718256
•  » » 2 months ago, # ^ |   0 You never know, 21st time's the charm.Take a look at Ticket 16543 from CF Stress for a counter example.
 » 2 months ago, # |   0 In the tutorial of problem D it says: i=0 or bi−1bi+1But shouldn't it be like: i=0 or bi−1>bi and i=n−1 or bi
 » 2 months ago, # |   0 did anyone solve G with bfs ? i got stuck in test 40 . any idea why i'm getting wrong answer ? 183283417
•  » » 2 months ago, # ^ |   0 Take a look at Ticket 16546 from CF Stress for a counter example.
 » 2 months ago, # |   0 Could someone point out where my code fails? ato[i] is xor value of path from a to i. 184338941
•  » » 2 months ago, # ^ |   0 Take a look at Ticket 16551 from CF Stress for a counter example.
 » 7 weeks ago, # |   0 why does this code fails 185000763 for G.
•  » » 7 weeks ago, # ^ |   0 Take a look at Ticket 16564 from CF Stress for a counter example.
 » 7 weeks ago, # | ← Rev. 2 →   0 Solved F in O(n) using prefix sum — Code
 » 7 weeks ago, # |   0 Could anybody please tell me what might be the problem in this code for problem E. Its failing on second test case for 2653rd iteration. Link to submission
•  » » 7 weeks ago, # ^ |   0 Take a look at Ticket 16572 from CF Stress for a counter example.
•  » » » 7 weeks ago, # ^ |   0 Thanks man finally figured it out. That site is a lifesaver.
 » 5 weeks ago, # |   0 why my solution is failing on test 2 iteration number 53 code
•  » » 5 weeks ago, # ^ |   0 Take a look at Ticket 16617 from CF Stress for a counter example.
 » 4 weeks ago, # |   0 Can someone help me? The example case of problem F in my local works but in Codeforces it does not. 188250142
 » 3 weeks ago, # |   0 Problem G unordered_set gives TLE but set solution Accepted. I also faced similar issues in other problems as well. Can anyone explain me why this is happening ?
 » 3 weeks ago, # |   0 I have tried stress testing my solution to problem G, and I haven't yet been able to find a test case that breaks my code. Can anyone please take a look at this? 188826168
•  » » 3 weeks ago, # ^ |   +1 Take a look at Ticket 16694 from CF Stress for a counter example.
 » 11 days ago, # |   0 very easy solution all you have to do is iterate and find letter with greatest ascii value and take away 96 #include using namespace std; typedef long long ll; void solve(){ int n, mx = 0; cin>>n; string s; cin>>s; for (int i = 0; i < n; i++){ mx = max(mx, (int)s[i]); } cout << mx - 96 << endl; } int main(){ int tc; cin >> tc; while(tc--){ solve(); } }