#include <cstdio> #include <cstring> typedef unsigned I; typedef unsigned long long L; static char text[200000 + 1]; static inline bool sg(char c) { return c == 'a' || c == 'e' || c == 'i' || c =='o' || c == 'u' || c == 'y'; } static L calc() { I n2 = 0; // 1 - sa, 2 - sg I n1 = 0; I pos = 0; I last = 0; L psum = 0; L res = 0; for (;; ++pos) { char c = text[pos]; if (!c) break; I n0 = sg(c) ? 2 : 1; if (n0 == n1 && n1 == n2) { I dist = pos - last - 1; last = pos - 1; res += psum * dist; psum += dist; } n2 = n1; n1 = n0; } I dist = pos - last - 1; res += psum * dist; return res; } int main() { scanf("%s\n", text); printf("%llu\n", calc()); 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 | #include <cstdio> #include <cstring> typedef unsigned I; typedef unsigned long long L; static char text[200000 + 1]; static inline bool sg(char c) { return c == 'a' || c == 'e' || c == 'i' || c =='o' || c == 'u' || c == 'y'; } static L calc() { I n2 = 0; // 1 - sa, 2 - sg I n1 = 0; I pos = 0; I last = 0; L psum = 0; L res = 0; for (;; ++pos) { char c = text[pos]; if (!c) break; I n0 = sg(c) ? 2 : 1; if (n0 == n1 && n1 == n2) { I dist = pos - last - 1; last = pos - 1; res += psum * dist; psum += dist; } n2 = n1; n1 = n0; } I dist = pos - last - 1; res += psum * dist; return res; } int main() { scanf("%s\n", text); printf("%llu\n", calc()); return 0; } |