You start out by finding a suitable problem to solve. Then you write code to solve the problem. After this, you submit the code to us for review. We will then compile your code and run it on some secret input. After some careful deliberation, you will get a judgement informing you whether your code behaved as expected or not.
Your program should read its input from standard input and produce output on standard output. This can for instance be done using cin / cout. Anything written on standard error (cerr) will be ignored. This can be used for debugging your program during development (i.e., you do not have to remove debug output before submitting if you use standard error for debug output). Of course, writing to standard error will take some runtime.
Input will always follow the input specification (so you do not need to validate the input). Your output must follow the output specification.
For C++, we use gcc version g++ (Ubuntu 8.3.0-6ubuntu1) 8.3.0 with the following flags: -g -O2 -std=gnu++17 -static {files}.
You are allowed to use all standard libraries included with C++.
We are currently using Dell PowerEdge R230 servers for judging. These are equipped with an Intel Xeon E3-1220V6 CPU running at 3.0 GHz and 8 GB RAM. A 64-bit Linux kernel is used.
We will inspect the exit code of your program. If it is non-zero, we will judge your submission as Run Time Error.
Now lets get down to business and write some code. The short tutorial below goes through the solution of A Different Problem.
You are tasked with writing a program that computes the difference between integers. Sounds simple, doesn't it? Well, as we will see, the problem still holds some small difficulties.
One thing to note is that the integers can be fairly large, as large as 1015, which is a lot larger than the maximum value of an int (which is 231−1). Luckily, there is a 64 bit integer type in C++, long long.
Now that we have determined a suitable type, we just have to read the data. Reading is done from standard input. In this problem, we should read until the end of the file (in other problems, there might be an integer at the beginning of the input, specifying how much to read, or there might be a special indicator denoting that there is nothing more to read). Using cin, this can be done as below:
Now that we've read the input, it's time to actually solve the problem. Since 0 ≤ a, b ≤ 1015, we have that −(1015) ≤ a−b ≤ 1015, which means that there is no danger of overflow involved in just subtracting the two numbers a and b. Then, we can just take the absolute value by using the std::abs function.
Finally, it's time to print the result. Using cout (assuming the long long variable r holds the result):
Now we are basically done, all that remains is to combine the above parts.
Here is a version of the complete solution.
The sample data provided in the problem statement is just there to help you make sure you understood what the problem asks for, and the input/output format. When you submit your solution, we will run it on an extensive set of additional test data to verify that it solves the problem correctly and efficiently.
When we run your solution, the first case(s) are always the sample case(s). If you fail on these, make sure that:
Sorry, no. We can't share the secret testdata.
The sample data is used to illustrate and clarify the problem. If you believe there is an error in the sample data, your interpretation of the problem is probably wrong. Consider if there is an alternative interpretation which matches the sample data.
No, however we allow you to submit your solution multiple times so you can test your way to the right solution.
Yes, we store your submissions. Occasionally a problem is found with one of the problems (no pun intended) or a time limit is changed (this should not happen frequently) and then we need to rejudge all submissions on that problem. We also use the code to check for plagiarism.
Please contact us and tell us about it.
If main returns a non-zero value you will get a Run Time Error. However, with a C++ compiler this should not happen as long as you (a) declare main to return int, and (b) do not explicitly return a non-zero value. If you declare main to have a non-int return type you should get a compile error. It never hurts to have an explicit return 0 at the end of main, though.
There are at least three simple things that you can do with cin and cout in order to make your I/O experience in C++ faster. Be advised though, that whatever you do, using the C stdio routines (e.g. scanf and printf) is still likely to be faster. If you have any more tips, we'd be happy to hear about it.
One problem is that the cin and cout are synchronized with the C stdio functions. In order to disable this, use ios::sync_with_stdio(false);.
Another problem is that cin and cout are tied, which means that as soon as you read from cin, cout is flushed. While this may be desirable when running a program interactively, it slows things down, especially if there are many alternating reads and writes. In order to disable this, use the command cin.tie(NULL);. Also, be aware that sync_with_stdio() resets this setting, so make sure you do things in the right order!
Third, it is good to know that the cout << endl also flushes cout. As far as we are aware of, this cannot be disabled, so if you are anticipating a lot of output, you should probably refrain from using endl, and use "\n" instead.