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

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

Hello Codeforces!

I have a doubt in today contest problem A :(https://mirror.codeforces.com/contest/1557/problem/A)

I submitted solution in which I have used accumulate function to get sum of all elements of vector but it gave me WA.

And finally I got AC in which I find sum by traversing all elements.

Is there any difference in both methods to get sum of all elements of vector?

Here are the links of my both submissions :

125393659 — WA

125396830 — AC

Please help me to find out the error in code(using accumulate function).

Thanks in advance:)

UPD : Resolved

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

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

as sum can go out of range of int u should use long long and 0LL

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

From the stdlib reference

Common mistakes

If left to type inference, op operates on values of the same type as init which can result in unwanted casting of the iterator elements. For example, std::accumulate(v.begin(), v.end(), 0) likely does not give the result one wishes for when v is std::vector.

Made the same mistake today :D