公式

A - 錬金術の材料 / Alchemy Materials 解説 by admin 印刷ページ

swe-2-high

Scan the string \(S\) from left to right and add each character’s score to a running total: 3 points for G, 2 for S, and 1 for C. Since every character is one of these three, a simple conditional covers all cases. The program directly sums the values exactly as defined in the statement, so correctness is immediate. Each character is examined once, so the time complexity is \(O(N)\). Storing the input string takes \(O(N)\) space, and only one counter variable is needed beyond that, i.e. \(O(1)\) extra space.

投稿日時:
最終更新: