Please subscribe to the official Codeforces channel in Telegram via the link https://t.me/codeforces_official. ×

### cgy4ever's blog

By cgy4ever, history, 5 years ago, As Errichto suggested here, I will post date/time of upcoming SRMs once I know, and will update it about 24 hours before the contest so it will be in the "Recent Actions" list.

SRM 702 will start on Nov 14 at 9pm EST. Note that Daylight Saving Time will end on Nov 6.

This is the last SRM before Topcoder Open 2016, so please come and compete if you want to practice once more. :)

Update: the contest will start in less than 1.5 hours. Comments (18)
 » Update: SRM 702 will start in 24 hours.
 » Woke up at 5:00 A connection to the server could not be established Will be fun to get this on TCO.
•  » » I'm sorry, looks like my internet provider blocks arena :(
 » How to Solve div2 1000 points problem?
•  » » What I did is as follows :Made a recursive function with memorization (Dynamic Programming), which will return expected value given a subset of block (call it mask) and the face vector.For each subset I calculated the result when a particular faces comes up with probability equal to 1/face.size() and for this face removed a subset, which sums to the number on this face, from mask, which will be most favorable (meaning which enable us create most of the numbers on the faces after removing the face).I am NOT passing all testcases with this approach. Passing 6 out 7 given test cases.Can anyone please explain where I am going wrong ?Here is my code if you would like to have a look : #include #include #include #include #include using namespace std; int test = 0; class SubsetSumExtreme{ public : int subset; int perms; double dp; double getExpectation(vector block, vector face, int mask){ if(dp[mask]!=-1.0) return dp[mask]; double ans = 0.0; double n = (double)(face.size()); int len_block = block.size(); for(auto f : face){ map < int, vector > mp; for(int i = 0; i<(1<second){ ans += getExpectation(block,face,mask-p)/n/mp.rbegin()->second.size(); } }else{ double z = 0.0; for(int i = 0; i<(len_block); i++){ if(mask & (1< block, vector face){ sort(face.begin(),face.end()); sort(block.begin(),block.end()); int len_block = block.size(); for(int i = 0; i<(1<
•  » » I didn't understand the problem , didn't get the part about finding the minimum expected score . Can someone explain why the answer for {1,2,1} , {1,2} is 0.5 ?
•  » » 5 years ago, # ^ | ← Rev. 3 →   First, let's binary search for answer. So problem reduces to finding if there exists a happy sublist with length at least m and value k.For each number, we can compute the closest index on the left that has absolute value at most k, and the closest index on the right that has absolute value at most k.For example, if the list is equal to [8,1,10,2,9,7], and k=2, then left = [-1,-1,0,1,2,4], and right = [2,3,4,6,5,6]. This is a pretty standard problem and can be solved using some binary indexed trees and takes O(n log n) time.Now, consider the following pseudocode to check if all sublists are not happy: def all_bad(s, e): if e-s <= m: # all subarrays are too short, so they are all bad return true find an index i such that left[i] < s and right[i] > e if no index exists: # all numbers are not lonely if we take the entire subarray return false # any subarray that contains index i will be bad, so we just need to check the two cases below. return all_bad(s, i-1) and all_bad(i+1, e) This is correct, but it is too slow. In particular, the line for finding the index is too slow if we try the straightforward loop from s to e. Instead, let's just scan from both ends simultaneously. This now becomes O(n log n) (basic idea is the recurrence is now T(n) = T(a) + T(b) + min(a,b)).Overall time complexity is O(n log^2 n).