ADDED SRM/591-U/1A.cpp Index: SRM/591-U/1A.cpp ================================================================== --- SRM/591-U/1A.cpp +++ SRM/591-U/1A.cpp @@ -0,0 +1,94 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +using namespace std; +typedef long long LL; +typedef complex CMP; + +class LittleElephantAndBalls { public: + int getNumber(string S) + { + int score = 0; + + char chars[]="RGB"; + + int left[128]={}, right[128]={}; + for(char c : S) + { + for(char x: chars) + score += left[x]+right[x]; + if(!left[c]) + left[c]++; + else if (!right[c]) + right[c]++; + } + return score; + } +}; + +// BEGIN CUT HERE +#include +double start_time; string timer() + { ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) << " msec)"; return os.str(); } +template ostream& operator<<(ostream& os, const vector& v) + { os << "{ "; + for(typename vector::const_iterator it=v.begin(); it!=v.end(); ++it) + os << '\"' << *it << '\"' << (it+1==v.end() ? "" : ", "); os << " }"; return os; } +void verify_case(const int& Expected, const int& Received) { + bool ok = (Expected == Received); + if(ok) cerr << "PASSED" << timer() << endl; else { cerr << "FAILED" << timer() << endl; + cerr << "\to: \"" << Expected << '\"' << endl << "\tx: \"" << Received << '\"' << endl; } } +#define CASE(N) {cerr << "Test Case #" << N << "..." << flush; start_time=clock(); +#define END verify_case(_, LittleElephantAndBalls().getNumber(S));} +int main(){ + +CASE(0) + string S = "RGB"; + int _ = 3; +END +CASE(1) + string S = "RGGRBBB"; + int _ = 21; +END +CASE(2) + string S = "RRRGBRR"; + int _ = 16; +END +CASE(3) + string S = "RRRR"; + int _ = 5; +END +CASE(4) + string S = "GGRRRGR"; + int _ = 18; +END +CASE(5) + string S = "G"; + int _ = 0; +END +/* +CASE(6) + string S = ; + int _ = ; +END +CASE(7) + string S = ; + int _ = ; +END +*/ +} +// END CUT HERE