#include <bits/stdc++.h> using namespace std; bitset<200005> v; long long solve(const int& n) { int inarow = 1, id = 0; long long sum = 0; for(int i = 0; i < n; i++) { while(inarow < 3 || i > id - 2) { ++id; if(id == n) return sum; if(v[id] == v[id - 1]) ++inarow; else inarow = 1; } //cout << "id: " << id << " inarow: " << inarow << " i: " << i << endl; sum += n - id; } return sum; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); string s; cin >> s; int n = s.size(); for(int i = 0; i < n; i++) { if(s[i] == 'a' || s[i] == 'e' || s[i] == 'i' || s[i] == 'o' || s[i] == 'u' || s[i] == 'y') v[i] = true; } cout << solve(n) << endl; }
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 | #include <bits/stdc++.h> using namespace std; bitset<200005> v; long long solve(const int& n) { int inarow = 1, id = 0; long long sum = 0; for(int i = 0; i < n; i++) { while(inarow < 3 || i > id - 2) { ++id; if(id == n) return sum; if(v[id] == v[id - 1]) ++inarow; else inarow = 1; } //cout << "id: " << id << " inarow: " << inarow << " i: " << i << endl; sum += n - id; } return sum; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); string s; cin >> s; int n = s.size(); for(int i = 0; i < n; i++) { if(s[i] == 'a' || s[i] == 'e' || s[i] == 'i' || s[i] == 'o' || s[i] == 'u' || s[i] == 'y') v[i] = true; } cout << solve(n) << endl; } |