### fcspartakm's blog

By fcspartakm, history, 3 years ago, translation, ,
Tutorial is loading...
Tutorial is loading...
Tutorial is loading...
Tutorial is loading...
Tutorial is loading...
Tutorial is loading...

• +52

 » 3 years ago, # | ← Rev. 2 →   +3 Problem D was very interesting. Can't solve it during contest but spend all of my time on this problem. I can't understand the editoroal properly for this problem. Can anyone exolain this or give some info on how to become good at this kinds of problems.During Contest I try to solve this using Binary Search and Two Pointer. But I can't figure it out.
•  » » 3 years ago, # ^ |   +9 If the number of days with negative temperature is larger than k then there is no solution. Otherwise there is a solution which is maximum 2*cnt ; (cnt number of negative segments) (because you need to change to Winter rubbers before the negative segment and change back to Summer rubbers after the negative segment is over). Now you have k — cnt days you can use Winter rubbers so if we can use them to merge 2 negative segments this will reduce the answer by 2. It's now obvious that we can greedily pick the shortest positive segments that lie in between 2 negative segments and delete them (as described in the tutorial). One special case is shown in the 3rd sample tests which is if you have enough days left for the last positive segment (that lies after the last negative segment), you can skip changing back to Summer rubbers at the end, thus we decrease the answer by 1.
 » 3 years ago, # |   0 Thanks for contest! Waiting for the next contest!(^_^)7
 » 3 years ago, # |   0 Easi tasks)0))0)
 » 3 years ago, # |   0 Unusual terrible bugs at unusual contest time...
 » 3 years ago, # |   +1 Can someone please give proof of why the last segment of days with non-negative temperature has to be processed separately ? and not inserted in the heap. As far as i can think of that the other segments give us 2 changes per segment and the last will only give 1 change. But how is the length of days not the priority when we are considering last segment of non-negative temperature.??
•  » » 3 years ago, # ^ | ← Rev. 2 →   +3 Because the last segment will decrease the answer by only 1, so it's better to get rid of another segment that will guarantee decreasing the answer by 2. Observe this Test Case: 5 4 -1 1 1 -1 1 If you were to choose the last segment [5,5] because it's smaller than [2,3], then the answer would decrease by one (answer = 3) and then I can't get rid of the segment [2,3] because I can use the winter rubber only once more. But if you choose the segment [2,3] then the answer would decrease by 2 (answer = 2) which is a better solution.
•  » » » 3 years ago, # ^ | ← Rev. 2 →   +3 I had the same approach but I am timing out on test case 12.Is O(nlogn) not appropriate>?
•  » » 3 years ago, # ^ |   +5 I will try to prove you why last segment is least important.Consider last segment gives you 1 point and other segments which are stored give you 2 points. Let initially k be some value which decreases as we move through the set till we reach a point we can’t gain any more 2 points.Now if leftover k is greater than the special segment we have no problem, we will gain one more point. But now you might think what if left over k is less than the special segment?.Well it turns out if you have to extract 1 point from this segment you will have to increase your k value!The only way to do this is to give up one segment that gave you 2 points. So will you a trade of 2 points for 1 point?:). I hope this clears your doubt.
 » 3 years ago, # | ← Rev. 7 →   +9 One of my classmates provided a solution for F in . Let us suppose that the ans is less than 162 * k. We devide the ans into 2 parts length of which is k. For the hinder part,suppose that if we have known how many letters we can use at most i times in the hinder part,we can get dp[s] interesting numbers while s is the state about it. Of course if i > k we can consider i = k.So the number of kinds of s is 16k + 1 at most. We can pretreat the dp array in O(16k + 1). Then we enumerate the front part in O(16k) and query the instereting number by dp array in O(1). So the solution is . Yeah,my English is really bad.QwQ
 » 3 years ago, # |   0 Can anyone help me the Problem C. I have wrong answer in test 9. Then I fix some in that, then it accept, but I can't regconize the difference between the old and new. Please help me.Here the accepted code : http://ideone.com/wPPQrNHere the "same" code wrong answer test 9 : http://ideone.com/z12T9u
•  » » 3 years ago, # ^ |   +6 You are getting WA because you tried to use the available servers but failed (because there isn't enough servers), but you already changed the values of the array Time. This means you skipped a task because not enough servers but you marked some of the servers as used for this task (but you shouldn't mark any servers if you skipped the task).
•  » » » 3 years ago, # ^ |   +3 Thank you very much, sir. Finally I can see my big mistake
•  » » » 3 years ago, # ^ |   +3 thanks Ibrahim.
•  » » » 3 years ago, # ^ | ← Rev. 3 →   0 In problem C for this case:12 33 3 21 3 14 1 1ACCPTED OUTPUT :6154BUT why not:664my explanation :for 1st task all server are not busy so i can use first 3 => 1,2,3 . They will free at 5th second (3,4 second will be busy) . So 6 . Look here before the 3th second in 1,2 seconds server 1,2,3,......,12 was unoccopied .So for second task since starting is from 1st second so it can be perform 1,2,3 servers since , "before the 3th second in 1,2 seconds server 1,2,3,......,12 was unoccopied ". so 6 .For the task 3rd . In the 4th second there will be unoccopied server : 4,5,6,......,12 i will pick the smallest so 4 .
•  » » » » 3 years ago, # ^ |   0 "The tasks are given in a chronological order"
 » 3 years ago, # |   +3 sir, i am struggling with today C, Server here is my code https://paste.ubuntu.com/23652768/ here i upadate my FREE[] while checking each server and getting WA. But some people got AC since they update it at the end,(comment in my code) my question is why this happening?? thanks in advance
•  » » 3 years ago, # ^ |   +3 This is because it is not guaranteed there will be enough servers to handle the request, in this case, none of the servers should be occupied by the task. If you update the status of the servers before determining if there is enough servers, it could result in occupying servers which are not supposed to be happening.
 » 3 years ago, # |   +11 Can someone explain F in more detail . Is it similar to digit DP ?
 » 3 years ago, # |   0 Is there any other way to solve D ??
 » 3 years ago, # |   +3 Sir, please help me with 747E - Comments. My approach is similar to the editorial : Firstly, I separate all the number and string and store it in a vector. After that, I find the depth of each word by DFS and print it. I think it will work in O(n), but as you see, it nearly TLE in test 9 and TLE in test 29. Here is my code: 23167334Thank you very much.
•  » » 3 years ago, # ^ |   +9 True, but you have an implementation problem in the separate function, you use s = s + str[i] which has a complexity of O(|s|), where you can use s += str[i] which has a complexity of O(1). 23169430 here I got AC just by changing this line of code.
•  » » » 3 years ago, # ^ |   +8 Oh thank you very much, I think that they have the same complexity. Lost E just because this :(.
•  » » » » 3 years ago, # ^ |   0 Now you know better, good luck next time.
•  » » » 3 years ago, # ^ |   0 What is the reason behind this?
•  » » » » 3 years ago, # ^ |   +3 Because s += str[i] will simply add the character to the string in O(1) (similar to push_back in Vectors), but with s = s + str[i], the compiler will make a copy of s and add str[i] to this copy and then assign the result to s which will takes a lot of time O(|s|).
 » 3 years ago, # | ← Rev. 2 →   0 Problem C is mostly similar to this problem : 416B — Art union
 » 3 years ago, # |   0 Can someone, please, explain problem F in more details?Thanks for the help!
•  » » 3 years ago, # ^ | ← Rev. 5 →   +5 I can describe my solution Binary search on what is the answer(mi). So, the problem reduces to counting number of numbers <= mi such that each digit occurs <= t times. In fact, we solve a more general problem — find number of numbers of length i such that each digit j occurs <= b[j] times. 0 complicates the matter somewhat but for the time assume that 0 can be placed anywhere and obeys constraint like the normal digits. Then formulate dp[i][j] = number of numbers with i digits and place only digits <= j. Iterate k = how many j digits will be there — 0 to min(i,b[j]) then dp[i][j] = sum((i choose k)*dp[i-k][j-1]). Base cases are simple to write. Overall count can be calculated by fixing highest digit(depends on mi) and then a dp call, then next digits etc.. similar to what we do in offline digits dp solution. The prefix digits that are fixed decide what array b is(t — number of times digit has occurred till now). Finally for 0, simply calculate for lesser lengths using a similar logic. Checkout my solution for more details. Time complexity = O(p^3*d^3) where p=max digits in answer=9 and d=16 and = runs in 15 ms :)
•  » » » 3 years ago, # ^ |   0 Can you explain a bit more on how do we handle dp when the prefix digits are fixed?
•  » » » » 3 years ago, # ^ | ← Rev. 3 →   0 If you have done any question in which we need to count numbers <= x such that some property holds then we calculate d[i] = number of numbers with length i having that property and run this loop: for(int k=MAX_DIGIT; k>=0; k--) {//digits from MAX_DIGIT to k+1 are equal to digits in x implicitly. for(int i=0; i
•  » » » » » 3 years ago, # ^ |   0 Thanks, got it now. I mistakenly interpreted that there is a way to fix the prefix and not recalculate the dp array.
•  » » » 3 years ago, # ^ |   0 Thanks a lot for your help! Got accepted!
 » 3 years ago, # | ← Rev. 4 →   0 I guess I'm misunderstanding problem F statement, because I coded a simple brute force to check the correctness of the second example and the result seems wrong.Input: 1000000 2Output: fca2cMy function: ll count() { ll ans = 0; char buf[10]; rp(i,1,0xfca2c) { // my rp macro is inclusive for both ends int cnt[16] = {}; sprintf(buf,"%x",i); bool add = true; rp(j,0,strlen(buf)-1) { cnt[fromhex(buf[j])]++; if (cnt[fromhex(buf[j])] > t) { add = false; break; } } if (add) ans++; } return ans; } It returns 931720, which is less than 1000000.I'd be thankful if someone could explain me the problem statement.UPD: Nevermind, my fromhex function had a bug...
 » 3 years ago, # | ← Rev. 2 →   0 For D, i think it is not necessary to use set to do thatfirst of all, we ignore the first consecutive and the last consecutive segments.then we gain all the segments which are only consist of non-negative numberswe sort the segments by their length (the same as the solution)so we just keep picking from smaller one to large onefinally, for the first consecutive part, it doesn't impact the answer, so we ignore it.for the last consecutive part, if it is consist of non-negative number, we should ensure whether we can use the left k tires to pass it, if we can, the answer should minus 1. if it is consist of negative number, we should let answer minus 1 (because u don't need to change at the end of the sequence)for more infor, here is my code : http://codeforces.com/contest/747/submission/23391692
 » 3 years ago, # |   0 In problem C — SERVERSMY CODE uses the same approach described in the editorial, but it gives an error of TLE on test 8.I can't seem to figure out the reason for this as my solution is order n * q (number of servers times number of queries)Can anyone please help me put with what's happening?Thankyou :)