#include <cstdio> #include <cstring> #include <algorithm> using namespace std; typedef long long LL; const int N = 200010; char txt[N]; int sm[N], sp[N]; int tb[N]; char samo[] = {'a', 'o', 'u', 'y', 'i', 'e'}; inline bool czy_samo(char c) { for(int i = 0; i < 6; ++i) if(c == samo[i]) return true; return false; } int main() { scanf("%s", &txt[1]); int n = strlen(&txt[1]); for(int i = 1; i <= n; ++i) { if(czy_samo(txt[i])) sm[i] = sm[i-1]+1, sp[i] = 0; else sm[i] = 0, sp[i] = sp[i-1]+1; } fill(tb, tb+n+10, -1); for(int i = n; i > 0;) { for(int j = max(sp[i], sm[i])-3, k = i-3; j >= 0; --j, --k) { tb[k] = k; } i -= max(max(sp[i], sm[i]), 1); } int last = n+1; for(int i = n; i >= 0; --i) { tb[i] = (tb[i] == -1 ? last : (last=tb[i])); } LL res = 0; for(int i = 0; i <= n; ++i) { res += max(n-tb[i]-2, 0); } 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 | #include <cstdio> #include <cstring> #include <algorithm> using namespace std; typedef long long LL; const int N = 200010; char txt[N]; int sm[N], sp[N]; int tb[N]; char samo[] = {'a', 'o', 'u', 'y', 'i', 'e'}; inline bool czy_samo(char c) { for(int i = 0; i < 6; ++i) if(c == samo[i]) return true; return false; } int main() { scanf("%s", &txt[1]); int n = strlen(&txt[1]); for(int i = 1; i <= n; ++i) { if(czy_samo(txt[i])) sm[i] = sm[i-1]+1, sp[i] = 0; else sm[i] = 0, sp[i] = sp[i-1]+1; } fill(tb, tb+n+10, -1); for(int i = n; i > 0;) { for(int j = max(sp[i], sm[i])-3, k = i-3; j >= 0; --j, --k) { tb[k] = k; } i -= max(max(sp[i], sm[i]), 1); } int last = n+1; for(int i = n; i >= 0; --i) { tb[i] = (tb[i] == -1 ? last : (last=tb[i])); } LL res = 0; for(int i = 0; i <= n; ++i) { res += max(n-tb[i]-2, 0); } printf("%lld\n", res); return 0; } |