题目链接
CodeForce 1178B. WOW Factor
代码
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
LL ans = 0LL;
int main() {
string s;
cin >> s;
s += 'o';
int n = s.length();
int n_consecutive = 0;
int prev_w = 0;
vector<LL> wPreSum(n + 1, -1);
for (int i = 0; i < n; ++i) {
if (s[i] == 'o') {
if (n_consecutive < 2)
wPreSum[i] = prev_w;
else
wPreSum[i] = prev_w + n_consecutive - 1;
n_consecutive = 0;
prev_w = wPreSum[i];
} else {
++n_consecutive;
}
}
wPreSum[n] = prev_w;
for (int i = 0; i < n; ++i) {
if (s[i] == 'o') {
ans += wPreSum[i] * (wPreSum[n] - wPreSum[i]);
}
}
printf("%lld\n", ans);
}