#include <bits/stdc++.h> using namespace std; typedef long long LL; typedef pair<int, int> PII; const int N = 1e6; char hard[6] = {'a', 'e', 'i', 'o', 'u', 'y'}; LL a[N]; bool isHard(char c) { return (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u' || c == 'y'); } int main() { ios_base::sync_with_stdio(0); string s; cin >> s; //cout << s.length() << " " << s << endl; LL t = -1; for(int i = (int)s.length()-3;i >= 0;--i) { if(isHard(s[i]) && isHard(s[i+1]) && isHard(s[i+2])) { //cout << i << " -> " << s[i] << " " << s[i+1] << " " << s[i+2] << endl; t = 0; } else if(!isHard(s[i]) && !isHard(s[i+1]) && !isHard(s[i+2])) { //cout << "N " << i << " -> " << s[i] << " " << s[i+1] << " " << s[i+2] << endl; t = 0; } else if(t != -1) t++; a[i] = t; } LL res = 0; for(int i = 0;i < (int)s.length()-2;++i) { //cout << i << " -> " << a[i] << endl; if(a[i] != -1) res += s.length()-i-a[i]-2; } cout << 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 50 | #include <bits/stdc++.h> using namespace std; typedef long long LL; typedef pair<int, int> PII; const int N = 1e6; char hard[6] = {'a', 'e', 'i', 'o', 'u', 'y'}; LL a[N]; bool isHard(char c) { return (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u' || c == 'y'); } int main() { ios_base::sync_with_stdio(0); string s; cin >> s; //cout << s.length() << " " << s << endl; LL t = -1; for(int i = (int)s.length()-3;i >= 0;--i) { if(isHard(s[i]) && isHard(s[i+1]) && isHard(s[i+2])) { //cout << i << " -> " << s[i] << " " << s[i+1] << " " << s[i+2] << endl; t = 0; } else if(!isHard(s[i]) && !isHard(s[i+1]) && !isHard(s[i+2])) { //cout << "N " << i << " -> " << s[i] << " " << s[i+1] << " " << s[i+2] << endl; t = 0; } else if(t != -1) t++; a[i] = t; } LL res = 0; for(int i = 0;i < (int)s.length()-2;++i) { //cout << i << " -> " << a[i] << endl; if(a[i] != -1) res += s.length()-i-a[i]-2; } cout << res << endl; return 0; } |