Official
B - 行儀のよい列 / Polite Queue Editorial by admin
swe-2-highWe need to count positions where a child C is immediately followed by an adult A. In other words, count occurrences of the adjacent pair CA in \(S\). The program checks every pair \(S[i]\) and \(S[i+1]\) from left to right and increments the answer exactly when it is CA. Since \(i\) ranges from \(0\) to \(N-2\), every relevant boundary is checked exactly once without accessing outside the string. The time complexity is \(O(N)\), and the space complexity is \(O(N)\) for storing the input string.
posted:
last update: