### Vovuh's blog

By Vovuh, history, 17 months ago, ,

1003A - Polycarp's Pockets

Tutorial
Solution (Vovuh)

1003B - Binary String Constructing

Tutorial
Solution (Vovuh)

1003C - Intense Heat

Tutorial
Solution (PikMike)

1003D - Coins and Queries

Tutorial
Solution (Vovuh)

1003E - Tree Constructing

Tutorial
Solution (Vovuh)

1003F - Abbreviation

Tutorial
Solution (Vovuh)

• +39

 » 17 months ago, # |   +4 In E, won't the distance change upon inserting new edges and if yes, how to update the "maximal distance set" efficiently?
•  » » 17 months ago, # ^ | ← Rev. 4 →   +3 The previous explanation was wrong, i had understood it now.If the distance for some vertex v will change after adding the new vertex, it means that we attach some leaf that increases the diameter of a tree. But it means that we attach a leaf to the vertex w with distw = d, but in this case we already doesn't have the answer.
•  » » 17 months ago, # ^ | ← Rev. 5 →   0 It is possible to prove that there exists such a tree iff n * (k - 2) <= -2 + k * (k - 1) ** (d // 2) for even n and n * (k - 2) <= -2 + k * (k - 1) ** (d // 2) + (k - 2) * (k - 1) ** (d // 2)for odd n. We simply check if conditions above are satisfied and proceed with making the tree or not.Edit: also, obviously it must be that n > d as said in the articleEdit: k = 1 and k = 2 should be treated as special cases
 » 17 months ago, # | ← Rev. 2 →   -13 :
 » 17 months ago, # |   +8 My solution to F was to assign an integer to each distinct string (since there's a maximum of 300) while keeping track of lengths for each of these integers and then run a KMP search to find the number of occurrences of each valid subsequence. This solution runs in approximately the same time complexity as the editorial's.
•  » » 17 months ago, # ^ | ← Rev. 2 →   0 My solution is same with you.39944563Or maybe it can solved by hashing, but it may be hacked if I use hashing with overflow.39945601 39946612
 » 17 months ago, # | ← Rev. 3 →   +7 There is an O(n) approach in problem C.coderough explanation
•  » » 17 months ago, # ^ |   0 your pish and pop operations aren't constant time operations.
•  » » » 17 months ago, # ^ |   0 But each node would be push and pop 1 time.I don't know why so much downvotes.
•  » » » » 17 months ago, # ^ |   0 No idea why you're getting downvotes (that shouldn't matter tho, if you think your comment is constructive), your solution is very efficient.
•  » » » » » 17 months ago, # ^ |   0 It is a classic method to optimize DP. I think I am doing nothing wrong to point it out in the case that editorial doesn't mention.
•  » » 17 months ago, # ^ |   +9 It seems that people are likely to downvote algorithm they don't know.I think that is a very simple way to analysis the complexity, but it might be far too difficult for those rating is under 1600?
•  » » 17 months ago, # ^ |   0 Can you please explain your solution?
 » 17 months ago, # |   +3 what wrong in problem F makes a lotta participants output 689 in test 6 instead of 581?
•  » » 17 months ago, # ^ |   0 Those solutions most likely did not consider more than two segments (only exactly two). The sample tests did not cover this.
 » 17 months ago, # | ← Rev. 2 →   0 what is wrong with my solution for D:https://codeforces.com/contest/1003/submission/39974183or mby i am not getting editorial??
•  » » 17 months ago, # ^ |   0 I did not read your entire code, but why are you running for loop until x>=0 it should be x>0.
•  » » » 17 months ago, # ^ | ← Rev. 2 →   0 yeah i tried it bt it doesn't matterupd:got AC [I am DUMB]
•  » » » » 17 months ago, # ^ |   0 what was the issue?
•  » » » » » 17 months ago, # ^ | ← Rev. 3 →   0 My code was giving output:6 11 1 2 2 4 412output:-1
•  » » » » » » 17 months ago, # ^ | ← Rev. 2 →   0 The link which you provided gives output 2 xD , Anyway forget it.
•  » » » » » » » 17 months ago, # ^ |   0 okay output should be 4 btw
•  » » » » » » » » 17 months ago, # ^ | ← Rev. 2 →   0 Oh you changed it from 8 to 12, Okay
 » 17 months ago, # |   0 can anyone explain me the method for Problem C becoz despite several efforts i m unable to figure it out
•  » » 17 months ago, # ^ |   0 my approach is quite simple what I have done is to check for all segments the average temperature and we will consider which gives best answer and has size >= k my code
•  » » » 17 months ago, # ^ |   +1 Bro really thanks for ur help my approach is also quite the same but i got a TLE i m giving my code link plz help as I m beginner and really want to increase my skills http://codeforces.com/contest/1003/submission/39983625
•  » » » » 17 months ago, # ^ | ← Rev. 2 →   0 I think "accumulate" as a third for loop .So the complexity is 5e3*5e3*5e3 , it will give you TLE. In worst case if n is 5e3 and k is 1 .
•  » » » » » 17 months ago, # ^ |   0 thanx bro ,,,, rest i think my algorithm is correct am I right??
•  » » » » » » 17 months ago, # ^ |   0 You're right,but in this problem you don't have to use "accumulate".Think in a different way.
•  » » » » » » » 17 months ago, # ^ |   0 i fixed by using sum=sum+v[i];
•  » » » » » » » » 17 months ago, # ^ |   0 Try it : ) . If it gives you a wrong answer , think about "what is the wrong in your code and what is the test you will fail in ", if you don't know , tell me , I will help you : ) .
•  » » » » » » » » » 17 months ago, # ^ |   0 thanx bro ...i passed all the test cases... thanx for ur help
 » 17 months ago, # | ← Rev. 2 →   0 In problem D my code passed all pretests but it timed out on 27th Case in system testing. No wonder how. Code complexity Q * 32 * 32. Can someone suggest something? Code
•  » » 17 months ago, # ^ |   0 unordered_map operations works some more than O(1).
•  » » 17 months ago, # ^ |   0 U can easily adjust to only Q * 32 operations with a greedy strategy. A complexity has no constants is it. your complexity is O(Q) if you say so. Map operations are O(log) so the number of operations is even worse in your solution. Just adapt to O(Q * log(MAX_VALUE) + N * log(MAX_VALUE)) which actually is O(N * log(VAX_VALUE)) because N and Q constrains are the same. Now to adapt you can just do this: the solutionread editorial
 » 17 months ago, # |   0 Could someone explain why it didn't pass even the pretests? (problem D, WA test 4)Code
 » 17 months ago, # |   0 What do think is wrong with my sol for binary string problem here: http://codeforces.com/contest/1003/submission/39907389 I believe it runs perfectly on the four cases you mentioned in your blog
 » 17 months ago, # |   0 For Question B: Binary String Constructing, is there a recursive approach? Does anyone know similar problems like this, where it has a large number of generalized test cases?
 » 17 months ago, # |   0 for problem E,shortest code :http://codeforces.com/contest/1003/submission/39967116
 » 17 months ago, # | ← Rev. 2 →   0 why it times out on test 23?? (problem E) http://codeforces.com/contest/1003/submission/39989027 but if i assign the values of test 23 and upload the code here it will not time out!!: http://codeforces.com/contest/959/submission/39989086 why????????????? :(
 » 17 months ago, # |   0 anyone with better explanation of F using DP
 » 17 months ago, # |   0 Is it possible to solve problem D using Python?
 » 17 months ago, # |   0 can anyone tell me what does __builtin_ctz(x) do?
•  » » 17 months ago, # ^ |   0 It counts trailing zero in the binary representation of a number. https://www.go4expert.com/articles/builtin-gcc-functions-builtinclz-t29238/
•  » » » 17 months ago, # ^ |   0 ok THX :)
 » 17 months ago, # |   0 Why is a random_shuffle performed at the end of the code for problem E?
 » 15 months ago, # |   0 Any O(nlogn) or O(n) method for C?