#include <bits/stdc++.h> using namespace std; #define REP(i,a,b) for (int i = (a); i <= (b); ++i) #define REPD(i,a,b) for (int i = (a); i >= (b); --i) #define FORI(i,n) REP(i,1,n) #define FOR(i,n) REP(i,0,int(n)-1) #define mp make_pair #define pb push_back #define pii pair<int,int> #define vi vector<int> #define ll long long #define SZ(x) int((x).size()) #define DBG(v) cerr << #v << " = " << (v) << endl; #define FOREACH(i,t) for (typeof(t.begin()) i=t.begin(); i!=t.end(); i++) #define fi first #define se second int n; int t[200200]; char s[200200]; int bad[333]; long long get(int lo, int hi) { hi = hi-lo+1; return 1LL * hi * (hi+1) / 2; } int main() { bad['a'] = bad['e'] = bad['i'] = bad['o'] = bad['u'] = bad['y'] = 1; scanf("%s", s); for (n = 0; s[n]; n++) { t[n] = bad[s[n]]; } long long res = 1LL * n * (n+1) / 2; int last = 0, cnt = 1; t[n] = -1; for (int i = 1; i <= n; i++) { if (t[i] == t[i-1]) cnt++; else { if (cnt >= 3) { res -= get(last, i-cnt+1); res += 7-2*cnt; last = i-2; } cnt = 1; } } res -= get(last, n-1); 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 46 47 48 49 50 51 | #include <bits/stdc++.h> using namespace std; #define REP(i,a,b) for (int i = (a); i <= (b); ++i) #define REPD(i,a,b) for (int i = (a); i >= (b); --i) #define FORI(i,n) REP(i,1,n) #define FOR(i,n) REP(i,0,int(n)-1) #define mp make_pair #define pb push_back #define pii pair<int,int> #define vi vector<int> #define ll long long #define SZ(x) int((x).size()) #define DBG(v) cerr << #v << " = " << (v) << endl; #define FOREACH(i,t) for (typeof(t.begin()) i=t.begin(); i!=t.end(); i++) #define fi first #define se second int n; int t[200200]; char s[200200]; int bad[333]; long long get(int lo, int hi) { hi = hi-lo+1; return 1LL * hi * (hi+1) / 2; } int main() { bad['a'] = bad['e'] = bad['i'] = bad['o'] = bad['u'] = bad['y'] = 1; scanf("%s", s); for (n = 0; s[n]; n++) { t[n] = bad[s[n]]; } long long res = 1LL * n * (n+1) / 2; int last = 0, cnt = 1; t[n] = -1; for (int i = 1; i <= n; i++) { if (t[i] == t[i-1]) cnt++; else { if (cnt >= 3) { res -= get(last, i-cnt+1); res += 7-2*cnt; last = i-2; } cnt = 1; } } res -= get(last, n-1); printf("%lld\n", res); return 0; } |