Weighted mixed-tile tilings of a board with holes
/app/cpu/main.cpp is the source of a multicore CPU program (C++17, OpenMP).
The program takes one input-file path (PROGRAM INPUT_FILE) and writes its result to stdout.
What the program computes
A board of H rows and W columns has holes: cell c = r*W + col is a hole when
mix64(seed ^ (c*0xC2B2AE3D27D4EB4F + 0x165667B19E3779F9)) mod 1000 < RHO. Every
non-hole cell must be covered by exactly one tile, tiles may not cover holes or leave the
board, and the 9 tile types have weights w0..w8 (weight 0 disables a type). A tile is
anchored at its first cell in row-major order; its cells relative to the anchor (dr, dc):
| k | tile | cells |
|---|---|---|
| 0 | monomino | (0,0) |
| 1 | horizontal domino | (0,0) (0,1) |
| 2 | vertical domino | (0,0) (1,0) |
| 3 | L | (0,0) (0,1) (1,0) |
| 4 | L | (0,0) (0,1) (1,1) |
| 5 | L | (0,0) (1,0) (1,1) |
| 6 | L | (0,0) (1,-1) (1,0) |
| 7 | horizontal I-tromino | (0,0) (0,1) (0,2) |
| 8 | vertical I-tromino | (0,0) (1,0) (2,0) |
The weight of a tiling is the product of its tile weights. The program computes the sum
of the weights of all tilings modulo the prime P with a cell-by-cell broken-profile DP
whose state is the occupancy bitmask of the 2W cells starting at the current cell
(bit j = cell idx + j; holes count as occupied), i.e. 4^W states.
Input format
W H P RHO SEED
w0 w1 w2 w3 w4 w5 w6 w7 w8
Output format
W=<W> H=<H> P=<P> holes=<number of holes> states=<4^W>
row <r> sum <S> hash <X> (one line per checkpoint row)
tilings <T>
Checkpoint rows are floor((j+1)*H/8) - 1 for j = 0..7 plus H-1, each once, in
increasing order. After finishing row r the window starts at cell (r+1)*W;
S is the sum of all window-state values modulo P and X is the sum over all states
i of mix64((i << 32) | value[i]) modulo 2^64 (values in [0, P)). T is the total
weight of complete tilings (the value of the empty window after the last cell).
Hidden inputs
1 <= W <= 11,1 <= H <= 2000,0 <= RHO <= 1000, weights in[0, P)with at least two non-zero.Pis a prime with2 <= P < 2^30(small primes appear in correctness inputs).- Correctness inputs include
1x1and one-column boards, single tile families (dominoes only, L-trominoes only, I-trominoes only), an all-hole board, andW = 10, 11with few rows. - The timing input has
Win {10, 11},RHOin[20, 100], each weight zero with probability 0.15, andHchosen so thatH * W * 4^W * (2 + enabled tiles)is about 9e10 (roughly 200 to 900 rows).
Your task
Port this program to CUDA in /app/gpu/main.cu: same command line (PROGRAM INPUT_FILE),
same output on stdout. Then make it as fast as you can on the GPU while keeping the output correct.
The main computation must execute on the GPU. Renaming CPU code to .cu, running a
CPU fallback, or launching a dummy kernel while computing the answer on the CPU does not satisfy this task.
The CPU source is the specification: when this text and the code disagree, the code wins.
This sandbox is for source generation only. Write /app/gpu/main.cu; compilation,
execution and verification are performed later in a separate verifier environment.
How you are scored
- Only
/app/gpu/main.cuis collected. It is compiled withnvcc -O3 -arch=sm_90 -std=c++17 -o port /app/gpu/main.cu; no extra libraries are linked. The CUDA runtime and the header-only libraries that ship with the CUDA toolkit (CUB, Thrust, libcu++) are allowed. - Your source must not contain any of:
system(,popen(,fork(,exec*,dlopen(,getenv(,#include <filesystem>,/tests/,/proc/. The program may read only the input file it is given. - GPU verification uses the backend selected for this run: an H100 attached to the separate verifier, or a remote H100 worker. Hidden inputs use a fresh random seed.
- Correctness: every hidden input (small edge cases plus the timing input) must pass. Your output must be identical to the CPU program's output (trailing whitespace ignored). Any mismatch, crash or timeout gives reward 0.
- GPU execution: a separate, untimed CUPTI check must observe completed GPU kernel activity on the hidden timing input. A CPU-only submission receives reward 0 even if its output is correct.
- Speed: The timing input has W in {10, 11} (1M or 4M states) and a few hundred rows, about 9e10 state-tile visits. Your port and our GPU reference are each run on it
once to warm up and then 5 times, interleaved; the time is the wall clock of the whole process
(including CUDA initialisation, input parsing and output). When correct,
reward = min(2, t_reference / t_yours)using the medians. /app/inputs/holds public input examples for understanding the input format.