#include<bits/stdc++.h> using namespace std; typedef long long int lld; int M[26]; vector<int> compress(const string& s){ vector<int> t(s.length()); for(int i=0;i<s.length();i++) t[i] = M[s[i]-'a']; return t; } int main(void){ ios_base::sync_with_stdio(false); M['a'-'a'] = 1; M['e'-'a'] = 1; M['o'-'a'] = 1; M['u'-'a'] = 1; M['i'-'a'] = 1; M['y'-'a'] = 1; string s; cin >> s; lld n = s.length(); vector<int> t = compress(s); t.push_back(0); for(int i=n-1;i>=0;i--) t[i] += t[i+1]; lld last = n; lld res = 0; for(int i=n-3;i>=0;i--){ if(t[i]%3 == t[i+3]%3) last = i+2; res += n-last; } cout << res << "\n"; 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 | #include<bits/stdc++.h> using namespace std; typedef long long int lld; int M[26]; vector<int> compress(const string& s){ vector<int> t(s.length()); for(int i=0;i<s.length();i++) t[i] = M[s[i]-'a']; return t; } int main(void){ ios_base::sync_with_stdio(false); M['a'-'a'] = 1; M['e'-'a'] = 1; M['o'-'a'] = 1; M['u'-'a'] = 1; M['i'-'a'] = 1; M['y'-'a'] = 1; string s; cin >> s; lld n = s.length(); vector<int> t = compress(s); t.push_back(0); for(int i=n-1;i>=0;i--) t[i] += t[i+1]; lld last = n; lld res = 0; for(int i=n-3;i>=0;i--){ if(t[i]%3 == t[i+3]%3) last = i+2; res += n-last; } cout << res << "\n"; return 0; } |