#include <iostream>
#include <vector>
#include <string>
using namespace std;
typedef long long LL;
#define FOR(ii, ll, uu) for(int ii##lim = (uu), ii = (ll); ii < ii##lim; ++ii)
#define REP(ii, nn) FOR(ii, 0, nn)
#define FORL(ii, ll, uu) for(LL ii##lim = (uu), ii = (ll); ii < ii##lim; ++ii)
#define REPL(ii, nn) FOR(ii, 0, nn)
typedef LL cnt;
cnt subwords(int len)
{
return cnt(len) * cnt(len+1) / 2;
}
inline bool is_vowel(char c)
{
switch(c)
{
case 'a':
case 'e':
case 'i':
case 'o':
case 'u':
case 'y':
return true;
default:
return false;
}
}
template <class T>
ostream& operator<<(ostream& o, const std::vector<T>& x)
{
o << '[';
if (!x.empty())
o << x[0];
FOR(i, 1, x.size())
o << ", " << x[i];
return o << ']';
}
int main()
{
string wishes;
cin >> wishes;
int n = wishes.size();
vector<int> vowel;
vowel.reserve(wishes.size());
for (auto c : wishes)
{
vowel.push_back(is_vowel(c));
}
vector<int> limits;
limits.push_back(0);
FOR(i, 1, n-1)
{
if (vowel[i-1] == vowel[i] && vowel[i] == vowel[i+1])
{
limits.push_back(i);
}
}
limits.push_back(n-1);
cnt all = subwords(n);
cnt good = 0;
REP(i, limits.size()-1)
{
good += subwords(limits[i+1] - limits[i] + 1);
}
good -= limits.size() - 2;
cnt bad = all - good;
// cout << limits << all << ' ' << good << ' ' << all - good << endl;
cout << bad << 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 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 | #include <iostream> #include <vector> #include <string> using namespace std; typedef long long LL; #define FOR(ii, ll, uu) for(int ii##lim = (uu), ii = (ll); ii < ii##lim; ++ii) #define REP(ii, nn) FOR(ii, 0, nn) #define FORL(ii, ll, uu) for(LL ii##lim = (uu), ii = (ll); ii < ii##lim; ++ii) #define REPL(ii, nn) FOR(ii, 0, nn) typedef LL cnt; cnt subwords(int len) { return cnt(len) * cnt(len+1) / 2; } inline bool is_vowel(char c) { switch(c) { case 'a': case 'e': case 'i': case 'o': case 'u': case 'y': return true; default: return false; } } template <class T> ostream& operator<<(ostream& o, const std::vector<T>& x) { o << '['; if (!x.empty()) o << x[0]; FOR(i, 1, x.size()) o << ", " << x[i]; return o << ']'; } int main() { string wishes; cin >> wishes; int n = wishes.size(); vector<int> vowel; vowel.reserve(wishes.size()); for (auto c : wishes) { vowel.push_back(is_vowel(c)); } vector<int> limits; limits.push_back(0); FOR(i, 1, n-1) { if (vowel[i-1] == vowel[i] && vowel[i] == vowel[i+1]) { limits.push_back(i); } } limits.push_back(n-1); cnt all = subwords(n); cnt good = 0; REP(i, limits.size()-1) { good += subwords(limits[i+1] - limits[i] + 1); } good -= limits.size() - 2; cnt bad = all - good; // cout << limits << all << ' ' << good << ' ' << all - good << endl; cout << bad << endl; return 0; } |
English