P1013 [NOIP 1998 Senior] Positional Addition Table
Description
To check students’ understanding of positional numeral systems, the famous scientist Lu Si gave the following addition table, where letters represent digits. For example:
$$
\def\arraystretch{2}
\begin{array}{c||c|c|c|c}
\rm + & \kern{.5cm} \rm \mathclap{L} \kern{.5cm} & \kern{.5cm} \rm \mathclap{K} \kern{.5cm} & \kern{.5cm} \rm \mathclap{V} \kern{.5cm} & \kern{.5cm} \rm \mathclap{E} \kern{.5cm} \\ \hline\hline
\rm L & \rm L & \rm K & \rm V & \rm E \\ \hline
\rm K & \rm K & \rm V & \rm E & \rm \mathclap{KL} \\ \hline
\rm V & \rm V & \rm E & \rm \mathclap{KL} & \rm \mathclap{KK} \\ \hline
\rm E & \rm E & \rm \mathclap{KL} & \rm \mathclap{KK} & \rm \mathclap{KV} \\
\end{array}$$
Its meaning is:
$L+L=L$,$L+K=K$,$L+V=V$,$L+E=E$
$K+L=K$,$K+K=V$,$K+V=E$,$K+E=KL$
$\cdots$
$E+E=KV$
From these rules, we can deduce: $L=0$,$K=1$,$V=2$,$E=3$.
We can also determine that the table represents base $4$ addition.
Input Format
The first line contains an integer $n$ ($3 \le n \le 9$) representing the number of rows.
The following $n$ lines each contain $n$ strings separated by spaces.
Let $s_{i,j}$ denote the string in row $i$ and column $j$. The testdata guarantees $s_{1,1}=\texttt{+}$, $s_{i,1}=s_{1,i}$, $|s_{i,1}|=1$, and $s_{i,1} \ne s_{j,1}$ ($i \ne j$).
It is guaranteed that there is at most one solution.
Output Format
On the first line, output which number each letter represents, in the format like: `L=0 K=1` $\cdots$ sorted in the given letter order. Different letters must represent different digits.
On the second line, output the base of the addition.
If it is impossible to form a valid addition table, output `ERROR!`.
Explanation/Hint
NOIP 1998 Senior Problem 3.
Translated by ChatGPT 5