Skip to content

Chained Tasks

Thang Pham edited this page Apr 19, 2020 · 2 revisions

This guide will help you go through the process of creating a chained task in kjudge!

Download the sample problem

This guide uses a simple problem called Broken Bit to illustrates the process of preparing a chained task in kjudge.

Given an integer N <= 10^9, you need to implement two functions:

  1. string encode(N) encodes the integer N and return a decoded string S.
  2. int decode(string S) decodes the string S and return an integer N.

The string S can only contain 0 or 1. Its size must be less than or equal 90. It is guaranteed that when you encode N and return S, one position of S will be flipped before the decode function is called.

Two functions are run independently by the grader.

You can download the sample problem files and tests here.

After extracting the .zip file, BrokenBit folder will look like this:

Broken Bit files

Add problem to kjudge

First, you need to create a problem in kjudge. In this guide, a problem named Broken Bit is added to the Weighted contest in kjudge's test database:

Broken Bit create problem

Then, you can add Broken Bit's tests:

Broken Bit tests 1

Broken Bit tests 2

Broken Bit tests 3

Add a build script

In the next step, you need to add a customized build script for the problem.

In Broken Bit, there is only a build script for C++: compile_cc.sh, which compiles contestant's solution (code.cc) with the problem's grader file (grader.cpp).

You can upload the files (grader.cpp, broken_bit.h and compile_cc.sh) that the problem requires to compile and run contestant's solution to kjudge:

Broken Bit upload build script

For more details about writing a custom compiler, refer to Custom Compilers.

Add a checker file

To compare and score contestant's solution with the expected output, you need to add a checker file.

In BrokenBit folder, there is a file called compare.cpp that checks and scores contestant's output.

You can upload compare.cpp and compile the file in kjudge.

Note: kjudge follows CMS's checker styleand it requires a binary file named compare for a checker file. Users can upload a file named compare.[language]( language is one of the supported languages) and compile it direcly in the kjudge system.

Broken bit checker file

For more details about writing a custom checker, refer to CMS's checker style and Custom diffs

Add .stages file

Finally, you need to add a .stages file that contains a list of arguments passed to the binary file when running contestant's solution.

The number of times the binary file is run is equal to the number of lines in .stages.

Each line of .stages is the arguments passed to the binary for a single run.

  1. In a single run, the binary file will receive input from standard input and return output to standard output.
  2. After a single run, the next input for the next run is the output of the previous run.
  3. The input for the first run is the problem's test input.
  4. The output for the last run is contestant's output, which will be checked again the problem's expected output by using a custom checker or the default diff checker.

In Broken Bit, the grader will run contestant's implementation of encode and decode independently in two separate stages.

the grader (grader.cpp) file:

Broken bit grader

and the .stages file:

Broken bit .stages file

You can upload .stages file to kjudge:

Broken bit stages

In kjudge, the necessary files for Broken Bit will look like this:

Broken bit files 2

The end

You have finished all the steps needed to prepare a chained task in kjudge.

To test whether you follow all steps correctly, you can try to submit the solution file sol.cpp in the BrokenBit folder.

Broken bit submit

Broken bit result

Now you can add your own chained task to kjudge!