/////////////////////////////////
//////**DOMINIK___KOWALCZYK**////
/////////////////////////////////
#include <bits/stdc++.h>
using namespace std;
#define boost ios_base::sync_with_stdio(0);
#define all(a) (a).begin(),(a).end()
#define sz(a) (int)(a).size()
#define ELO exit(0)
typedef long long ll;
bool samogloska(char a)
{
return (a == 'a' or a == 'e' or a == 'i' or a == 'o' or a == 'u' or a == 'y');
}
int main()
{
boost;
string s;
cin >> s;
ll res = 1ll * sz(s) * (sz(s) - 1) / 2;
vector<int> bad(sz(s));
for (int i = 2; i < sz(s); i++)
{
if (samogloska(s[i]) == samogloska(s[i - 1]) and
samogloska(s[i]) == samogloska(s[i - 2]))
{
bad[i] = bad[i - 1] = bad[i - 2] = samogloska(s[i]) + 1;
}
}
vector<pair<int, int> > tab;
int i = 0;
while (i < sz(s))
{
int dl = 1;
while (i + 1 < sz(s) and bad[i] == bad[i + 1])dl++, i++;
tab.push_back({dl, bad[i]});
i++;
}
for (i = 0 ; i < sz(tab); i++)
{
if (tab[i].second == 0)
{
res -= 1ll * tab[i].first * (tab[i].first - 1) / 2;
}
else
{
res -= tab[i].first - 1;
if (i > 0 and tab[i - 1].second == 0)
{
res -= 2 * tab[i - 1].first;
}
if (i + 1 < sz(tab) and tab[i + 1].second == 0)
{
res -= 2 * tab[i + 1].first;
if (i + 2 < sz(tab))
{
res -= 4;
}
}
if (i + 1 < sz(tab) and tab[i + 1].second != 0)
{
res -= 4;
}
}
}
cout << res;
ELO;
}
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 | ///////////////////////////////// //////**DOMINIK___KOWALCZYK**//// ///////////////////////////////// #include <bits/stdc++.h> using namespace std; #define boost ios_base::sync_with_stdio(0); #define all(a) (a).begin(),(a).end() #define sz(a) (int)(a).size() #define ELO exit(0) typedef long long ll; bool samogloska(char a) { return (a == 'a' or a == 'e' or a == 'i' or a == 'o' or a == 'u' or a == 'y'); } int main() { boost; string s; cin >> s; ll res = 1ll * sz(s) * (sz(s) - 1) / 2; vector<int> bad(sz(s)); for (int i = 2; i < sz(s); i++) { if (samogloska(s[i]) == samogloska(s[i - 1]) and samogloska(s[i]) == samogloska(s[i - 2])) { bad[i] = bad[i - 1] = bad[i - 2] = samogloska(s[i]) + 1; } } vector<pair<int, int> > tab; int i = 0; while (i < sz(s)) { int dl = 1; while (i + 1 < sz(s) and bad[i] == bad[i + 1])dl++, i++; tab.push_back({dl, bad[i]}); i++; } for (i = 0 ; i < sz(tab); i++) { if (tab[i].second == 0) { res -= 1ll * tab[i].first * (tab[i].first - 1) / 2; } else { res -= tab[i].first - 1; if (i > 0 and tab[i - 1].second == 0) { res -= 2 * tab[i - 1].first; } if (i + 1 < sz(tab) and tab[i + 1].second == 0) { res -= 2 * tab[i + 1].first; if (i + 2 < sz(tab)) { res -= 4; } } if (i + 1 < sz(tab) and tab[i + 1].second != 0) { res -= 4; } } } cout << res; ELO; } |
English