### BledDest's blog

By BledDest, history, 8 months ago, translation, ,

•
• +68
•

 » 8 months ago, # |   0 In problem F The length of the smallest period is (|t|-plast) instead of |t|/(|t|-plast).
 » 8 months ago, # | ← Rev. 2 →   +6 in problem E , why does this logic fails ?1 : pick vertex with zero in-degree (and with minimum node number ,in case of tie in degree)2 : remove this vertex from the graph and update degree of all other nodes attached to this.3 : assign label to this removed vertex4 : repeat above steps while there are nodes in graphlabels are assigned from 1 to N
•  » » 8 months ago, # ^ |   0 Becouse then you firstly attach one to first vertex it might have parents. You need to do it from the other side. Label highest leave n and remove it.
•  » » » 8 months ago, # ^ |   0 sorry ,by "degree" i meant "in-degree"
•  » » 8 months ago, # ^ | ← Rev. 9 →   0 Try this:- 10 23 1 4 1 The problem here is the algorithm tries to allocate the best position for value 1,2,... and so on.But this greedy algorithm forces you to place a bigger number at the more significant position.
•  » » » 8 months ago, # ^ |   0 or just ``````3 1 3 1 ``````
•  » » 8 months ago, # ^ |   0 counter example`4 -> 1``2 -> 3`
 » 8 months ago, # |   0 For problem A, why the accepted output of input '100' is '100', shouldn't it be '10'? (Because first we meet 1 and then terminate of first digit with 0 and then we meet 0, thus the output is 10) sorry for my bad english
•  » » 8 months ago, # ^ |   0 I also can't understand this one
•  » » 8 months ago, # ^ | ← Rev. 2 →   0 The problem said that `0` character separates blocks consists only character `1`, and the length/size of each block is the digit it represents.For the input `100`, we can rewrite it like this: `(1)0()0()`. So there are 3 blocks. First block has size 1 and the other 2 have size 0. So the output is `100`.
•  » » » 8 months ago, # ^ |   +5 I'm too have written solution with using split as you have, but in Java blocks with zero-length lines skips.
•  » » » » 8 months ago, # ^ |   +2 yes, it is like the difference between `.split()` and `split(' ')` in python
•  » » 8 months ago, # ^ |   +1 We divide line using '0',start,end. Then print count of '1' in every segment.
•  » » » 8 months ago, # ^ |   0 Thanks for your explanation by image. Initially I thought all zeros themselves were separators which separate the digits before each of it and the digits after each of it, and zeros appeared only when there were at least three zeros, for instance, 11000111, in which the first and the third zeros respectively separate 11 & 0 and 0 & 111, meaning the result is 1+1 and 0 and 1+1+1.
 » 8 months ago, # |   0 Can somebody explain problem c I find it diffcult to understand
•  » » 8 months ago, # ^ |   0 The problem is saying that you have a person who has to solve the problems in the Decoder contest, and he has only solved difficulty k problems before. He will only be able to solve a problem if its difficulty is <=2k. So in some cases, he needs to go solve harder problems outside until he can get high enough to finish the original problem.For example, k = 3. If one problem is difficulty 10, he can't solve it. First, he needs to solve a difficulty 6, and then he can solve 10.
 » 8 months ago, # |   0 In problem F, why the answer for the string `kbyjorwqjk` is 11 and not 12 (test case 4)?
•  » » 8 months ago, # ^ |   +10 answer can't be greater than |s| + 1
•  » » » 8 months ago, # ^ |   0 Why not? What would be the compressed version for this string?
•  » » » » 8 months ago, # ^ |   +5 1kbyjorwqjk
•  » » » » » 8 months ago, # ^ |   0 Lol, my bad. For some reason I thought the quantity of characters of the period should precede it, not the number of times it is repeated. Thanks a lot for the help.
 » 8 months ago, # |   +3 WA in test 14 prob D but i can't check what that test is
•  » » 8 months ago, # ^ |   +3 Use long long
•  » » » 8 months ago, # ^ |   0 thank you so much
 » 8 months ago, # |   0 In problem D, If i make a count map for all characters for string t and then consider window length of strlen(t) in string s.Now in each window, there is map count for all characters and then a variable storing count of number of empty characters -> '?'. Now we match the count array of t with count array of window and see if there is a match considering empty characters with all unmatched characters.Lastly, if i get a match , I jump from i->i+strlen(t) otherewise i->i+1.Will this algorithm work..??
•  » » 8 months ago, # ^ |   0 It should work. Here's my solution, though I think it's slightly different from yours. I stored all positions of '?,' then iterated through them. For each position keep going through all letters in t while subtracting it from a count map if it is already in string s (not a '?'). If a letter isn't in s, we set the current '?' to that letter and repeat for all other positions. Ignore the variables 'bad' and 'mx.' I forgot to delete them but they are unused. 28608658
 » 8 months ago, # | ← Rev. 2 →   0 UPD : SOLVEDProblem D : i AM Getting WA on test 14 . my solution : http://paste.ubuntu.com/25112777/ can you please help me to find out the bug .
 » 8 months ago, # |   +11 in problem E :I have not understood why doing the same as the editorial but from the other side is wrong yet, I mean why labeling from 1 to N starting from the nodes with in-degree equals to zero is wrong.I applied the proof in the editorial on that and I didn't find anything wrong, could anyone please tell where is my mistake ?thanks in advance.
•  » » 8 months ago, # ^ |   0 I thin there is a bug in your code, when you are trying to do something with unconnected nodes. In the test you fail judge is waiting for 13, while where is no information given about 13. And you print 15, you should print 13, becouse it is unconnected and can be smaller than 15.
•  » » » 8 months ago, # ^ |   0 sorry if it seemed like I was defending my solution , I know it's wrong !!maybe the code has some bugs. However, you can see that this approach is wrong here by the counter examples that were mentioned in the above comments.what I want to know is why the proof in the editorial can not be applied on my approach, where does it fails!!!!!!
•  » » » » 8 months ago, # ^ |   0 It works, you just fail to implement it
•  » » » » » 8 months ago, # ^ |   0 take this counter testcase:4 23 12 4if you apply our approach on this test you will choose 2 first, then 3,then 1,finally 4. which will give you this permutation :3 1 2 4but the correct solution is to choose 3 first, then 1, then 2, finally 4. which will give you the correct permutation:2 3 1 4if I made a mistake, hope you clarify where it is
•  » » » » » » 8 months ago, # ^ |   0 4->2->4 is a cycle
•  » » » » » » » 8 months ago, # ^ |   0 i'm crashing my head with walls now4 is the number of nodes2 is the num of edges
•  » » » » » » » » 8 months ago, # ^ |   0 Ohhh, now i see why it doesn't work... Also look at sneaky test 6...
•  » » 8 months ago, # ^ | ← Rev. 2 →   +1 From the set of nodes of in-degree equals to zero: picking node V, the one with smallest index to be labeled '1' will not always give the lexicographically smallest permutation.Let's apply the same approach of the editorial: let node V be labeled X (X > 1), this labeling may result that other node U (U < V) get labeled Y (Y < X) which result in lexicographically smaller permutation.So applying the same approach won't result in a contradiction.
•  » » 8 months ago, # ^ |   0 Look at this testcase: n = 3, m = 1; An edge from 3 -> 1. Ur algo gives 3 1 2 as the output whereas 2 3 1 is the lexicographically smallest.
 » 8 months ago, # |   0 Sorry for the incorrect formula in F, it is fixed now.
 » 8 months ago, # |   0 Can someone explain reason for MLE in my code?Code : 28646208
•  » » 8 months ago, # ^ |   +1 Same problem as here. Your binary search may find incorrectly a big number as answer. So this vector that you create to build the answer will exceed the memory limit.
 » 8 months ago, # |   +1 Can someone help me with my solution for D ? I'm getting WA Code : 28647476
•  » » 8 months ago, # ^ |   +2 The problem was overflow inside your check function. If the frequency of some letter is big and you test a big number at the binary search the result of multiplication may exceed by far the int limit.
•  » » » 8 months ago, # ^ |   0 Thank you, AC :)
 » 8 months ago, # |   0 Could someone please explain problem D more clearly?I didn't get that.Thanks ins advance :)
•  » » 8 months ago, # ^ |   0 I tried explaining my solution in a comment above (under Todi_Kunal). If you have any further questions, feel free to ask. 28608658
 » 8 months ago, # |   0 Can anyone tell me What is qsum in 825D?
•  » » 8 months ago, # ^ |   0 How many question marks there is at string s.
•  » » 8 months ago, # ^ |   0 Whoops, my bad. Fixed it, now it's qcnt in both initialization and formula.
 » 8 months ago, # |   0 In 825F how the prefix sum is calculated? How the complexity is reduced from s^3 to s^2?
 » 8 months ago, # | ← Rev. 2 →   0 Can someone please help me find the mistake in my code for 825F?? Getting wrong answer on test case 13. submission/28674792
 » 8 months ago, # |   0 Hi :) I have read that problem E can be solved with a "somewhat standard approach, involving advanced data structures and quite tedious to implement" (Petr words xD).I understand that the intended and best solution is the one described here, but I would like to know what is this other solution? :)Could anyone elaborate on this? Thanks
•  » » 8 months ago, # ^ | ← Rev. 2 →   0 I have a basic idea however not sure how to optimize it. Reverse the edges first. Choose the smallest index that is yet to get a number, mark all the nodes reachable from it. We can assign a number to this index only after assigning number to all the nodes reachable from it. Among the nodes reachable from this index, choose the smallest index that is yet to get a number and repeat the process.
•  » » » 8 months ago, # ^ | ← Rev. 2 →   0 Yes, that's the question haha, is it possible to optimize those kinds of naive algorithms?Another similar way will be:Reverse the edges.Go over the nodes in increasing order. For a node v, count x = the number of nodes reachable from it (including itself), v's label has to be  ≥ x, so we can choose the smallest free label among those  ≥ x and assign it to v.No idea if this can be done better than in O(N2)upd: this doesn't work as pointed by MrDindows, thanksThe obvious bottle neck for these algorithms is to get the size of the "reach" of a node, I wonder if there's a way to optimize that, or if the other solution uses a different approach.
•  » » » » 8 months ago, # ^ |   0 oh okay! misunderstood your question!
•  » » » » 8 months ago, # ^ |   0 Such solution wouldn't work at all.Testcase:3 13 1
•  » » » » » 8 months ago, # ^ |   0 you're right, thanks. But do you know what "standard approach" is Petr talking about in that post?
 » 8 months ago, # |   0 In the problem C : 825C - Multi-judge SolvingAre we supposed to find the number of questions that are to be solved only from some other judge?
 » 8 months ago, # | ← Rev. 2 →   0 Can anyone explain test case in G? What i understand that graph is 1-2-3-4 and queries are:1)set 2 vertex black2)set 2 vertex black (again?)3)get answer for vertex x=2.we have only one black vertex (=2), so the only path between 2 and black vertex is zero path from 2 to 2. so the answer is 2. Where am i wrong?
 » 8 months ago, # |   0 For problem C, why not choose the most hard problem like with difficulty 10^9 to solve at first? Then we can solve all other problems , isn't this the best way?
•  » » 8 months ago, # ^ |   +7 Before solving a problem with difficulty Y on any judge,you have to solve a problem with difficulty which is greater than or equal to Y/2
•  » » » 8 months ago, # ^ |   0 I see, thanks!
 » 8 months ago, # |   0 can anyone please explain what is wrong with my solution of F http://codeforces.com/contest/825/submission/28946671
 » 8 months ago, # |   0 Can someone please help me debug this code ?.I have checked it many times and it seems correct to me.