The SPOJ System
Submitted solutions are automatically compiled and run under Linux test system.
You must keep strictly the input output specification.
In particular your program must not printout any additional messages like 'input the number please',
which are not specified in the problem formulation.
Compilers
Submitted solutions are compiled according to the user selection made during the submission process.
For example:
-
gcc 4.0.0-8
(with standard library) for C language.
-
g++ 4.0.0-8
(with Standard Template Library) for C++ language.
-
fpc 2.0.4
(with standard library end Delphi extension for FreePascal) for Pascal language.
-
j2se jdk 5.0 with standard library (excluding some multimedia, network and system interaction classes).
Starting point for Java programs is public
static void main (String[] a) method in Main class, which must be defined.
-
other compilers are accessible depending on chosen programming language:
C 99strict, D, C#, Nemerle, Haskell, O'Caml, Prolog, Scheme, Lips, Clips, Icon, Whitespace, Fortran, Smalltalk,
Ada95, Assembler (Nasm), Intercal, Php, Pike, Ruby, Perl, Brainf**k.
Source code length restriction
Source code length is restricted to 50 000 bytes in a one file.
Additional restrictions might be provided for particular problems.
Using external libraries or files is prohibited.
Execution time restriction
Execution time is restricted for each problem and for each test case separately.
In each case restriction is not severer then 1s. Solutions are tested on equal PIII 733 MHZ processors.
Memory restriction
Accessible memory is at least 64MB.
Input Output
Program should read from standard input and write into standard output.
There is no need to read all data first, compute them all and then print all output.
It is recommended to read and write data as simultaneously.
Technically, server redirects standard stream to files.
You can test you programs in the same way at home.
Example
Task: write the program for sum two integers. On input two integers A and B. On output sum of these integers.
Input example:
2
3
Output example:
5
Solution in C:
#include <stdio.h>
int main()
{
int a, b;
scanf("%d %d", &a, &b);
printf("%d\n",a+b);
return 0;
}
Solution in PASCAL:
program ex;
var a, b: integer;
begin
read(a,b);
writeln(a+b);
end.
Solution in Java:
public class Main
{
public static void main (String[] args) throws java.lang.Exception
{
java.io.BufferedReader r = new java.io.BufferedReader
(new java.io.InputStreamReader (System.in));
int a=Integer.parseInt(r.readLine()),
b=Integer.parseInt(r.readLine());
System.out.println(a+b);
}
}
Solution submitting
The only way to submit a solution is through http://hs.spoj.pl/.
You can submit multiple solutions to each problem.
Score for the problem is equal to the score of the best submitted solution.
To submit a solution choose problem from list of problems and press button 'Submit'
at the top of the problem description.
To see the Statistic for problem choose problem from list of problems and press button 'All submissions' at the top of the problem description.
At present for SPOJ available next status codes:
Status codes on spoj:
AC - accepted - your program ran successfully and gave a correct answer
(for particular problems you can find a number describing the quality of the solution).
WA - wrong answer - your program ran successfully, but gave an incorrect answer
TLE - time limit exceeded - your program was compiled successfully, but it didn't stop before time limit.
CE - compilation error - your program couldn't be compiled; compiler's errors can be seen from www and are sent via mail if your preferences say so; note: only some languages can give CE, syntax errors in
interpreted languages can lead to WA (Python - no pre-checking syntax or Perl - CE only after a basic syntax check).
RE - runtime error - your program was compiled successfully, but it exited with an error; possible codes are:
SIGSEGV(signal 11) - most common, 'segmentation fault';
- SIGXFSZ (signal 25) - 'output limit exceeded';
- SIGFPE (signal 8) - 'floating point error' - like division by zero, etc.;
- SIGABRT (signal 6) - raised by the program itself; In C and C++ macro assert does it while fails,
also C++ STL does it under some conditions;
- NZEC (non-zero exit code) - helps telling crash from WA with interpreted languages;
- other - there are other signals which can cause program to terminate, all remaining are shown as other.
Technical issues related to C/C++
Debugging at home
You could use symbolic constant ONLINE_JUDGE for debugging purpose. In C you can use:
#ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif
Input data are taken from
input.txt, and output data are print to
output.txt only outside the SPOJ system.
Technical issues related to other OS system users
New line encoding
Please consider it important that a new line characters can differ between Linux and other OS.
It might be a cause of malicious bugs.
Using 64-bit number types
If you use a compiler in which a long long type does not exist (like MS VisualC++) then
to assure proper compilation you can create a symbolic constant:
#define __int64 long long
In this case do not forget about proper output format:
%lld instead of %I64d in the case of using scanf/printf functions.
Further reading