Whitewiz's blog

By Whitewiz, history, 5 months ago, In English

I used accumulate for calculating the sum of elements of the array(which got hacked) however simply calculating the sum via iteration gives the correct result.

Am i missing something or is there any problem with using this "accumulate" thing.

Accepted — (https://mirror.codeforces.com/contest/1985/submission/265437274) ,(https://mirror.codeforces.com/contest/1985/submission/265439252)

Hacked — (https://mirror.codeforces.com/contest/1985/submission/265303752)

update — this idea of using all the attacks at once (at 1st second) requires to calculate the sum of the array ,but this sum can overflow (long long is insufficient). Better idea is to use the ceil division in the check function like this :

tot += ((have + cool[i] — 1)/cool[i]) * attack[i]; Hacker of the above solution helped me figure this out. Thanks a lot sammyuri sir.

  • Vote: I like it
  • +3
  • Vote: I do not like it

»
5 months ago, # |
  Vote: I like it 0 Vote: I do not like it

Auto comment: topic has been updated by Whitewiz (previous revision, new revision, compare).

»
5 months ago, # |
Rev. 2   Vote: I like it +12 Vote: I do not like it

It will overflow due to 0 not being a long long, You should use

long long sum = accumulate(array.begin(), array.end(), 0ll); 

instead of

long long sum = accumulate(array.begin(), array.end(), 0);
»
5 months ago, # |
  Vote: I like it +5 Vote: I do not like it

You have to use it like this:

long long int sum = accumulate(arr.begin(), arr.end(), 0LL);

You missed the 0LL.

»
5 months ago, # |
Rev. 2   Vote: I like it 0 Vote: I do not like it

in the binary search part of this question why the submission using the upper limit as greater than 1e13 got hacked??

  • »
    »
    5 months ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    because if number of attacks are too large then the accumulated sum (total damage calculated in binary search) in could overflow if expected number of turns is greater than 1e13.

»
5 months ago, # |
  Vote: I like it 0 Vote: I do not like it

Auto comment: topic has been updated by Whitewiz (previous revision, new revision, compare).