estro estro - 1 month ago 10
C++ Question

Codeforces test server error, not reproducible on local machine

My code:

#include <stdlib.h>
#include <iostream>
#include <math.h>

int main(int argc, char *argv[]) {

long long n = atoi(argv[1]);
long long m = atoi(argv[2]);
long long a = atoi(argv[3]);

if (n == 0 || m == 0 || a == 0) {
std::cout << "" << 0 << std::endl;
return 0;
}

long long num_tiles = ceil(n / a) * ceil(m / a);

if (num_tiles == 0) num_tiles = 1;

std::cout << "" << num_tiles << std::endl;
return 0;
}


This produces an error ("Runtime error on test 1") on the Codeforces test servers using GNU C++ 11. I am using
g++ -std=c++11 ...
to compile my code locally, which works fine. I have also gotten the same error for all of my other solutions to problems. Any ideas?

PRP PRP
Answer

These lines are the culprit :

int main(int argc, char *argv[]) {
  long long n = atoi(argv[1]);
  long long m = atoi(argv[2]);
  long long a = atoi(argv[3]);

In Online Judges you have to take input from Standard Input (STDIN) and output to Standard Output (STDOUT).

Use any of the standard methods like scanf or cin to take your input and use printf or cout to give your output. Don't expect anything useful in argc or argv.

Have a look at this FAQ on Codeforces.

An excerpt from another famous online judge Codechef, which also applies to Codeforces.

If you use any method other than using the standard input and output streams - for example, using command line arguments, reading from a file, opening up some sort of dialog box, or otherwise - you will never be judged correct.