#include <bits/stdc++.h> #define mp make_pair #define fi first #define se second #define pb push_back #define all(x) (x).begin(),(x).end() using namespace std; typedef long long LL; typedef pair<int,int> PII; typedef vector < int > VI; typedef double D; const int MN = 200005, inf = 1000000005, mod = 1000000007; const LL INF = 1000000000000000005LL; string d00psko = "aeiouy"; string s; int dod[MN], wyw[MN], typ[MN]; int main() { cin >> s; int l = s.length(); for(int i = 0; i < l; ++i) { typ[i] = 1; for(auto lit : d00psko) if(s[i] == lit) typ[i] = 0; } for(int i = 2; i < l; ++i) if(typ[i] == typ[i - 1] && typ[i] == typ[i - 2]) { dod[i]++; wyw[i - 2]++; } int kon = -1, suma = 0; LL ans = 0LL; for(int i = 0; i < l; ++i) { while(kon < l && !suma) { ++kon; suma += dod[kon]; } ans -= 2LL * (kon - i); suma -= wyw[i]; } ans += 1LL * l * (l + 1); ans /= 2LL; printf("%lld", ans); }
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 51 52 53 54 55 56 57 | #include <bits/stdc++.h> #define mp make_pair #define fi first #define se second #define pb push_back #define all(x) (x).begin(),(x).end() using namespace std; typedef long long LL; typedef pair<int,int> PII; typedef vector < int > VI; typedef double D; const int MN = 200005, inf = 1000000005, mod = 1000000007; const LL INF = 1000000000000000005LL; string d00psko = "aeiouy"; string s; int dod[MN], wyw[MN], typ[MN]; int main() { cin >> s; int l = s.length(); for(int i = 0; i < l; ++i) { typ[i] = 1; for(auto lit : d00psko) if(s[i] == lit) typ[i] = 0; } for(int i = 2; i < l; ++i) if(typ[i] == typ[i - 1] && typ[i] == typ[i - 2]) { dod[i]++; wyw[i - 2]++; } int kon = -1, suma = 0; LL ans = 0LL; for(int i = 0; i < l; ++i) { while(kon < l && !suma) { ++kon; suma += dod[kon]; } ans -= 2LL * (kon - i); suma -= wyw[i]; } ans += 1LL * l * (l + 1); ans /= 2LL; printf("%lld", ans); } |