Problem E12. Sudoku Through an Oracle ≡

Author:Course Instructor   Time limit:10 sec
Input / output:interactive   Memory limit:512 Mb

Statement

Fill a Sudoku of box size k: a grid of n × n cells, n = k2, split into n boxes of k × k cells. Every row, every column and every box must contain each of the numbers 1,…,n exactly once. Some cells are given.

You do not have to search for the answer yourself. The judge owns a SAT solver (an oracle) and lets your program use it: you send a formula in conjunctive normal form, the oracle says whether it is satisfiable and, in MODEL mode, returns a satisfying assignment. Translate the puzzle into a formula, ask the oracle, and translate its answer back into a filled grid. The large tests are out of reach of hand-written backtracking within the time limit; a correct encoding makes them easy for the oracle.

This is an interactive problem. After reading the test, your program prints commands (tokens separated by whitespace; a command may span several lines):

In DECISION mode the oracle answers only SAT or UNSAT, without a model, and you must still output a filled grid. Hint: forcing one more literal that keeps the formula satisfiable keeps a solution.

Clauses stay in the oracle between queries: you may add clauses after a reply and ask again.

Example (fragment, MODEL mode): two clauses over variables 1 and 2, one query, the model says x1 = 0, x2 = 1.

you:    a 1 2 0
you:    a -1 0
you:    s 0
oracle: SAT
oracle: 01
you:    ans ...

Input format

Line 1: the mode (MODEL or DECISION), the conflict budget of one query C and the maximum number of queries Q. Line 2: k. Then n lines of n integers, the grid; 0 marks an empty cell.

Output format

The commands described above, ending with ans and the filled grid. Any valid filling that keeps the given cells is accepted.

Constraints

3 ≤ k ≤ 6; every test has a solution.

At most Q queries per test and at most 3 ⋅ 107 literals in all clauses together.

Groups: warm-up (n ≤ 16, MODEL), large (n = 25,36, MODEL), decision (n ≤ 16, DECISION), decision large (n = 25, DECISION).


0.078s 0.015s 16