Блог пользователя Whitewiz

Автор Whitewiz, история, 3 месяца назад, По-английски

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://codeforces.net/contest/1985/submission/265437274) ,(https://codeforces.net/contest/1985/submission/265439252)

Hacked — (https://codeforces.net/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.

  • Проголосовать: нравится
  • +3
  • Проголосовать: не нравится

»
3 месяца назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

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

»
3 месяца назад, # |
Rev. 2   Проголосовать: нравится +12 Проголосовать: не нравится

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);
»
3 месяца назад, # |
  Проголосовать: нравится +5 Проголосовать: не нравится

You have to use it like this:

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

You missed the 0LL.

»
3 месяца назад, # |
Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

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

  • »
    »
    3 месяца назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    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.

»
3 месяца назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

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