Invitation to International Coding League 2018- External Rated Contest

I too had got the first observation, that its required to calculate for hard disk 1 only. Noticed the pattern too, but couldn’t formulate it in terms of code. Had the idea of binary search, but messed up.

PS: Same pattern of bits occurs in problem CodeChef: Practical coding for everyone

1 Like

you are considering floor division, while the problem requires float division.

Initial answer N/1.

change your condition to (num > 2*K) and add (num/K - 2)*freq[i] to answer. Handle fractions instead of taking floor division.

I have used double k to do float division.I understand your logic,But what is wrong with my logic.
My idea is to either choose letter or convert to number.
The cost of one letter is 1 and cost of one number is (-1)+(num/k),so my condition is num/k - 1(cost of number) > 1(cost of one letter) then convert to number else add 1 to sum

Yes we can, though there is a small problem with your solution, the constraints state that ‘A[i][j]’ can also be ‘0’ since 0 doesn’t count towards the score, its frequency doesn’t matter, but you are considering that in your solution. A small change in the last loop of your solution to ignore the frequency of zero gets an ac. CodeChef: Practical coding for everyone

1 Like

@garrykevin, you are using float arithmetic here which is causing the issue, consider the following testcase where k is 3 and the string is ‘j’. since replacing j with 10 gives us benefit we should replace it. Now your solution stores it in rsum in the form 2.333333333 (assuming precision of 9 digits) when you convert it back it converts back to 2333333333/1000000000 though the precise answer should be 7/3 (as the actual value is 2.33 repeating). You are loosing precision while storing it as double. Instead store integer numerator and denominators separately.

Can anyone explain this line “For the substring which contain “x” in the middle we can visualise them as 2 parts, left and right and their mask being the “OR” of the left and right mask. Thus doing this OR convolution of the left and right masks in naive manner i.e. O(ALPHA**2) we can find their contribution too.”,what does convolution means here and what is ALPHA?any help or reference to any tutorial for learnig such concepts is welcomed.

Thanx in advance!!

1 Like

thanks mate.

Thanx a lot!!