#include<bits/stdc++.h> #define ALL(X) X.begin(),X.end() #define FOR(I,A,B) for(int (I) = (A); (I) <= (B); (I)++) #define FORW(I,A,B) for(int (I) = (A); (I) < (B); (I)++) #define FORD(I,A,B) for(int (I) = (A); (I) >= (B); (I)--) #define CLEAR(X) memset(X,0,sizeof(X)) #define SIZE(X) int(X.size()) #define CONTAINS(A,X) (A.find(X) != A.end()) #define PB push_back #define MP make_pair #define X first #define Y second using namespace std; typedef signed long long slong; typedef long double ldouble; const slong INF = 1000000100; const ldouble EPS = 1e-9; const int MAXN = 1000100; set<char> vowels { 'a', 'e', 'i', 'o', 'u', 'y' }; char A[MAXN]; bool T[MAXN]; int Z[MAXN]; void read_data() { scanf("%s", A); } bool ok(char c) { return CONTAINS(vowels, c); } void solve() { int n = strlen(A); FORW(i,0,n-2) { if(ok(A[i]) == ok(A[i+1]) and ok(A[i]) == ok(A[i+2])) { T[i+2] = true; } } slong good = 0; Z[n-1] = T[n-1] ? n-1 : -1; FORD(i,n-2,0) { Z[i] = T[i] ? i : Z[i+1]; } FORW(i,0,n) { int g; if (i == n-2) { g = 2; } else if (i == n-1) { g = 1; } else { if (Z[i+2] == -1) { g = n - i; } else { g = Z[i+2] - i; } } good += g; } slong all = slong(n) * (n+1) / 2; slong bad = all - good; printf("%lld\n", bad); } int main() { read_data(); solve(); }
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 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 | #include<bits/stdc++.h> #define ALL(X) X.begin(),X.end() #define FOR(I,A,B) for(int (I) = (A); (I) <= (B); (I)++) #define FORW(I,A,B) for(int (I) = (A); (I) < (B); (I)++) #define FORD(I,A,B) for(int (I) = (A); (I) >= (B); (I)--) #define CLEAR(X) memset(X,0,sizeof(X)) #define SIZE(X) int(X.size()) #define CONTAINS(A,X) (A.find(X) != A.end()) #define PB push_back #define MP make_pair #define X first #define Y second using namespace std; typedef signed long long slong; typedef long double ldouble; const slong INF = 1000000100; const ldouble EPS = 1e-9; const int MAXN = 1000100; set<char> vowels { 'a', 'e', 'i', 'o', 'u', 'y' }; char A[MAXN]; bool T[MAXN]; int Z[MAXN]; void read_data() { scanf("%s", A); } bool ok(char c) { return CONTAINS(vowels, c); } void solve() { int n = strlen(A); FORW(i,0,n-2) { if(ok(A[i]) == ok(A[i+1]) and ok(A[i]) == ok(A[i+2])) { T[i+2] = true; } } slong good = 0; Z[n-1] = T[n-1] ? n-1 : -1; FORD(i,n-2,0) { Z[i] = T[i] ? i : Z[i+1]; } FORW(i,0,n) { int g; if (i == n-2) { g = 2; } else if (i == n-1) { g = 1; } else { if (Z[i+2] == -1) { g = n - i; } else { g = Z[i+2] - i; } } good += g; } slong all = slong(n) * (n+1) / 2; slong bad = all - good; printf("%lld\n", bad); } int main() { read_data(); solve(); } |