#define ll long long
#include <cstdio>
char s[200010];
inline ll t(int x) {
return (ll)(x) * (ll)(x+1) / 2;
}
inline ll n(int x) {
return (ll)(x + 1);
}
inline bool isVowel(char c) {
bool is = (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u' || c == 'y');
return is;
}
ll comp(char *s) {
if (s[2] == '\0') return 0;
ll x = 2;
ll hx = 0;
ll not_N = 0; // 1, 2, 1:2
ll length = 2;
ll N=0;
bool is_hard = true;
for(char *c=s+2; *c != '\0'; ++c) {
if (isVowel(*c) == isVowel(*(c-1)) && isVowel(*(c)) == isVowel(*(c-2))) {
if (!is_hard) {
// printf("similiar, adding %lld\n", t(x) - 3);
not_N += t(x) - 3;
hx = 3;
x = 2;
} else {
if(hx)
++hx;
else
hx=3;
}
is_hard = true;
} else {
if (is_hard) {
if (hx) {
// printf("not similiar, adding %lld\n", hx*2-1);
not_N += (hx) * 2 - 4; // substrings of length 1 and 2 which end in 'c'
}
hx = 0;
x = 3;
} else {
++x;
}
is_hard = false;
}
length += 1;
}
// add remaining group
if (!is_hard) {
not_N += t(x);
}
if (is_hard) {
not_N += (hx) * 2 - 1;
}
//printf("%lld %lld\n", length, not_N);
return t(length) - not_N;
}
int main() {
scanf("%s", s);
ll res = comp(s);
printf("%lld\n", res);
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 | #define ll long long #include <cstdio> char s[200010]; inline ll t(int x) { return (ll)(x) * (ll)(x+1) / 2; } inline ll n(int x) { return (ll)(x + 1); } inline bool isVowel(char c) { bool is = (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u' || c == 'y'); return is; } ll comp(char *s) { if (s[2] == '\0') return 0; ll x = 2; ll hx = 0; ll not_N = 0; // 1, 2, 1:2 ll length = 2; ll N=0; bool is_hard = true; for(char *c=s+2; *c != '\0'; ++c) { if (isVowel(*c) == isVowel(*(c-1)) && isVowel(*(c)) == isVowel(*(c-2))) { if (!is_hard) { // printf("similiar, adding %lld\n", t(x) - 3); not_N += t(x) - 3; hx = 3; x = 2; } else { if(hx) ++hx; else hx=3; } is_hard = true; } else { if (is_hard) { if (hx) { // printf("not similiar, adding %lld\n", hx*2-1); not_N += (hx) * 2 - 4; // substrings of length 1 and 2 which end in 'c' } hx = 0; x = 3; } else { ++x; } is_hard = false; } length += 1; } // add remaining group if (!is_hard) { not_N += t(x); } if (is_hard) { not_N += (hx) * 2 - 1; } //printf("%lld %lld\n", length, not_N); return t(length) - not_N; } int main() { scanf("%s", s); ll res = comp(s); printf("%lld\n", res); return 0; } |
English