Java template for the Cloudflight Coding Contest (CCC). The framework handles
file discovery, input/output files and (optionally) checking solutions against the contest's HTML visualizer.
During a contest, the only things that normally change are Solver.solve(), Solver.verify() and config.xml.
- A contest runs ~4 hours and consists of sequential levels (usually 5–7). Each level extends the previous one: same story, more rules, bigger inputs. Keep the solver code reusable across levels.
- Each level comes with a statement (PDF/web page) and a zip of input files:
levelN_example.in,levelN_example.out(expected output for the example) andlevelN_1.in…levelN_5.in. Newer contests name themin_level-N_0-example.txt,out_level-N_0-example.txt(expected output) andin_level-N_1-small.txt…in_level-N_k-large.txt, often with asandbox-level-N.htmlvisualizer. Both schemes are picked up;out_*files are never treated as input. - For every
levelN_k.inan output file is uploaded to the contest platform, which answers valid/invalid immediately. All files of a level must be accepted to unlock the next level; usually the source code is uploaded as well. - Input files usually start with a count (number of test cases, or dimensions) followed by the cases. Output is usually one line per case, in later levels sometimes several lines per case.
- Later levels often accept any valid solution (paths, placements, schedules), so
levelN_example.outis then just one possible answer and a plain diff proves nothing. Some contests ship avisualizer.htmlthat validates a solution for exactly this reason. - The statement is provided by the user (PDF or pasted text). If it is missing, ask for it — do not infer the task from the input files alone.
| Path | Purpose |
|---|---|
src/main/java/solver/Solver.java |
solve() and verify() — the contest code. Do not change main or the method signatures. |
src/main/resources/config.xml |
Paths, level filter, log level, verifier settings. |
src/main/java/io/IOUtils.java |
readList (one line → list), readGrid (height lines → 2D list). Delimiter is a regex. |
src/main/java/io/IOManager.java |
Finds input files, creates output files, calls solve/verify per file. |
src/main/java/solver/SolutionVerifier.java |
Selenium/Chrome driver around the visualizer. |
input/levelN/ |
Unzipped level files. |
output/ |
<input basename>.txt per input file (a leading in_ becomes out_), plus <basename>.ver when the verifier is on. Scratch: created if missing, wiped on every run. |
solutions/ |
Only if <solutionPath> is set: a copy of every non-empty output file, in the same sub-folders as below input/ (input/contest/level1/ → solutions/contest/level1/). Never cleaned, meant to be committed. |
input/level99/ is a dummy level (sum of each line) matching the template code in Solver.java.
input/visualizer.html is a sample from CCC 41 ("Spaceship") and is unrelated to level99.
Always from the repo root (paths in config.xml are relative to the working directory):
mvn -q compile exec:java
config.xml is read from the classpath, so it only takes effect after mvn compile — the command above covers
that. Requires JDK 21 and Maven.
- Unzip the level into
input/levelN/. - Read the statement and
levelN_example.in/.out, then implementsolve(). - Set
<targetSpecificLevel>Ne</targetSpecificLevel>(example only) and run. - Compare with the expected example output:
With the newer naming both files are called
diff --strip-trailing-cr output/levelN_example.txt input/levelN/levelN_example.out
out_level-N_0-example.txt:No output means identical. If the level accepts multiple valid answers, use the visualizer instead (below).diff --strip-trailing-cr output/out_level-N_0-example.txt input/levelN/out_level-N_0-example.txt
- Set
<targetSpecificLevel>N</targetSpecificLevel>, run, and sanity-check the outputs (line count matches the number of cases, no empty files). The user uploadsoutput/levelN_*.txt.
targetSpecificLevel: N = all files of level N, Ne = only its example, e = all examples, -1 = everything.
SolutionVerifier opens the HTML in headless Chrome, puts one test case into the input textarea and its
solution into the output textarea, then reads the status element. Setup for a new contest:
-
Put the file into
input/and set<visualizerPath>. -
Find the element ids and adjust
<elementLocators>(CSS selector, or XPath if it starts with//):grep -n -o -E '<(textarea|input|span|div|strong)[^>]*id="[^"]*"' input/visualizer.htmlNeeded: input field, solution field, status element; optional: info/message element.
-
Read the validation code in the HTML's
<script>. It tells you- what the page expects as input — normally one test case, not the whole
.infile, - the status strings (
SUCCESS/FAILUREin the sample), - when validation runs. It must run on the
inputevent of the input or the solution field; a visualizer that needs a button click is not supported bySolutionVerifieras is.
This script is also the most precise spec of what counts as a valid solution — read it when the statement is ambiguous.
- what the page expects as input — normally one test case, not the whole
-
Write
verify()so that it slices the input file and the output file per test case and callsverifier.checkValidity(run, inputCase, outputCase). Multi-line cases are joined with\n:for (int run = 0; run < maxRuns; run++) { String inputCase = input.nextLine() + "\n" + input.nextLine(); String outputCase = output.nextLine() + "\n" + output.nextLine(); verifier.checkValidity(run, inputCase, outputCase); }
-
Set
<enabled>true</enabled>, run, and check the result files:grep -c "exited with SUCCESS" output/*.ver grep "exited with FAILURE" output/*.ver
Each case produces one entry
Validation run <i> exited with <status>! Additional Info: '<message>' | .... If the page sets no status within 5 s the entry saysexited with TIMEOUT, and a case whose check threw (console showsSEVERE: Visualizer failed) saysexited with ERROR. The SUCCESS count must equal the number of cases.With
<onlyFailures>true</onlyFailures>entries whose status is exactlySUCCESSare left out, so an empty.verfile means that every case is valid. List the files that still contain something:find output -name "*.ver" -size +0
Verifier limits:
- Chrome must be installed; the first run downloads a matching chromedriver (needs internet, ~8 s startup).
- The page is loaded once per input file and reused for all of its cases. Both fields are set through
JavascriptExecutorand get oneinputevent each, so the page validates twice per case regardless of the text length (CCC 41 level 8: 100 cases with 670 000 characters in ~8 s). A single validation may take up to 3 minutes before the case is aborted. - Since the page is not reloaded between cases, a visualizer that keeps state apart from the two fields can carry it over to the next case.
- Set
<headless>false</headless>to watch the visualizer while debugging.
- After
reader.nextInt()callreader.nextLine()before reading whole lines. IOUtils.readListdoes not trim: leading or double spaces produce empty tokens (NumberFormatException). Use"\\s+"as delimiter when the spacing is irregular.readGrid(reader, "", w, h, ...)splits a line into single characters.- Only
IOExceptionis caught aroundsolve(). Any other exception aborts the whole run: later files get no output, and with the verifier enabled the Chrome process stays open. <cleanupOutput>true</cleanupOutput>deletes everything insideoutputPathon every run, recursively. Never pointoutputPathat a directory with anything worth keeping; outputs that should survive go to<solutionPath>.<solutionPath>is overwritten by every run, including runs of a half-finished solver — checkgit diffbefore committing. The sub-folder is taken relative to the first folder ofinputPath.- The level filter looks for
levelN/level-N/level_Nin the file name (not the folder) and does not match longer numbers (1skipslevel10_*). The example filter is a plain substring match onexample. - Output files are named by input basename only; two inputs with the same name in different folders overwrite each other.
- Debug output:
log.fine(...)insolve()plus<logLevel>FINE</logLevel>;FINERalso lists the files found. - Sums and products in later levels overflow
intquickly — default tolong.