#include <bits/stdc++.h> // #pragma GCC optimize ("O3") // #pragma GCC target ("sse4") using namespace std; typedef long long LL; typedef unsigned long long ULL; typedef pair<int,int> PII; #define REP(i,n) for(int i=0;i<(n);++i) #define FOR(i,a,b) for (int i=(a); i<(b); ++i) #define FORD(i,a,b) for (int i=(a)-1; i>=(b); --i) #define pb push_back #define mp make_pair #define st first #define nd second char S[300000]; const set<char> vowels = {'a', 'e', 'i', 'o', 'u', 'y'}; int main() { // ios_base::sync_with_stdio(0); scanf("%s", S); int N = strlen(S); if (N < 3) { printf("0\n"); return 0; } REP(i,N) S[i] = vowels.find(S[i]) != vowels.end(); vector<int> borders; REP(i,N) if (i == 0 || i == N-1 || (S[i-1] == S[i] && S[i] == S[i+1])) borders.pb(i); LL result = N*(LL)(N+1)/2; REP(i, borders.size()-1) { LL d = borders[i+1] - borders[i] + 1; result -= d * (d+1) / 2; } result += borders.size()-2; printf("%lld\n", result); }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | #include <bits/stdc++.h> // #pragma GCC optimize ("O3") // #pragma GCC target ("sse4") using namespace std; typedef long long LL; typedef unsigned long long ULL; typedef pair<int,int> PII; #define REP(i,n) for(int i=0;i<(n);++i) #define FOR(i,a,b) for (int i=(a); i<(b); ++i) #define FORD(i,a,b) for (int i=(a)-1; i>=(b); --i) #define pb push_back #define mp make_pair #define st first #define nd second char S[300000]; const set<char> vowels = {'a', 'e', 'i', 'o', 'u', 'y'}; int main() { // ios_base::sync_with_stdio(0); scanf("%s", S); int N = strlen(S); if (N < 3) { printf("0\n"); return 0; } REP(i,N) S[i] = vowels.find(S[i]) != vowels.end(); vector<int> borders; REP(i,N) if (i == 0 || i == N-1 || (S[i-1] == S[i] && S[i] == S[i+1])) borders.pb(i); LL result = N*(LL)(N+1)/2; REP(i, borders.size()-1) { LL d = borders[i+1] - borders[i] + 1; result -= d * (d+1) / 2; } result += borders.size()-2; printf("%lld\n", result); } |