FThiesen's blog

By FThiesen, history, 5 years ago, In English

Hi!

I have two really similar submissions to problem (https://codeforces.me/contest/1266/problem/E)

https://codeforces.me/contest/1266/submission/67209030 (**WA version**)

https://codeforces.me/contest/1266/submission/67209163 (**AC version**)

The WA version has the following line:

long long ans = accumulate( a.begin(), a.end(), 0, [] (long long a, long long b) { return a + b; } );

With this simple change on this specific line I got it accepted.

long long ans = accumulate( a.begin(), a.end(), 0ll, [] (long long a, long long b) { return a + b; } );

Why the zero of the WA version does not seem to be converted to long long?

Tags cpp
  • Vote: I like it
  • +1
  • Vote: I do not like it

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

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

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

    Thank you for the simple explanation! I missed this information when I checked out cppreference..

»
5 years ago, # |
  Vote: I like it +13 Vote: I do not like it

Accumulate(a, b, c, func) work something like this:

while(a != b){
    c = func(c, *a++);
}
accumulate( a.begin(), a.end(), 0, [] (long long a, long long b) { return a + b; } ); //return int, because third parametr int
accumulate( a.begin(), a.end(), 0ll, [] (long long a, long long b) { return a + b; } ); //return long long, because third parametr long long