RT,实在想不到哪里会越界。
#include <bits/stdc++.h>
using namespace std;
int n, tot, ans;
string s, st;
int main () {
cin >> n >> s;
int slen = s.size ();
for (int i = 0; i < slen; ++ i) {
tot = 0;
for (int j = i; j < slen; ++ j) {
if (st[tot] != s[j] || tot == 0)
st[++ tot] = s[j];
else {
if (st[tot] == s[j] && tot != 0)
tot --;
if (tot == 0)
ans ++;
}
}
}
cout << ans;
return 0;
}