#include <iostream> #include <cstdio> #include <vector> using namespace std; typedef long long LL; //#define DEBUG bool sam(char c) { if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u' || c == 'y') return true; else return false; } LL pary(LL n) { #ifdef DEBUG printf("pary(%lld) = %lld\n", n, (n - 1) * (n - 2) / 2); #endif return (n - 1) * (n - 2) / 2; } LL dobre = 0; LL ost_kon = -1; void nowa3(LL pocz, LL kon) { if (ost_kon == -1) { #ifdef DEBUG printf("nowa3(%lld, %lld), ost_kon = %lld\n", pocz, kon, ost_kon); #endif dobre += pary(pocz + 1 + 1); } else { #ifdef DEBUG printf("nowa3(%lld, %lld), ost_kon = %lld\n", pocz, kon, ost_kon); #endif dobre += pary((pocz + 1) - (ost_kon - 1) + 1); } ost_kon = kon; } int main() { ios_base::sync_with_stdio(0); string s; LL n; cin >> s; n = s.size(); LL ost = -1; // sam = 0, spol = 1 LL dl_spol = 0, dl_sam = 0; for (LL i = 0; i < n; i++) { if (sam(s[i])) { //sam if (ost == 0) { dl_sam++; } if (ost == 1 || ost == -1) { if (dl_spol >= 3) { nowa3(i - dl_spol, i - 1); } ost = 0; dl_sam = 1; } } if (!sam(s[i])) { //spol if (ost == 1) { dl_spol++; } if (ost == 0 || ost == -1) { if (dl_sam >= 3) { nowa3(i - dl_sam, i - 1); } ost = 1; dl_spol = 1; } } } if (ost == 1 && dl_spol >= 3) { #ifdef DEBUG printf("konca, dl_spol = %lld\n", dl_spol); #endif nowa3(n - dl_spol, n - 1); } else if (ost == 0 && dl_sam >= 3) { #ifdef DEBUG printf("koncb, dl_sam = %lld\n", dl_sam); #endif nowa3(n - dl_sam, n - 1); } else { if (ost_kon == -1) { #ifdef DEBUG printf("konc3a, ost_kon = %lld\n", ost_kon); #endif dobre += pary(n); } else { #ifdef DEBUG printf("konc3b, ost_kon = %lld\n", ost_kon); #endif dobre += pary((n - 1) - (ost_kon - 1) + 1); } } LL wynik = pary(n) - dobre; #ifdef DEBUG printf("dobre = %lld, pary(n) = %lld, wynik = %lld\n", dobre, pary(n), wynik); #endif printf("%lld\n", wynik); 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 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 | #include <iostream> #include <cstdio> #include <vector> using namespace std; typedef long long LL; //#define DEBUG bool sam(char c) { if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u' || c == 'y') return true; else return false; } LL pary(LL n) { #ifdef DEBUG printf("pary(%lld) = %lld\n", n, (n - 1) * (n - 2) / 2); #endif return (n - 1) * (n - 2) / 2; } LL dobre = 0; LL ost_kon = -1; void nowa3(LL pocz, LL kon) { if (ost_kon == -1) { #ifdef DEBUG printf("nowa3(%lld, %lld), ost_kon = %lld\n", pocz, kon, ost_kon); #endif dobre += pary(pocz + 1 + 1); } else { #ifdef DEBUG printf("nowa3(%lld, %lld), ost_kon = %lld\n", pocz, kon, ost_kon); #endif dobre += pary((pocz + 1) - (ost_kon - 1) + 1); } ost_kon = kon; } int main() { ios_base::sync_with_stdio(0); string s; LL n; cin >> s; n = s.size(); LL ost = -1; // sam = 0, spol = 1 LL dl_spol = 0, dl_sam = 0; for (LL i = 0; i < n; i++) { if (sam(s[i])) { //sam if (ost == 0) { dl_sam++; } if (ost == 1 || ost == -1) { if (dl_spol >= 3) { nowa3(i - dl_spol, i - 1); } ost = 0; dl_sam = 1; } } if (!sam(s[i])) { //spol if (ost == 1) { dl_spol++; } if (ost == 0 || ost == -1) { if (dl_sam >= 3) { nowa3(i - dl_sam, i - 1); } ost = 1; dl_spol = 1; } } } if (ost == 1 && dl_spol >= 3) { #ifdef DEBUG printf("konca, dl_spol = %lld\n", dl_spol); #endif nowa3(n - dl_spol, n - 1); } else if (ost == 0 && dl_sam >= 3) { #ifdef DEBUG printf("koncb, dl_sam = %lld\n", dl_sam); #endif nowa3(n - dl_sam, n - 1); } else { if (ost_kon == -1) { #ifdef DEBUG printf("konc3a, ost_kon = %lld\n", ost_kon); #endif dobre += pary(n); } else { #ifdef DEBUG printf("konc3b, ost_kon = %lld\n", ost_kon); #endif dobre += pary((n - 1) - (ost_kon - 1) + 1); } } LL wynik = pary(n) - dobre; #ifdef DEBUG printf("dobre = %lld, pary(n) = %lld, wynik = %lld\n", dobre, pary(n), wynik); #endif printf("%lld\n", wynik); return 0; } |