#include <cstdio> #include <string.h> char text[200010]; int difficult_from[200010]; char vow[] = {'a', 'e', 'i', 'o', 'u', 'y'}; bool is_vow(char c) { for (int i = 0; i < 6; i++) { if (vow[i] == c) { return true; } } return false; } int main() { scanf("%s", text); int n = strlen(text); difficult_from[0] = -1; difficult_from[1] = -1; for (int i = 2; i < n; i++) { if ((is_vow(text[i]) && is_vow(text[i - 1]) && is_vow(text[i - 2])) || (!is_vow(text[i]) && !is_vow(text[i - 1]) && !is_vow(text[i - 2]))) { difficult_from[i] = i - 2; } else { difficult_from[i] = difficult_from[i - 1]; } } int begin = 0; int end = 2; long long int answer = 0; while (end < n) { while (end < n && difficult_from[end] < begin) { end++; } answer += n - end; begin++; } printf("%lld", answer); 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 | #include <cstdio> #include <string.h> char text[200010]; int difficult_from[200010]; char vow[] = {'a', 'e', 'i', 'o', 'u', 'y'}; bool is_vow(char c) { for (int i = 0; i < 6; i++) { if (vow[i] == c) { return true; } } return false; } int main() { scanf("%s", text); int n = strlen(text); difficult_from[0] = -1; difficult_from[1] = -1; for (int i = 2; i < n; i++) { if ((is_vow(text[i]) && is_vow(text[i - 1]) && is_vow(text[i - 2])) || (!is_vow(text[i]) && !is_vow(text[i - 1]) && !is_vow(text[i - 2]))) { difficult_from[i] = i - 2; } else { difficult_from[i] = difficult_from[i - 1]; } } int begin = 0; int end = 2; long long int answer = 0; while (end < n) { while (end < n && difficult_from[end] < begin) { end++; } answer += n - end; begin++; } printf("%lld", answer); return 0; } |