Hi everyone, I'm solving problem A from round #575 (div 3). It's a fairly simple problem and I'm getting the right answer when I try the example on visual studio code (using c++) but when I upload my solution, I get the third case wrong (the one with big numbers). Why can this happen?
Useful info: problem: https://codeforces.net/contest/1196/problem/A my code:
include
int main() { int n = 0; std::cin >> n;
for (int i = 0; i < n; i++) { long total = 0; long a = 0; long b = 0; long c = 0; std::cin >> a; std::cin >> b; std::cin >> c; total = a+b+c; if (int(total)%2==0) std::cout<<total/2 <<"\n"; else std::cout<<(total-1)/2 <<"\n"; } return 0;
}
example entry: 4 1 3 4 1 10 100 10000000000000000 10000000000000000 10000000000000000 23 34 45 my output on vs code (right answer): 4 55 15000000000000000 51 my output when I submit my solution: 4 55 1073741823 0
Thank you very much for your help!
Use long long instead of just long
Thank you very much! I just tried with long long and it worked.
Try
long long
instead oflong
. You can read more here. Also please add submission link instead of copy/pasting in the blog, or use the block format for your code:Using ``` before and after it (With enter).
This is because you are converting long to int. You shouldn't do that since the constraints are pretty big (10^16 — whereas max int can go is something of order 10^9) and then the long value will give just some garbage value. Also, you don't need to do that since modulo will work for longs as well. Check this solution of mine for a better and simpler implementation (You should take advantage of the truncating behaviour of C++ int division :)).
Thank you very much, but I can't see the solution you're suggesting!
Use long long instead of long. Because size of long in codeforces compiler is 4 bytes = ( 2147483648 ). try with below code.
Thank you very much!