#include <bits/stdc++.h> using namespace std; const int INF = 5e5; int n; set <char> vowels({'a', 'e', 'i', 'o', 'u', 'y'}); bool isHard(string& s, int i) { if (i > n - 3) { return false; } return (vowels.count(s[i]) == 1 && vowels.count(s[i + 1]) == 1 && vowels.count(s[i + 2]) == 1) || (vowels.count(s[i]) == 0 && vowels.count(s[i + 1]) == 0 && vowels.count(s[i + 2]) == 0); } int main() { string word; cin >> word; n = word.size(); vector <int> positions(n); for (int i = 0; i < n; i++) { positions[i] = isHard(word, i) ? i : INF; } for (int i = n - 3; i >= 0; i--) { positions[i] = min(positions[i], positions[i + 1]); } long long result = 0; for (int i = 0; i < n - 2; i++) { result += max(n - 2 - positions[i], 0); } cout << result << 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 | #include <bits/stdc++.h> using namespace std; const int INF = 5e5; int n; set <char> vowels({'a', 'e', 'i', 'o', 'u', 'y'}); bool isHard(string& s, int i) { if (i > n - 3) { return false; } return (vowels.count(s[i]) == 1 && vowels.count(s[i + 1]) == 1 && vowels.count(s[i + 2]) == 1) || (vowels.count(s[i]) == 0 && vowels.count(s[i + 1]) == 0 && vowels.count(s[i + 2]) == 0); } int main() { string word; cin >> word; n = word.size(); vector <int> positions(n); for (int i = 0; i < n; i++) { positions[i] = isHard(word, i) ? i : INF; } for (int i = n - 3; i >= 0; i--) { positions[i] = min(positions[i], positions[i + 1]); } long long result = 0; for (int i = 0; i < n - 2; i++) { result += max(n - 2 - positions[i], 0); } cout << result << endl; return 0; } |