Check-in [51e0369b55]
Not logged in
Overview
SHA1 Hash:51e0369b55b47b2e4f085e0c69af0c05c7020482
Date: 2013-10-05 15:09:23
User: kinaba
Comment:591
Timelines: family | ancestors | descendants | both | trunk
Downloads: Tarball | ZIP archive
Other Links: files | file ages | manifest
Tags And Properties
Changes

Added SRM/591-U/1A.cpp version [e8be027ce98cd754]

1 +#include <iostream> 2 +#include <sstream> 3 +#include <iomanip> 4 +#include <vector> 5 +#include <string> 6 +#include <map> 7 +#include <set> 8 +#include <algorithm> 9 +#include <numeric> 10 +#include <iterator> 11 +#include <functional> 12 +#include <complex> 13 +#include <queue> 14 +#include <stack> 15 +#include <cmath> 16 +#include <cassert> 17 +#include <tuple> 18 +using namespace std; 19 +typedef long long LL; 20 +typedef complex<double> CMP; 21 + 22 +class LittleElephantAndBalls { public: 23 + int getNumber(string S) 24 + { 25 + int score = 0; 26 + 27 + char chars[]="RGB"; 28 + 29 + int left[128]={}, right[128]={}; 30 + for(char c : S) 31 + { 32 + for(char x: chars) 33 + score += left[x]+right[x]; 34 + if(!left[c]) 35 + left[c]++; 36 + else if (!right[c]) 37 + right[c]++; 38 + } 39 + return score; 40 + } 41 +}; 42 + 43 +// BEGIN CUT HERE 44 +#include <ctime> 45 +double start_time; string timer() 46 + { ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) << " msec)"; return os.str(); } 47 +template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) 48 + { os << "{ "; 49 + for(typename vector<T>::const_iterator it=v.begin(); it!=v.end(); ++it) 50 + os << '\"' << *it << '\"' << (it+1==v.end() ? "" : ", "); os << " }"; return os; } 51 +void verify_case(const int& Expected, const int& Received) { 52 + bool ok = (Expected == Received); 53 + if(ok) cerr << "PASSED" << timer() << endl; else { cerr << "FAILED" << timer() << endl; 54 + cerr << "\to: \"" << Expected << '\"' << endl << "\tx: \"" << Received << '\"' << endl; } } 55 +#define CASE(N) {cerr << "Test Case #" << N << "..." << flush; start_time=clock(); 56 +#define END verify_case(_, LittleElephantAndBalls().getNumber(S));} 57 +int main(){ 58 + 59 +CASE(0) 60 + string S = "RGB"; 61 + int _ = 3; 62 +END 63 +CASE(1) 64 + string S = "RGGRBBB"; 65 + int _ = 21; 66 +END 67 +CASE(2) 68 + string S = "RRRGBRR"; 69 + int _ = 16; 70 +END 71 +CASE(3) 72 + string S = "RRRR"; 73 + int _ = 5; 74 +END 75 +CASE(4) 76 + string S = "GGRRRGR"; 77 + int _ = 18; 78 +END 79 +CASE(5) 80 + string S = "G"; 81 + int _ = 0; 82 +END 83 +/* 84 +CASE(6) 85 + string S = ; 86 + int _ = ; 87 +END 88 +CASE(7) 89 + string S = ; 90 + int _ = ; 91 +END 92 +*/ 93 +} 94 +// END CUT HERE