#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <cstdlib>
#include <stdint.h>
#include <string>
int brute(const std::string& str) {
std::vector<char> type(256);
for (auto& c : "aeiouy") {
type[c] = 1;
}
int res = 0;
for (int i = 0; i < str.size(); i++) {
for (int j = i + 2; j < str.size(); j++) {
bool ok = false;
for (int k = i; k <= j - 2; k++) {
char t = type[str[k]];
if (t == type[str[k + 1]] && t == type[str[k + 2]]) {
ok = true;
break;
}
}
if (ok) {
res++;
}
}
}
return res;
}
int64_t solve(std::string& str) {
std::vector<char> type(256);
for (auto& c : "aeiouy") {
type[c] = 1;
}
int64_t res = 0;
int cur_type = -1;
int cur_cnt = 0;
int start = 0;
for (int i = 0; i < str.size(); i++) {
char t = type[str[i]];
if (cur_type == t) {
cur_cnt++;
} else {
cur_cnt = 1;
cur_type = t;
}
if (cur_cnt >= 3) {
start = i - 1;
}
res += i - start + 1;
}
res = (str.size()) * int64_t(str.size() + 1) / 2 - res;
return res;
}
int main(int argc, char** argv) {
std::ios_base::sync_with_stdio(0);
std::string line;
std::getline(std::cin, line);
std::cout << solve(line) << std::endl;
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 | #include <iostream> #include <algorithm> #include <cmath> #include <vector> #include <cstdlib> #include <stdint.h> #include <string> int brute(const std::string& str) { std::vector<char> type(256); for (auto& c : "aeiouy") { type[c] = 1; } int res = 0; for (int i = 0; i < str.size(); i++) { for (int j = i + 2; j < str.size(); j++) { bool ok = false; for (int k = i; k <= j - 2; k++) { char t = type[str[k]]; if (t == type[str[k + 1]] && t == type[str[k + 2]]) { ok = true; break; } } if (ok) { res++; } } } return res; } int64_t solve(std::string& str) { std::vector<char> type(256); for (auto& c : "aeiouy") { type[c] = 1; } int64_t res = 0; int cur_type = -1; int cur_cnt = 0; int start = 0; for (int i = 0; i < str.size(); i++) { char t = type[str[i]]; if (cur_type == t) { cur_cnt++; } else { cur_cnt = 1; cur_type = t; } if (cur_cnt >= 3) { start = i - 1; } res += i - start + 1; } res = (str.size()) * int64_t(str.size() + 1) / 2 - res; return res; } int main(int argc, char** argv) { std::ios_base::sync_with_stdio(0); std::string line; std::getline(std::cin, line); std::cout << solve(line) << std::endl; return 0; } |
English