#include <bits/stdc++.h> using namespace std; #define e1 first #define e2 second #define pb push_back #define mp make_pair #define boost ios_base::sync_with_stdio(false) #define eb emplace_back #define OUT(x) {cout << x; exit(0); } #define FOR(i, a, b) for (int i=(a); i<=(b); ++i) typedef long long ll; typedef unsigned long long ull; typedef pair <int, int> PII; typedef pair <ll, ll> PLL; typedef pair <PLL, PLL> PP; typedef unsigned int ui; const int mod = 1e9+7; const int inf = 1e9+9; const ll MOD = 1e9+696969; const ll INF = 1e18; int a, wyn = 0; string s; const int maxn = 300100; int dp[maxn]; inline bool sam(int pos) { return (s[pos] == 'a' || s[pos] == 'e' || s[pos] == 'i' || s[pos] == 'y' || s[pos] == 'u' || s[pos] == 'o'); } int main() { boost; cin >> s; int n = s.length(); dp[0] = 1; dp[1] = 2; ll res = 0; for (int i=2; i<n; ++i) { if (sam(i) && sam(i-1) && sam(i-2)) dp[i] = 2; else if (!sam(i) && !sam(i-1) && !sam(i-2)) dp[i] = 2; else dp[i] = dp[i - 1] + 1; } //for (int i=0; i<n; ++i) cout << dp[i] << ' '; //cout << endl; for (int i=0; i<n; ++i) res += dp[i]; ll N = n; cout << N * (N + 1) / 2LL - res; }
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 | #include <bits/stdc++.h> using namespace std; #define e1 first #define e2 second #define pb push_back #define mp make_pair #define boost ios_base::sync_with_stdio(false) #define eb emplace_back #define OUT(x) {cout << x; exit(0); } #define FOR(i, a, b) for (int i=(a); i<=(b); ++i) typedef long long ll; typedef unsigned long long ull; typedef pair <int, int> PII; typedef pair <ll, ll> PLL; typedef pair <PLL, PLL> PP; typedef unsigned int ui; const int mod = 1e9+7; const int inf = 1e9+9; const ll MOD = 1e9+696969; const ll INF = 1e18; int a, wyn = 0; string s; const int maxn = 300100; int dp[maxn]; inline bool sam(int pos) { return (s[pos] == 'a' || s[pos] == 'e' || s[pos] == 'i' || s[pos] == 'y' || s[pos] == 'u' || s[pos] == 'o'); } int main() { boost; cin >> s; int n = s.length(); dp[0] = 1; dp[1] = 2; ll res = 0; for (int i=2; i<n; ++i) { if (sam(i) && sam(i-1) && sam(i-2)) dp[i] = 2; else if (!sam(i) && !sam(i-1) && !sam(i-2)) dp[i] = 2; else dp[i] = dp[i - 1] + 1; } //for (int i=0; i<n; ++i) cout << dp[i] << ' '; //cout << endl; for (int i=0; i<n; ++i) res += dp[i]; ll N = n; cout << N * (N + 1) / 2LL - res; } |