#include <bits/stdc++.h> #define fi first #define se second #define ll long long #define inf (1<<30); #define pi pair <int,int> #define pl pair <long long, long long> #define ld long double #define pb push_back using namespace std; const int MAXN = 200002; int F[MAXN]; string s; int n; bool vowel(char c) { return c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'i' || c == 'y'; } bool hard(int i) { return (vowel(s[i]) && vowel(s[i-1]) && vowel(s[i-2])) || (!vowel(s[i]) && !vowel(s[i-1]) && !vowel(s[i-2])); } int main() { ios_base::sync_with_stdio(0); cin>>s; n = s.length(); ll res = 2*n - 1; F[0] = F[1] = 1; ll l; for(int i=2; i<=n; i++) { F[i] = F[i-1]; if( hard(i) ) { F[i] = i; l = F[i] - F[i-1] + 1; if(l > 3) res += ((1+l)*l/2 - l - l + 1); } } l = n - F[n-1] + 1; res += ((1+l)*l/2 - l - l + 1); cout<<(n*(n+1)/2 - res)<<endl; 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 | #include <bits/stdc++.h> #define fi first #define se second #define ll long long #define inf (1<<30); #define pi pair <int,int> #define pl pair <long long, long long> #define ld long double #define pb push_back using namespace std; const int MAXN = 200002; int F[MAXN]; string s; int n; bool vowel(char c) { return c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'i' || c == 'y'; } bool hard(int i) { return (vowel(s[i]) && vowel(s[i-1]) && vowel(s[i-2])) || (!vowel(s[i]) && !vowel(s[i-1]) && !vowel(s[i-2])); } int main() { ios_base::sync_with_stdio(0); cin>>s; n = s.length(); ll res = 2*n - 1; F[0] = F[1] = 1; ll l; for(int i=2; i<=n; i++) { F[i] = F[i-1]; if( hard(i) ) { F[i] = i; l = F[i] - F[i-1] + 1; if(l > 3) res += ((1+l)*l/2 - l - l + 1); } } l = n - F[n-1] + 1; res += ((1+l)*l/2 - l - l + 1); cout<<(n*(n+1)/2 - res)<<endl; return 0; } |