P3186 [HNOI2007] Solomon's Spell

Description

Solomon's treasure is sealed by a powerful spell, and only a special incantation can open it. To leave a glimmer of hope for future generations, Solomon hid the incantation needed to open the treasure within the vast Solomon Square. Solomon Square is paved with square marble slabs with side length $1$ meter. It is said that due to Solomon's magic, at every lightning-filled dawn, each marble slab emits a faint light of varying intensity. Those slabs whose brightness exceeds a certain threshold, when viewed as a whole, form the incantation to open Solomon's treasure. However, due to years of disrepair, some slabs may have incorrect brightness. Figure 1 shows an example view of Solomon Square from space during a lightning-filled dawn. According to Solomon's books, the incantation to open the treasure consists of several of the 15 characters `0`, `1`, `2`, `3`, `4`, `5`, `6`, `7`, `8`, `9`, `A`, `D`, `E`, `L`, `X`, forming a string of length less than $10$. These symbols are roughly arranged in a single line from left to right, as shown in Figure 1. The brightness of each marble slab on Solomon Square has been collected during a lightning-filled dawn. The brightness values are measured by integers from $0$ to $255$. Can you decipher the incantation that opens Solomon's treasure? ![](https://cdn.luogu.com.cn/upload/image_hosting/pko6syac.png)

Input Format

The first line contains two integers $L$ and $H$ separated by a space, where $L$ is the number of columns of marble slabs in Solomon Square, $5 \le L \le 100$, and $H$ is the number of rows, $5 \le H \le 100$. The next $H$ lines each contain $L$ integers separated by a space. Let the integer in the $i$-th line and the $j$-th column be $V_{ij}$, then $0 \le V_{ij} \le 255$.

Output Format

The first line contains a positive integer $t$, indicating the length of the incantation. The second line contains a string of length $t$, representing the recognized incantation.

Explanation/Hint

Translated by ChatGPT 5