#include <bits/stdc++.h>
#define f first
#define s second
#define LL long long
#define ALL(V) V.begin(),V.end()
#define boost ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define endl "\n"
#define de(x) cout<<#x<<": "<<x<<endl
using namespace std;
const LL N=1e6+69, base=1024*1024,mod=1e9+7;
long long wynik;
string S;
bool lastThree(int v) {
int re=0;
for(int i=v-2;i<=v;i++) {
if(S[i]=='a') re++;
else if(S[i]=='e') re++;
else if(S[i]=='i') re++;
else if(S[i]=='o') re++;
else if(S[i]=='u') re++;
else if(S[i]=='y') re++;
}
if(re==3||re==0) return true;
return false;
}
int main(void) {
boost;
cin>>S;
int akt=0;
wynik=S.size();
wynik*=(wynik+1);
wynik/=2;
bool isBad = false;
for(int i=0;i<S.size();i++) {
while(akt + 1 < S.size() && (akt - i) < 1) akt++, isBad = false;
while(akt + 1 < S.size() && isBad == false && lastThree(akt+1) != true) akt++;
isBad = true;
wynik-=(akt-i+1);
}
cout<<wynik<<endl;
}
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 | #include <bits/stdc++.h> #define f first #define s second #define LL long long #define ALL(V) V.begin(),V.end() #define boost ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0) #define endl "\n" #define de(x) cout<<#x<<": "<<x<<endl using namespace std; const LL N=1e6+69, base=1024*1024,mod=1e9+7; long long wynik; string S; bool lastThree(int v) { int re=0; for(int i=v-2;i<=v;i++) { if(S[i]=='a') re++; else if(S[i]=='e') re++; else if(S[i]=='i') re++; else if(S[i]=='o') re++; else if(S[i]=='u') re++; else if(S[i]=='y') re++; } if(re==3||re==0) return true; return false; } int main(void) { boost; cin>>S; int akt=0; wynik=S.size(); wynik*=(wynik+1); wynik/=2; bool isBad = false; for(int i=0;i<S.size();i++) { while(akt + 1 < S.size() && (akt - i) < 1) akt++, isBad = false; while(akt + 1 < S.size() && isBad == false && lastThree(akt+1) != true) akt++; isBad = true; wynik-=(akt-i+1); } cout<<wynik<<endl; } |
English