#include <cstdio>
#include <iostream>
#include <cstring>
//#define dbgprint printf
#define dbgprint(...) //
using ULL = unsigned long long;
constexpr int MAX_LENGTH = 200010;
size_t length;
char str_raw[MAX_LENGTH];
bool hard[MAX_LENGTH];
bool isVowel(char c) {
return (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u' || c == 'y');
}
bool isVowel_s(int i) {
return isVowel(str_raw[i]);
}
bool is_hard_around_point(int point) {
if (point == 0 || point == length-1) {
return false;
}
return (isVowel_s(point) == isVowel_s(point-1)) && (isVowel_s(point) == isVowel_s(point+1));
}
ULL substrings_longer_than_two(int start, int end) {
auto len = static_cast<ULL>(end-start) + 1;
return (len*(len+1))/2 - len - (len-1);
}
int main() {
scanf("%s", str_raw);
length = std::strlen(str_raw);
dbgprint("%s\n", str_raw);
for (int i = 0; i < length; ++i) {
hard[i] = is_hard_around_point(i);
dbgprint("%d", hard[i]);
}
dbgprint("\n");
ULL ok_substrings = 0;
// last_ok - beginning of correct string
int last_ok = 0;
for (int i = 0; i < length; ++i) {
if (hard[i]) {
// hard[i] == true
// hard[i-1] == false
dbgprint("OK (%d %d) -> %d\n", last_ok, i, substrings_longer_than_two(last_ok, i));
ok_substrings += substrings_longer_than_two(last_ok, i);
// skip to next easy
while (i < length && hard[i]) {
++i;
}
last_ok = i - 1;
}
}
dbgprint("OK (%d %d) -> %d\n", last_ok, length-1, substrings_longer_than_two(last_ok, length-1));
ok_substrings += substrings_longer_than_two(last_ok, length-1);
dbgprint("OK: %llu\n", ok_substrings);
ULL result = substrings_longer_than_two(0, length-1) - ok_substrings;
printf("%llu\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 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 | #include <cstdio> #include <iostream> #include <cstring> //#define dbgprint printf #define dbgprint(...) // using ULL = unsigned long long; constexpr int MAX_LENGTH = 200010; size_t length; char str_raw[MAX_LENGTH]; bool hard[MAX_LENGTH]; bool isVowel(char c) { return (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u' || c == 'y'); } bool isVowel_s(int i) { return isVowel(str_raw[i]); } bool is_hard_around_point(int point) { if (point == 0 || point == length-1) { return false; } return (isVowel_s(point) == isVowel_s(point-1)) && (isVowel_s(point) == isVowel_s(point+1)); } ULL substrings_longer_than_two(int start, int end) { auto len = static_cast<ULL>(end-start) + 1; return (len*(len+1))/2 - len - (len-1); } int main() { scanf("%s", str_raw); length = std::strlen(str_raw); dbgprint("%s\n", str_raw); for (int i = 0; i < length; ++i) { hard[i] = is_hard_around_point(i); dbgprint("%d", hard[i]); } dbgprint("\n"); ULL ok_substrings = 0; // last_ok - beginning of correct string int last_ok = 0; for (int i = 0; i < length; ++i) { if (hard[i]) { // hard[i] == true // hard[i-1] == false dbgprint("OK (%d %d) -> %d\n", last_ok, i, substrings_longer_than_two(last_ok, i)); ok_substrings += substrings_longer_than_two(last_ok, i); // skip to next easy while (i < length && hard[i]) { ++i; } last_ok = i - 1; } } dbgprint("OK (%d %d) -> %d\n", last_ok, length-1, substrings_longer_than_two(last_ok, length-1)); ok_substrings += substrings_longer_than_two(last_ok, length-1); dbgprint("OK: %llu\n", ok_substrings); ULL result = substrings_longer_than_two(0, length-1) - ok_substrings; printf("%llu\n", result); return 0; } |
English