#include <bits/stdc++.h> using namespace std; int main(){ char S[200005]; int T[200005]; scanf("%s", S); int len = strlen(S); if(len == 1 || len == 2){ printf("0\n"); return 0; } for(int i=0; i<len; i++){ if(S[i] == 'a' || S[i] == 'e' || S[i] == 'i' || S[i] == 'o' || S[i] == 'u' || S[i] == 'y') T[i] = 0; else T[i] = 1; } int PRE[200005]; PRE[0] = T[0]; for(int i=1; i<len; i++) PRE[i] = PRE[i-1] + T[i]; vector<int> ENDs; if(PRE[2] == 0 || PRE[2] == 3) ENDs.push_back(2); for(int i=3; i<len; i++){ if(PRE[i]-PRE[i-3] == 0 || PRE[i]-PRE[i-3] == 3){ ENDs.push_back(i); } } ENDs.push_back(len); long long Newt[200005]; Newt[0] = Newt[1] = Newt[2] = 1; for(int i=3; i<=len+2; i++) Newt[i] = Newt[i-1]+(long long)i-1; int i=0; long long res=1; for(int j=0; j<ENDs.size(); j++){ res += (Newt[ENDs[j]-i+1] - 1); i = ENDs[j]-1; } res = Newt[len+1] - res; printf("%lld\n", res); return 0; }
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 44 45 46 47 48 49 50 51 | #include <bits/stdc++.h> using namespace std; int main(){ char S[200005]; int T[200005]; scanf("%s", S); int len = strlen(S); if(len == 1 || len == 2){ printf("0\n"); return 0; } for(int i=0; i<len; i++){ if(S[i] == 'a' || S[i] == 'e' || S[i] == 'i' || S[i] == 'o' || S[i] == 'u' || S[i] == 'y') T[i] = 0; else T[i] = 1; } int PRE[200005]; PRE[0] = T[0]; for(int i=1; i<len; i++) PRE[i] = PRE[i-1] + T[i]; vector<int> ENDs; if(PRE[2] == 0 || PRE[2] == 3) ENDs.push_back(2); for(int i=3; i<len; i++){ if(PRE[i]-PRE[i-3] == 0 || PRE[i]-PRE[i-3] == 3){ ENDs.push_back(i); } } ENDs.push_back(len); long long Newt[200005]; Newt[0] = Newt[1] = Newt[2] = 1; for(int i=3; i<=len+2; i++) Newt[i] = Newt[i-1]+(long long)i-1; int i=0; long long res=1; for(int j=0; j<ENDs.size(); j++){ res += (Newt[ENDs[j]-i+1] - 1); i = ENDs[j]-1; } res = Newt[len+1] - res; printf("%lld\n", res); return 0; } |