Created
February 8, 2026 07:41
-
-
Save maehrm/4182308d43a79ad36073798f941ee8a5 to your computer and use it in GitHub Desktop.
D - Alter Altar https://atcoder.jp/contests/abc174/tasks/abc174_d
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| N = int(input()) | |
| S = input() | |
| prefixW = [0] * (N + 1) # iまでの白の個数 | |
| totalW = 0 # 全体で白が何個あるか | |
| for i in range(N): | |
| prefixW[i + 1] = prefixW[i] | |
| if S[i] == 'W': | |
| prefixW[i + 1] += 1 | |
| totalW += 1 | |
| ans = N | |
| for i in range(N + 1): | |
| leftW = prefixW[i] | |
| rightR = (N - i) - (totalW - leftW) | |
| ans = min(ans, max(leftW, rightR)) | |
| print(ans) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment