#P3186. Decipher Solomon's Treasure

    ID: 16443 Type: Default 1000ms 256MiB

Decipher Solomon's Treasure

Decipher Solomon's Treasure

Solomon's treasure is sealed by a powerful spell and the key to open it is hidden in the massive Solomon Square. The square is paved with 1-meter square marble plates. At each stormy dawn, due to Solomon’s magic, every plate emits a faint light. Those plates whose brightness is greater than a given threshold, when viewed together in reading order (from left to right, top to bottom), reveal the spell to open the treasure.

The spell is a string of length less than 10, composed of symbols from the set {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, D, E, L, X}. For each valid marble plate (i.e. those with brightness greater than the threshold), its brightness value b is converted into a symbol via the mapping:

\( s = f(b) = mapping[b \bmod 15] \)

where the mapping is defined as follows:

  • 0: "0"
  • 1: "1"
  • 2: "2"
  • 3: "3"
  • 4: "4"
  • 5: "5"
  • 6: "6"
  • 7: "7"
  • 8: "8"
  • 9: "9"
  • 10: "A"
  • 11: "D"
  • 12: "E"
  • 13: "L"
  • 14: "X"

You are given the brightness values of the plates in Solomon Square along with the threshold. Your task is to read the grid in row-major order, select those plates with brightness strictly greater than the given threshold, convert each valid plate's brightness into its corresponding symbol using the above mapping, and finally output the concatenation of these symbols as the secret spell. You can assume that the number of valid plates will be less than 10.

inputFormat

The first line contains two integers R and C, representing the number of rows and columns of the square (1 ≤ R, C ≤ 100).

The next R lines each contain C integers, each between 0 and 255, representing the brightness values of the marble plates.

The last line contains an integer T (0 ≤ T ≤ 255), the brightness threshold. Only boards with brightness strictly greater than T are considered valid.

outputFormat

Output a single line containing the spell — the concatenated string of symbols for each valid marble plate in reading order. The length of the string will be less than 10.

sample

2 2
10 20
30 40
15
50A