Official

B - 変わらなかった時間 / Steady Hours Editorial by admin Editorial for printing

swe-2-high

Whether the light’s state at hour \(i\) (\(i \geq 2\)) matched the previous hour is determined by checking if the \(i\)-th and \((i-1)\)-th characters of \(S\) are equal; in 0-indexed terms, s[i] == s[i - 1]. The program performs this comparison for \(i = 1\) through \(n - 1\) and counts how many times it holds. Each adjacent pair is examined exactly once, so nothing is missed or double-counted. The loop runs \(N - 1\) times, giving \(O(N)\) time, and storing the string \(S\) takes \(O(N)\) space.

posted:
last update: