Official

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

gpt-6-astra-medium

Overview

Convert the number of pins knocked down in each throw into a character according to the specified rules. Then, concatenate the converted characters in the order of the throws and output the result.

Analysis

The record for each throw is determined solely by the number of pins knocked down in that throw. There is no need to consider the results of previous or subsequent throws.

Therefore, a straightforward approach that converts each \(A_i\) as follows is sufficient:

  • If \(A_i = 10\), convert to X.
  • If \(A_i = 0\), convert to -.
  • Otherwise, convert to the digit representing \(A_i\).

For example, if the number of knocked-down pins is \([10, 0, 3, 9, 10]\), the output will be X-39X.

Since this method only processes the \(N\) values once, there is no risk of TLE (Time Limit Exceeded). However, simply printing the counts directly would output 10 for \(10\) and 0 for \(0\), which differs from the required symbols and leads to WA (Wrong Answer). Also, be careful not to include spaces between characters.

Algorithm

  1. Read \(N\) and the array \(A\).
  2. Initialize an empty list out to store the characters.
  3. Iterate through the array \(A\) from the beginning, and for each value v, perform the following:
    • If v == 10, append X to out.
    • If v == 0, append - to out.
    • Otherwise, append str(v) to out.
  4. Concatenate the characters without spaces using "".join(out) and print the result.

Since we append the specified character one by one for each throw without changing their order, we obtain the desired string of length \(N\).

Complexity

  • Time Complexity: \(O(N)\)
    Converting each value and concatenating the final string each take \(O(N)\) time.
  • Space Complexity: \(O(N)\)
    We use space for the input array and the list storing the characters for the output.

Implementation Notes

  • str(v) converts an integer into a string. Since we concatenate using join, we must add strings to the list.

  • By handling \(10\) and \(0\) first with conditional statements, the remaining values are guaranteed to be from \(1\) to \(9\), allowing them to be directly converted into single-digit characters.

  • "".join(out) concatenates the elements without any delimiter. Note that using " ".join(out) would introduce unwanted spaces.

    Source Code

# 問題文から独立に実装
n = int(input())
a = list(map(int, input().split()))
out = []
for v in a:
    if v == 10:
        out.append('X')
    elif v == 0:
        out.append('-')
    else:
        out.append(str(v))
print("".join(out))

This editorial was generated by gpt-6-astra-medium.

posted:
last update: