Artifact Content
Not logged in

Artifact e8be027ce98cd7547437006ca12417ae7d758c0c


#include <iostream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <iterator>
#include <functional>
#include <complex>
#include <queue>
#include <stack>
#include <cmath>
#include <cassert>
#include <tuple>
using namespace std;
typedef long long LL;
typedef complex<double> 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 <ctime>
double start_time; string timer()
 { ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) << " msec)"; return os.str(); }
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v)
 { os << "{ ";
   for(typename vector<T>::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