Skip to content

Instantly share code, notes, and snippets.

@Chgtaxihe
Last active January 7, 2020 11:07
Show Gist options
  • Save Chgtaxihe/3b2b8526c76d320424d5eb64f939f405 to your computer and use it in GitHub Desktop.
Save Chgtaxihe/3b2b8526c76d320424d5eb64f939f405 to your computer and use it in GitHub Desktop.
Codeforces 1238 #Codeforces
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