51e0369b55 2013-10-05 kinaba: #include <iostream> 51e0369b55 2013-10-05 kinaba: #include <sstream> 51e0369b55 2013-10-05 kinaba: #include <iomanip> 51e0369b55 2013-10-05 kinaba: #include <vector> 51e0369b55 2013-10-05 kinaba: #include <string> 51e0369b55 2013-10-05 kinaba: #include <map> 51e0369b55 2013-10-05 kinaba: #include <set> 51e0369b55 2013-10-05 kinaba: #include <algorithm> 51e0369b55 2013-10-05 kinaba: #include <numeric> 51e0369b55 2013-10-05 kinaba: #include <iterator> 51e0369b55 2013-10-05 kinaba: #include <functional> 51e0369b55 2013-10-05 kinaba: #include <complex> 51e0369b55 2013-10-05 kinaba: #include <queue> 51e0369b55 2013-10-05 kinaba: #include <stack> 51e0369b55 2013-10-05 kinaba: #include <cmath> 51e0369b55 2013-10-05 kinaba: #include <cassert> 51e0369b55 2013-10-05 kinaba: #include <tuple> 51e0369b55 2013-10-05 kinaba: using namespace std; 51e0369b55 2013-10-05 kinaba: typedef long long LL; 51e0369b55 2013-10-05 kinaba: typedef complex<double> CMP; 51e0369b55 2013-10-05 kinaba: 51e0369b55 2013-10-05 kinaba: class LittleElephantAndBalls { public: 51e0369b55 2013-10-05 kinaba: int getNumber(string S) 51e0369b55 2013-10-05 kinaba: { 51e0369b55 2013-10-05 kinaba: int score = 0; 51e0369b55 2013-10-05 kinaba: 51e0369b55 2013-10-05 kinaba: char chars[]="RGB"; 51e0369b55 2013-10-05 kinaba: 51e0369b55 2013-10-05 kinaba: int left[128]={}, right[128]={}; 51e0369b55 2013-10-05 kinaba: for(char c : S) 51e0369b55 2013-10-05 kinaba: { 51e0369b55 2013-10-05 kinaba: for(char x: chars) 51e0369b55 2013-10-05 kinaba: score += left[x]+right[x]; 51e0369b55 2013-10-05 kinaba: if(!left[c]) 51e0369b55 2013-10-05 kinaba: left[c]++; 51e0369b55 2013-10-05 kinaba: else if (!right[c]) 51e0369b55 2013-10-05 kinaba: right[c]++; 51e0369b55 2013-10-05 kinaba: } 51e0369b55 2013-10-05 kinaba: return score; 51e0369b55 2013-10-05 kinaba: } 51e0369b55 2013-10-05 kinaba: }; 51e0369b55 2013-10-05 kinaba: 51e0369b55 2013-10-05 kinaba: // BEGIN CUT HERE 51e0369b55 2013-10-05 kinaba: #include <ctime> 51e0369b55 2013-10-05 kinaba: double start_time; string timer() 51e0369b55 2013-10-05 kinaba: { ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) << " msec)"; return os.str(); } 51e0369b55 2013-10-05 kinaba: template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) 51e0369b55 2013-10-05 kinaba: { os << "{ "; 51e0369b55 2013-10-05 kinaba: for(typename vector<T>::const_iterator it=v.begin(); it!=v.end(); ++it) 51e0369b55 2013-10-05 kinaba: os << '\"' << *it << '\"' << (it+1==v.end() ? "" : ", "); os << " }"; return os; } 51e0369b55 2013-10-05 kinaba: void verify_case(const int& Expected, const int& Received) { 51e0369b55 2013-10-05 kinaba: bool ok = (Expected == Received); 51e0369b55 2013-10-05 kinaba: if(ok) cerr << "PASSED" << timer() << endl; else { cerr << "FAILED" << timer() << endl; 51e0369b55 2013-10-05 kinaba: cerr << "\to: \"" << Expected << '\"' << endl << "\tx: \"" << Received << '\"' << endl; } } 51e0369b55 2013-10-05 kinaba: #define CASE(N) {cerr << "Test Case #" << N << "..." << flush; start_time=clock(); 51e0369b55 2013-10-05 kinaba: #define END verify_case(_, LittleElephantAndBalls().getNumber(S));} 51e0369b55 2013-10-05 kinaba: int main(){ 51e0369b55 2013-10-05 kinaba: 51e0369b55 2013-10-05 kinaba: CASE(0) 51e0369b55 2013-10-05 kinaba: string S = "RGB"; 51e0369b55 2013-10-05 kinaba: int _ = 3; 51e0369b55 2013-10-05 kinaba: END 51e0369b55 2013-10-05 kinaba: CASE(1) 51e0369b55 2013-10-05 kinaba: string S = "RGGRBBB"; 51e0369b55 2013-10-05 kinaba: int _ = 21; 51e0369b55 2013-10-05 kinaba: END 51e0369b55 2013-10-05 kinaba: CASE(2) 51e0369b55 2013-10-05 kinaba: string S = "RRRGBRR"; 51e0369b55 2013-10-05 kinaba: int _ = 16; 51e0369b55 2013-10-05 kinaba: END 51e0369b55 2013-10-05 kinaba: CASE(3) 51e0369b55 2013-10-05 kinaba: string S = "RRRR"; 51e0369b55 2013-10-05 kinaba: int _ = 5; 51e0369b55 2013-10-05 kinaba: END 51e0369b55 2013-10-05 kinaba: CASE(4) 51e0369b55 2013-10-05 kinaba: string S = "GGRRRGR"; 51e0369b55 2013-10-05 kinaba: int _ = 18; 51e0369b55 2013-10-05 kinaba: END 51e0369b55 2013-10-05 kinaba: CASE(5) 51e0369b55 2013-10-05 kinaba: string S = "G"; 51e0369b55 2013-10-05 kinaba: int _ = 0; 51e0369b55 2013-10-05 kinaba: END 51e0369b55 2013-10-05 kinaba: /* 51e0369b55 2013-10-05 kinaba: CASE(6) 51e0369b55 2013-10-05 kinaba: string S = ; 51e0369b55 2013-10-05 kinaba: int _ = ; 51e0369b55 2013-10-05 kinaba: END 51e0369b55 2013-10-05 kinaba: CASE(7) 51e0369b55 2013-10-05 kinaba: string S = ; 51e0369b55 2013-10-05 kinaba: int _ = ; 51e0369b55 2013-10-05 kinaba: END 51e0369b55 2013-10-05 kinaba: */ 51e0369b55 2013-10-05 kinaba: } 51e0369b55 2013-10-05 kinaba: // END CUT HERE