Available tutorials:

Tutorial for new (and not only new) users
Tutorial for problem-setters
Tutorial for problem-setters (interactive problems)
Tutorial for contest-setters


Tutorial for problem-setters
(interactive problems)

This is tutorial about creating interactive problems. It is advisable to read tutorials for users and problem-setters first.


Content:

What are interactive problems?

Dictionary

Edit problem panel

Judge

Time limits

Buffering

Restrictions for the user

Restriction for the problem-setter

Sample interactive problems


What are interactive problems?

Interactive problems give possibility - as the name says :) - to interact with the judge, i.e. talk with it, by using STDIN and STDOUT.


Dictionary

  • judge - judge program
  • tested - tested program (submitted by a user)


Edit problem panel

To create interactive problem, in the edit problem panel set Problem type option to interactive.


Judge

There is spoj_interactive.h file available that contains the spoj's basic constants and functions.

Judge can return AC, WA, SE, CE, RE, TLE, MLE, EOF as a result. The EOF result is displayed like WA with the difference that it yields to the tested runtime errors.

Example judge:

#include "spoj_interactive.h"

int main()
{
    spoj_init();                       // always at the beginning

    fscanf(spoj_p_in, "...", ...);     // reading input for the problem
    fscanf(spoj_p_out, "...", ...);    // reading output for the problem

    fprintf(spoj_p_info, "...", ...);  // outputting information that is only available for ps
    fprintf(spoj_u_info, "...", ...);  // outputting information that is only available for the user

    spoj_printf("%d", 5);              // using macro to print data for tested
                                       // in case tested ended -> EOF

    spoj_scanf("%d", &x);              // using macro to get data from tested
                                       // in case of wrong data -> WA
                                       // in case tested ended -> EOF

    spoj_assert(x == 5);               // condition unfulfilled -> WA

    fprintf(spoj_score, "...", ...);   // points for the test

    int len = spoj_srclen();           // length of the source code
                                       // function of one-time use

    return SPOJ_RV_AC;                 // AC
}


Time limits

Time limits are set in the same way as in case of classical problems, i.e. they are set for each test case separately.

Time limit concerns both tested and judge programs:
Real-time limit for tested = 2 * time limit + 1s.
Real-time limit for judge = 2 * time limit + 2s.


Buffering

In order to have the communication between the judge and the tested available on both sides you should clean the output buffer or set the standard output buffering for linear.

Each task should have information similar to the one written below:
Attention: the program should clear the output buffer after printing each line. It can be done using fflush(stdout) command or by setting the proper type of buffering at the beginning of the execution - setlinebuf(stdout).


Restriction for the problem-setter

The preview of the stdout is unavailable.


Sample interactive problems