#include <cstdio> #include <cstring> const int max_n = 200010; char input[max_n]; int n; bool is_vovel(char c) { return c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u' || c == 'y'; } int brute_check() { int ret = 0; for (int i = 0; i < n; ++i) { for (int j = i; j < n; ++j) { bool bad = false; for (int k = i; k + 2 <= j; ++k) { if (is_vovel(input[k]) && is_vovel(input[k + 1]) && is_vovel(input[k + 2]) || !is_vovel(input[k]) && !is_vovel(input[k + 1]) && !is_vovel(input[k + 2])) { bad = true; } } if (bad) ret++; } } return ret; } int main() { scanf("%s", input); n = strlen(input); long long result = n * (n + 1ll) / 2; int last_index = 0; for (int i = 0; i < n; ++i) { if (i == 0) result -= 1; else if (i == 1) result -= 2; else { if (is_vovel(input[i]) && is_vovel(input[i - 1]) && is_vovel(input[i - 2]) || !is_vovel(input[i]) && !is_vovel(input[i - 1]) && !is_vovel(input[i - 2])) { result -= 2; last_index = i - 1; } else { result -= (i - last_index + 1); } } } // printf("%d\n", brute_check()); printf("%lld\n", result); 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 | #include <cstdio> #include <cstring> const int max_n = 200010; char input[max_n]; int n; bool is_vovel(char c) { return c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u' || c == 'y'; } int brute_check() { int ret = 0; for (int i = 0; i < n; ++i) { for (int j = i; j < n; ++j) { bool bad = false; for (int k = i; k + 2 <= j; ++k) { if (is_vovel(input[k]) && is_vovel(input[k + 1]) && is_vovel(input[k + 2]) || !is_vovel(input[k]) && !is_vovel(input[k + 1]) && !is_vovel(input[k + 2])) { bad = true; } } if (bad) ret++; } } return ret; } int main() { scanf("%s", input); n = strlen(input); long long result = n * (n + 1ll) / 2; int last_index = 0; for (int i = 0; i < n; ++i) { if (i == 0) result -= 1; else if (i == 1) result -= 2; else { if (is_vovel(input[i]) && is_vovel(input[i - 1]) && is_vovel(input[i - 2]) || !is_vovel(input[i]) && !is_vovel(input[i - 1]) && !is_vovel(input[i - 2])) { result -= 2; last_index = i - 1; } else { result -= (i - last_index + 1); } } } // printf("%d\n", brute_check()); printf("%lld\n", result); return 0; } |