#include <iostream> #include <cstdint> #include <string> #define NEWL std::cout << '\n'; #define PRINT(var) std::cout << #var << " = " << var << "\n"; typedef int64_t int64; typedef int32_t int32; typedef int8_t int8; const int64 MAX_N = 200001; int64 n, gain, streak, iter, t; int8 last, arr[MAX_N]; std::string inputRaw; inline int8 readOne(char c){ static char vowels[] = "aeiouy"; for(int8 i=0; i<6; i++){ if(vowels[i] == c){return 1;} } return 2; } int64 sum(int64 v){return v*(v+1)/2;} int main(){ std::ios_base::sync_with_stdio(0); std::cin >> inputRaw; n = inputRaw.length(); for(int32 i=0; i < n; i++){arr[i] = readOne(inputRaw[i]);} gain = -1; while(iter < n){ if(arr[iter] == last){ streak++; } else{ streak = 0; last = arr[iter]; } if(streak == 2){ int64 k = 0, iter_ = iter; iter++; while(iter < n && arr[iter] == last){iter++; k++;} last = arr[iter]; t += gain*(n-iter_) + k*n - k*iter_ - sum(k); streak = 0; gain =1; } gain++; iter++; } std::cout << t; }
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 | #include <iostream> #include <cstdint> #include <string> #define NEWL std::cout << '\n'; #define PRINT(var) std::cout << #var << " = " << var << "\n"; typedef int64_t int64; typedef int32_t int32; typedef int8_t int8; const int64 MAX_N = 200001; int64 n, gain, streak, iter, t; int8 last, arr[MAX_N]; std::string inputRaw; inline int8 readOne(char c){ static char vowels[] = "aeiouy"; for(int8 i=0; i<6; i++){ if(vowels[i] == c){return 1;} } return 2; } int64 sum(int64 v){return v*(v+1)/2;} int main(){ std::ios_base::sync_with_stdio(0); std::cin >> inputRaw; n = inputRaw.length(); for(int32 i=0; i < n; i++){arr[i] = readOne(inputRaw[i]);} gain = -1; while(iter < n){ if(arr[iter] == last){ streak++; } else{ streak = 0; last = arr[iter]; } if(streak == 2){ int64 k = 0, iter_ = iter; iter++; while(iter < n && arr[iter] == last){iter++; k++;} last = arr[iter]; t += gain*(n-iter_) + k*n - k*iter_ - sum(k); streak = 0; gain =1; } gain++; iter++; } std::cout << t; } |