#include <bits/stdc++.h> // Tomasz Nowak using namespace std; // XIII LO Szczecin #define FOR(i,a,n) for (auto i = (a), i##__ = (n); i <= i##__; ++i) #define REP(i,n) FOR(i,0,(n)-1) #define FORD(i,a,n) for (auto i = (a), i##__ = (n); i >= i##__; --i) #define REPD(i,n) FORD(i,(n)-1,0) #define ALL(x) x.begin(), x.end() #define SZ(x) ((int) x.size()) #define X first #define Y second #define V vector #define A array constexpr char nl = '\n'; template<class A, class B> A&& mini(A &&a, B &&b) { if (b < a) a = b; return a; } template<class A, class B> A&& maxi(A &&a, B &&b) { if (b > a) a = b; return a; } int first_bit(int x) { return x == 0 ? 0 : sizeof(x) * 8 - __builtin_clz(x); } int ceil2(int x) { return x < 2 ? x : 1 << first_bit(x - 1); } constexpr int inf = 0x3f3f3f3f; constexpr long long inf_l = 0x3f3f3f3f3f3f3f3f; #define _eif(a...) typename enable_if<a, int>::type() #define _func(func, a...) template<class T> auto func(T &&x) -> decltype(a) #define _rref(a...) typename remove_reference<a>::type #define _create_trait(name, a...) \ _func(_##name, a, true_type{}); \ false_type _##name(...); \ template<class T> struct name : decltype(_##name(declval<T>())) {}; struct Debug; _create_trait(is_debug_func, x(declval<add_lvalue_reference<Debug>::type>())); _create_trait(is_func, x()) _create_trait(is_string, string(x)) _create_trait(is_ptr, *x, _eif(is_string<T>() == false)); _create_trait(is_container, x.begin(), _eif(is_string<T>() == false)) template<class Iter> struct Off { Iter _a, _b; }; _func(O, _eif(is_container<T>() == true), Off<decltype(x.begin())>()) { return { ALL(x) }; } _func(O, _eif(is_container<T>() == false), x) { return x; } #define _operator(a...) _func(operator<<, a, *this) struct Debug { Debug() { cerr << boolalpha << fixed << setprecision(0); } ~Debug() { cerr << nl; } Debug& operator()(int x = 1) { REP(_, x) *this << " "; return *this; } _operator(cerr << x, _eif(is_func<T>() == false && is_ptr<T>() == false && is_integral<_rref(T)>() == true)) { using L = long long; if(abs(int(x)) == inf || abs(L(x)) == inf_l) cerr << ((int(x) == inf || L(x) == inf_l) ? "+∞" : (int(x) == -inf || L(x) == -inf_l) ? "-∞" : "?"); else cerr << x; return *this; } _operator(cerr << x, _eif(is_func<T>() == false && is_ptr<T>() == false && is_integral<_rref(T)>() == false)) { cerr << x; return *this; } _operator(x.first) { return *this << "(" << O(x.first) << ", " << O(x.second) << ")"; } _operator(_eif(is_container<T>() == true)) { *this << "{\n"; for (auto a = x.begin(); a != x.end(); ++a) *this << " " << distance(x.begin(), a) << ": " << O(*a) << '\n'; return *this << "}"; } _operator(x._a) { *this << "{"; for (auto a = x._a, b = x._b; a != b; ++a) *this << O(*a) << (next(a) == b ? "" : ", "); return *this << "}"; } _operator(_eif(is_func<T>() == true)) { x(); return *this; } _operator(_eif(is_debug_func<T>() == true)) { x(*this); return *this; } _operator(_eif(is_ptr<T>() == true && is_func<T>() == false && is_debug_func<T>() == false)) { return *this << *x; } }; struct DebugOff { template<class T> DebugOff& operator<<(T&&) { return *this; } DebugOff& operator()(int = 0) { return *this; } }; #ifdef DEBUG # define D Debug() #else # define D DebugOff() #endif #define I(a...) #a ": " << a << " " using VI = V<int>; using VVI = V<VI>; using L = long long; using VL = V<L>; using VB = V<bool>; using II = pair<int, int>; using VII = V<II>; using VVII = V<VII>; // end of templates v8 by Tomasz Nowak bool samogloska(char c) { for(char s : string("aeyiou")) if(c == s) return true; return false; } bool spolgloska(char c) { return !samogloska(c); } int main() { ios_base::sync_with_stdio(0); cin.tie(0); string s; cin >> s; int n = SZ(s); VI bad_start; auto is_bad_start = [&](int i) { return (samogloska(s[i]) && samogloska(s[i + 1]) && samogloska(s[i + 2])) || (spolgloska(s[i]) && spolgloska(s[i + 1]) && spolgloska(s[i + 2])); }; REP(i, n - 2) if(is_bad_start(i)) bad_start.emplace_back(i); D << I(bad_start); if(SZ(bad_start) == 0) return cout << 0 << nl, 0; auto dwumian = [&](int x) { return x * L(x + 1) / 2; }; L all = dwumian(n); all -= dwumian(bad_start[0] + 2); // removing good ones before first bad all -= dwumian(n - bad_start.back() - 1); // removing good ones after last bad REP(it, SZ(bad_start) - 1) { int i = bad_start[it], j = bad_start[it + 1]; // removing in between int len = j - i + 1; all -= dwumian(len); } all += SZ(bad_start); // magic fix cout << all << nl; }
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 144 145 146 147 148 149 150 151 152 | #include <bits/stdc++.h> // Tomasz Nowak using namespace std; // XIII LO Szczecin #define FOR(i,a,n) for (auto i = (a), i##__ = (n); i <= i##__; ++i) #define REP(i,n) FOR(i,0,(n)-1) #define FORD(i,a,n) for (auto i = (a), i##__ = (n); i >= i##__; --i) #define REPD(i,n) FORD(i,(n)-1,0) #define ALL(x) x.begin(), x.end() #define SZ(x) ((int) x.size()) #define X first #define Y second #define V vector #define A array constexpr char nl = '\n'; template<class A, class B> A&& mini(A &&a, B &&b) { if (b < a) a = b; return a; } template<class A, class B> A&& maxi(A &&a, B &&b) { if (b > a) a = b; return a; } int first_bit(int x) { return x == 0 ? 0 : sizeof(x) * 8 - __builtin_clz(x); } int ceil2(int x) { return x < 2 ? x : 1 << first_bit(x - 1); } constexpr int inf = 0x3f3f3f3f; constexpr long long inf_l = 0x3f3f3f3f3f3f3f3f; #define _eif(a...) typename enable_if<a, int>::type() #define _func(func, a...) template<class T> auto func(T &&x) -> decltype(a) #define _rref(a...) typename remove_reference<a>::type #define _create_trait(name, a...) \ _func(_##name, a, true_type{}); \ false_type _##name(...); \ template<class T> struct name : decltype(_##name(declval<T>())) {}; struct Debug; _create_trait(is_debug_func, x(declval<add_lvalue_reference<Debug>::type>())); _create_trait(is_func, x()) _create_trait(is_string, string(x)) _create_trait(is_ptr, *x, _eif(is_string<T>() == false)); _create_trait(is_container, x.begin(), _eif(is_string<T>() == false)) template<class Iter> struct Off { Iter _a, _b; }; _func(O, _eif(is_container<T>() == true), Off<decltype(x.begin())>()) { return { ALL(x) }; } _func(O, _eif(is_container<T>() == false), x) { return x; } #define _operator(a...) _func(operator<<, a, *this) struct Debug { Debug() { cerr << boolalpha << fixed << setprecision(0); } ~Debug() { cerr << nl; } Debug& operator()(int x = 1) { REP(_, x) *this << " "; return *this; } _operator(cerr << x, _eif(is_func<T>() == false && is_ptr<T>() == false && is_integral<_rref(T)>() == true)) { using L = long long; if(abs(int(x)) == inf || abs(L(x)) == inf_l) cerr << ((int(x) == inf || L(x) == inf_l) ? "+∞" : (int(x) == -inf || L(x) == -inf_l) ? "-∞" : "?"); else cerr << x; return *this; } _operator(cerr << x, _eif(is_func<T>() == false && is_ptr<T>() == false && is_integral<_rref(T)>() == false)) { cerr << x; return *this; } _operator(x.first) { return *this << "(" << O(x.first) << ", " << O(x.second) << ")"; } _operator(_eif(is_container<T>() == true)) { *this << "{\n"; for (auto a = x.begin(); a != x.end(); ++a) *this << " " << distance(x.begin(), a) << ": " << O(*a) << '\n'; return *this << "}"; } _operator(x._a) { *this << "{"; for (auto a = x._a, b = x._b; a != b; ++a) *this << O(*a) << (next(a) == b ? "" : ", "); return *this << "}"; } _operator(_eif(is_func<T>() == true)) { x(); return *this; } _operator(_eif(is_debug_func<T>() == true)) { x(*this); return *this; } _operator(_eif(is_ptr<T>() == true && is_func<T>() == false && is_debug_func<T>() == false)) { return *this << *x; } }; struct DebugOff { template<class T> DebugOff& operator<<(T&&) { return *this; } DebugOff& operator()(int = 0) { return *this; } }; #ifdef DEBUG # define D Debug() #else # define D DebugOff() #endif #define I(a...) #a ": " << a << " " using VI = V<int>; using VVI = V<VI>; using L = long long; using VL = V<L>; using VB = V<bool>; using II = pair<int, int>; using VII = V<II>; using VVII = V<VII>; // end of templates v8 by Tomasz Nowak bool samogloska(char c) { for(char s : string("aeyiou")) if(c == s) return true; return false; } bool spolgloska(char c) { return !samogloska(c); } int main() { ios_base::sync_with_stdio(0); cin.tie(0); string s; cin >> s; int n = SZ(s); VI bad_start; auto is_bad_start = [&](int i) { return (samogloska(s[i]) && samogloska(s[i + 1]) && samogloska(s[i + 2])) || (spolgloska(s[i]) && spolgloska(s[i + 1]) && spolgloska(s[i + 2])); }; REP(i, n - 2) if(is_bad_start(i)) bad_start.emplace_back(i); D << I(bad_start); if(SZ(bad_start) == 0) return cout << 0 << nl, 0; auto dwumian = [&](int x) { return x * L(x + 1) / 2; }; L all = dwumian(n); all -= dwumian(bad_start[0] + 2); // removing good ones before first bad all -= dwumian(n - bad_start.back() - 1); // removing good ones after last bad REP(it, SZ(bad_start) - 1) { int i = bad_start[it], j = bad_start[it + 1]; // removing in between int len = j - i + 1; all -= dwumian(len); } all += SZ(bad_start); // magic fix cout << all << nl; } |