Last active
January 7, 2020 11:07
-
-
Save Chgtaxihe/3b2b8526c76d320424d5eb64f939f405 to your computer and use it in GitHub Desktop.
Codeforces 1238 #Codeforces
This file contains 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
def main(): | |
n = int(input()) | |
s = input() | |
ret = n * (n - 1) // 2 | |
for x in range(2): # 正着来一遍,反着来一遍 | |
cur = 1 | |
for i in range(1, n): | |
if s[i-1] == s[i]: | |
cur += 1 | |
else: | |
ret -= cur - x # AAB (rev)--> BAA 有重复计算 | |
cur = 1 | |
s = s[::-1] | |
return ret | |
print(main()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment