Created
March 12, 2026 11:02
-
-
Save maehrm/89ebf8e307a6b1ddb6cc90f3dd8da070 to your computer and use it in GitHub Desktop.
D - XNOR Operation https://atcoder.jp/contests/abc418/tasks/abc418_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()) | |
| T = input() | |
| # dp[r][0] : 0が偶数個(結果が1になる) | |
| # dp[r][1] : 0が奇数個(結果が0になる) | |
| dp = [[0] * 2 for _ in range(N + 1)] | |
| for r in range(1, N + 1): | |
| if T[r - 1] == "0": | |
| dp[r][0] = dp[r - 1][1] | |
| dp[r][1] = dp[r - 1][0] + 1 # 自分自身の分を+1 | |
| else: | |
| dp[r][0] = dp[r - 1][0] + 1 | |
| dp[r][1] = dp[r - 1][1] | |
| ans = 0 | |
| for r in range(1, N + 1): | |
| ans += dp[r][0] | |
| print(ans) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment