#include <stdio.h> #include <stdlib.h> #include <string.h> #include <assert.h> #include <time.h> #include <algorithm> #include <bitset> #include <fstream> #include <iomanip> #include <iostream> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <vector> using namespace std; // debugging stuff {{{ #ifdef DEBUG #define bDebug 1 #define bDebug2 0 #else #define bDebug 0 #define bDebug2 0 #endif #define deb(a) #a << "=" << (a) << " " #ifndef HOME #define assert(a) {} #endif template<class T> ostream& operator<<(ostream& os, vector<T> v) //{{{ { for(int i=0; i<v.size(); i++) os << v[i] << " "; os << endl; return os; } //}}} // }}} end of debugging stuff //c++11 #define typeof __typeof__ #define array(a, type, count) type *a = (type*)calloc(sizeof(type), count) #define eps 1e-9 #define eq(a, b) ( (a) > (b) - eps && (a) < (b) + eps ) #define eraseAll(v) v.erase(v.begin(), v.end()) #define fi first #define rep(i,n) for(long i=0; i<(n); i++) #define rep2(i,a,b) for(long i=(a); i<=(b); i++) #define rep2d(i,a,b) for(long i=(a); i>=(b); i--) #define zeroMem(a) memset(a, 0, sizeof(a)) #define zeroMem2(a, n) memset(a, 0, sizeof(*a) * n) #define fore(it,L) for(typeof(L.begin()) it=L.begin(); it!=L.end(); it++) #define eraseAll(v) v.erase(v.begin(), v.end()) #define se second #define setMin(a,b) { typeof(a) rv = (b); if (rv < a) a = rv; } #define setMinP(a,b) { typeof(a) rv = (b); \ if (rv >= 0 && (a < 0 || rv < a)) a = rv; } #define setMax(a,b) { typeof(a) rv = (b); if (rv > a) a = rv; } #define swap(a,b) { typeof(a) swapVar = a; a = b; b = swapVar; } #define Int long long #define _CRT_SECURE_NO_WARNINGS #pragma warning(suppress : 4996) //*********************** SOLUTION ****************************** #define N 210000 char s0[N]; char s[N]; int at[2][N]; long ak[N]; int samogloska(char c) { return strchr("aeiouy", c) != NULL; } int main (int argc, char **args) { #ifdef HOME if (argc > 0) { freopen(args[1], "r", stdin); } #endif cin.sync_with_stdio(false); cout.sync_with_stdio(false); cin >> s0; long long n = strlen(s0); rep(i, n) s[i] = samogloska(s0[i]); rep(i, N) at[0][i] = at[1][i] = 0, ak[i] = 0; //rep(i, n) cout << (char)('0' + s[i]); long c0 = 0, c1 = 0; rep(dir, 2) { long i = dir == 0 ? 0 : n - 1; while (true) { if (s[i] == 0) c0++; else c0 = 0; if (s[i] == 1) c1++; else c1 = 0; at[dir][i] = max(c0, c1); if (dir == 0) { i++; if (i >= n) break; } else { i--; if (i < 0) break; } } } long k = 1; ak[n - 1] = 1; rep2d(i, n - 2, 0) { if (at[1][i] >= 3) k = 2; else k++; ak[i] = k; } if (0) { rep(i, n) cerr << s0[i]; cerr << endl; rep(i, n) cerr << (int)(s[i]); cerr << endl; rep(i, n) cerr << at[0][i]; cerr << endl; rep(i, n) cerr << at[1][i]; cerr << endl; rep(i, n) cerr << ak[i]; cerr << endl; } long long x = n * (n + 1) / 2; rep(i, n) { x -= ak[i]; } cout << x << 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 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 | #include <stdio.h> #include <stdlib.h> #include <string.h> #include <assert.h> #include <time.h> #include <algorithm> #include <bitset> #include <fstream> #include <iomanip> #include <iostream> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <vector> using namespace std; // debugging stuff {{{ #ifdef DEBUG #define bDebug 1 #define bDebug2 0 #else #define bDebug 0 #define bDebug2 0 #endif #define deb(a) #a << "=" << (a) << " " #ifndef HOME #define assert(a) {} #endif template<class T> ostream& operator<<(ostream& os, vector<T> v) //{{{ { for(int i=0; i<v.size(); i++) os << v[i] << " "; os << endl; return os; } //}}} // }}} end of debugging stuff //c++11 #define typeof __typeof__ #define array(a, type, count) type *a = (type*)calloc(sizeof(type), count) #define eps 1e-9 #define eq(a, b) ( (a) > (b) - eps && (a) < (b) + eps ) #define eraseAll(v) v.erase(v.begin(), v.end()) #define fi first #define rep(i,n) for(long i=0; i<(n); i++) #define rep2(i,a,b) for(long i=(a); i<=(b); i++) #define rep2d(i,a,b) for(long i=(a); i>=(b); i--) #define zeroMem(a) memset(a, 0, sizeof(a)) #define zeroMem2(a, n) memset(a, 0, sizeof(*a) * n) #define fore(it,L) for(typeof(L.begin()) it=L.begin(); it!=L.end(); it++) #define eraseAll(v) v.erase(v.begin(), v.end()) #define se second #define setMin(a,b) { typeof(a) rv = (b); if (rv < a) a = rv; } #define setMinP(a,b) { typeof(a) rv = (b); \ if (rv >= 0 && (a < 0 || rv < a)) a = rv; } #define setMax(a,b) { typeof(a) rv = (b); if (rv > a) a = rv; } #define swap(a,b) { typeof(a) swapVar = a; a = b; b = swapVar; } #define Int long long #define _CRT_SECURE_NO_WARNINGS #pragma warning(suppress : 4996) //*********************** SOLUTION ****************************** #define N 210000 char s0[N]; char s[N]; int at[2][N]; long ak[N]; int samogloska(char c) { return strchr("aeiouy", c) != NULL; } int main (int argc, char **args) { #ifdef HOME if (argc > 0) { freopen(args[1], "r", stdin); } #endif cin.sync_with_stdio(false); cout.sync_with_stdio(false); cin >> s0; long long n = strlen(s0); rep(i, n) s[i] = samogloska(s0[i]); rep(i, N) at[0][i] = at[1][i] = 0, ak[i] = 0; //rep(i, n) cout << (char)('0' + s[i]); long c0 = 0, c1 = 0; rep(dir, 2) { long i = dir == 0 ? 0 : n - 1; while (true) { if (s[i] == 0) c0++; else c0 = 0; if (s[i] == 1) c1++; else c1 = 0; at[dir][i] = max(c0, c1); if (dir == 0) { i++; if (i >= n) break; } else { i--; if (i < 0) break; } } } long k = 1; ak[n - 1] = 1; rep2d(i, n - 2, 0) { if (at[1][i] >= 3) k = 2; else k++; ak[i] = k; } if (0) { rep(i, n) cerr << s0[i]; cerr << endl; rep(i, n) cerr << (int)(s[i]); cerr << endl; rep(i, n) cerr << at[0][i]; cerr << endl; rep(i, n) cerr << at[1][i]; cerr << endl; rep(i, n) cerr << ak[i]; cerr << endl; } long long x = n * (n + 1) / 2; rep(i, n) { x -= ak[i]; } cout << x << endl; } |