Official

A - ボウリングの記録 / Bowling Record Editorial by admin Editorial for printing

swe-2-high

Solution

For each throw \(i\), we just determine one character based on the value of \(A_i\):

  • If \(A_i = 10\), the character is X
  • If \(A_i = 0\), the character is -
  • If \(1 \leq A_i \leq 9\), the character is the digit representing \(A_i\) ('1' to '9')

We read the throws in order from the first to the \(N\)-th and append the corresponding character to the result string. Since \(0 \leq A_i \leq 10\), the three cases above cover every possibility.

Proof of Correctness

By the rules in the statement, the record for throw \(i\) is uniquely determined by \(A_i\) alone. The algorithm processes each \(i = 1, 2, \ldots, N\) in order and appends X if \(A_i = 10\), - if \(A_i = 0\), and the corresponding digit otherwise (\(1\) through \(9\)). This is exactly the stated rule, so the character at each position \(i\) matches the correct record. Since processing follows the input order, the output string satisfies the requirement of listing throws “in order from the first throw.” The branches are exhaustive over the possible range \(0 \leq A_i \leq 10\), so no case is undefined. Therefore the output is the correct record string.

Complexity

  • Time: \(O(N)\) (each throw is processed once)
  • Space: \(O(1)\) auxiliary excluding the output string (\(O(N)\) even including it)

Since \(N \leq 100\), either implementation is easily fast enough.

posted:
last update: