#include <iostream> #include <string> #include <vector> #include<bits/stdc++.h> using namespace std; string String; int Sum; int First; int Last = 0; int Length; int LengthSub; uint64_t Comp = 0; int CharTest(int aPos){ if( String[aPos]=='a'|| String[aPos]=='e'|| String[aPos]=='i'|| String[aPos]=='o'|| String[aPos]=='u'|| String[aPos]=='y'){ return 1; }else{ return -1; } } int Pre(int aPos){ int oResult = 0; int oEdge = aPos + 2; for(int oLoop=aPos;oLoop<oEdge;oLoop++){ oResult += CharTest(oLoop); } return oResult; }; void Brutal(){ uint16_t Count = 0; for(int oL1=0;oL1<LengthSub;oL1++){ int oSum = Pre(oL1); std::cout <<"Pre="<<oSum<<endl; for(int oL2=oL1+2;oL2<Length;oL2++){ oSum += CharTest(oL2); std::cout<<oSum<<" dodaje "<<String[oL2]<<endl; if (oSum==3||oSum==-3){ std::cout<<"pos="<<oL2-2<<" "<<oL2<<endl; Count += Length - oL2; break; } oSum -= CharTest(oL2-2); std::cout<<oSum<<" odejmuje"<<String[oL2-2]<<endl; } } std::cout << "Brutal="<<Count<<endl; } int FindBin(vector<int> aVec, int aVal){ int oLeft = 0; int oRigth = aVec.size()-1; int oMed = oLeft; while( oLeft <= oRigth){ oMed =( oLeft + oRigth) / 2; if(aVal == aVec[oMed]){ return oMed; } if( aVec[oMed]<aVal){ oLeft = oMed + 1; }else{ oRigth = oMed - 1; } } if(aVec[oMed]<aVal){ oMed++;}; return oMed; } vector<int> GenerateVector(vector<int> aVec){ Sum = Pre(0); for(int oLoop=2;oLoop<Length;oLoop++){ Sum += CharTest(oLoop); if(Sum==3||Sum==-3){ aVec.push_back(oLoop); } Sum -= CharTest(oLoop-2); }; aVec.push_back(INT_MAX); return aVec; } uint64_t FastCompute(vector<int> aVec){ uint64_t oSum = 0; for(int oLoop=2;oLoop<Length;oLoop++){ int oRes=aVec[FindBin(aVec,oLoop)]; if(oRes<Length){ oSum += Length-oRes; } } return oSum; } int main() { vector<int> vec; std::getline (std::cin,String); Length = String.length(); LengthSub = Length - 2; vec = GenerateVector(vec); std::cout << FastCompute(vec)<<endl; return 0; // Brutal(); // return 0; } /** abeeccаggoxxuuhhaalleerruucceettoonnaqaqaqaqaqaqaq Out: 0 In: trolujebolubie Out: 0 pokiegogrzybatrolujeszdzbanie 262 abeeccаggoxxuuhhaalleerruucceettoonnaqaqaqaqaqaqaq Out: 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 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 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 | #include <iostream> #include <string> #include <vector> #include<bits/stdc++.h> using namespace std; string String; int Sum; int First; int Last = 0; int Length; int LengthSub; uint64_t Comp = 0; int CharTest(int aPos){ if( String[aPos]=='a'|| String[aPos]=='e'|| String[aPos]=='i'|| String[aPos]=='o'|| String[aPos]=='u'|| String[aPos]=='y'){ return 1; }else{ return -1; } } int Pre(int aPos){ int oResult = 0; int oEdge = aPos + 2; for(int oLoop=aPos;oLoop<oEdge;oLoop++){ oResult += CharTest(oLoop); } return oResult; }; void Brutal(){ uint16_t Count = 0; for(int oL1=0;oL1<LengthSub;oL1++){ int oSum = Pre(oL1); std::cout <<"Pre="<<oSum<<endl; for(int oL2=oL1+2;oL2<Length;oL2++){ oSum += CharTest(oL2); std::cout<<oSum<<" dodaje "<<String[oL2]<<endl; if (oSum==3||oSum==-3){ std::cout<<"pos="<<oL2-2<<" "<<oL2<<endl; Count += Length - oL2; break; } oSum -= CharTest(oL2-2); std::cout<<oSum<<" odejmuje"<<String[oL2-2]<<endl; } } std::cout << "Brutal="<<Count<<endl; } int FindBin(vector<int> aVec, int aVal){ int oLeft = 0; int oRigth = aVec.size()-1; int oMed = oLeft; while( oLeft <= oRigth){ oMed =( oLeft + oRigth) / 2; if(aVal == aVec[oMed]){ return oMed; } if( aVec[oMed]<aVal){ oLeft = oMed + 1; }else{ oRigth = oMed - 1; } } if(aVec[oMed]<aVal){ oMed++;}; return oMed; } vector<int> GenerateVector(vector<int> aVec){ Sum = Pre(0); for(int oLoop=2;oLoop<Length;oLoop++){ Sum += CharTest(oLoop); if(Sum==3||Sum==-3){ aVec.push_back(oLoop); } Sum -= CharTest(oLoop-2); }; aVec.push_back(INT_MAX); return aVec; } uint64_t FastCompute(vector<int> aVec){ uint64_t oSum = 0; for(int oLoop=2;oLoop<Length;oLoop++){ int oRes=aVec[FindBin(aVec,oLoop)]; if(oRes<Length){ oSum += Length-oRes; } } return oSum; } int main() { vector<int> vec; std::getline (std::cin,String); Length = String.length(); LengthSub = Length - 2; vec = GenerateVector(vec); std::cout << FastCompute(vec)<<endl; return 0; // Brutal(); // return 0; } /** abeeccаggoxxuuhhaalleerruucceettoonnaqaqaqaqaqaqaq Out: 0 In: trolujebolubie Out: 0 pokiegogrzybatrolujeszdzbanie 262 abeeccаggoxxuuhhaalleerruucceettoonnaqaqaqaqaqaqaq Out: 0 */ |