90dd89d9af 2012-03-17 kinaba: #include <iostream> 90dd89d9af 2012-03-17 kinaba: #include <sstream> 90dd89d9af 2012-03-17 kinaba: #include <iomanip> 90dd89d9af 2012-03-17 kinaba: #include <vector> 90dd89d9af 2012-03-17 kinaba: #include <string> 90dd89d9af 2012-03-17 kinaba: #include <map> 90dd89d9af 2012-03-17 kinaba: #include <set> 90dd89d9af 2012-03-17 kinaba: #include <algorithm> 90dd89d9af 2012-03-17 kinaba: #include <numeric> 90dd89d9af 2012-03-17 kinaba: #include <iterator> 90dd89d9af 2012-03-17 kinaba: #include <functional> 90dd89d9af 2012-03-17 kinaba: #include <complex> 90dd89d9af 2012-03-17 kinaba: #include <queue> 90dd89d9af 2012-03-17 kinaba: #include <stack> 90dd89d9af 2012-03-17 kinaba: #include <cmath> 90dd89d9af 2012-03-17 kinaba: #include <cassert> 90dd89d9af 2012-03-17 kinaba: #include <cstring> 90dd89d9af 2012-03-17 kinaba: #ifdef __GNUC__ 90dd89d9af 2012-03-17 kinaba: #include <ext/hash_map> 90dd89d9af 2012-03-17 kinaba: #define unordered_map __gnu_cxx::hash_map 90dd89d9af 2012-03-17 kinaba: #else 90dd89d9af 2012-03-17 kinaba: #include <unordered_map> 90dd89d9af 2012-03-17 kinaba: #endif 90dd89d9af 2012-03-17 kinaba: using namespace std; 90dd89d9af 2012-03-17 kinaba: typedef long long LL; 90dd89d9af 2012-03-17 kinaba: typedef complex<double> CMP; 90dd89d9af 2012-03-17 kinaba: 90dd89d9af 2012-03-17 kinaba: class RollingDiceDivOne { public: 90dd89d9af 2012-03-17 kinaba: long long mostLikely(vector <int> dice) 90dd89d9af 2012-03-17 kinaba: { 90dd89d9af 2012-03-17 kinaba: sort(dice.begin(), dice.end()); 90dd89d9af 2012-03-17 kinaba: if( dice.size() == 1 ) 90dd89d9af 2012-03-17 kinaba: return 1; 90dd89d9af 2012-03-17 kinaba: 90dd89d9af 2012-03-17 kinaba: 90dd89d9af 2012-03-17 kinaba: LL m2sum = 0; 90dd89d9af 2012-03-17 kinaba: for(int i=0; i<dice.size(); ++i) 90dd89d9af 2012-03-17 kinaba: m2sum += dice[i]+1; 90dd89d9af 2012-03-17 kinaba: LL v = m2sum / 2; 90dd89d9af 2012-03-17 kinaba: return v; 90dd89d9af 2012-03-17 kinaba: } 90dd89d9af 2012-03-17 kinaba: }; 90dd89d9af 2012-03-17 kinaba: 90dd89d9af 2012-03-17 kinaba: // BEGIN CUT HERE 90dd89d9af 2012-03-17 kinaba: #include <ctime> 90dd89d9af 2012-03-17 kinaba: double start_time; string timer() 90dd89d9af 2012-03-17 kinaba: { ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) << " msec)"; return os.str(); } 90dd89d9af 2012-03-17 kinaba: template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) 90dd89d9af 2012-03-17 kinaba: { os << "{ "; 90dd89d9af 2012-03-17 kinaba: for(typename vector<T>::const_iterator it=v.begin(); it!=v.end(); ++it) 90dd89d9af 2012-03-17 kinaba: os << '\"' << *it << '\"' << (it+1==v.end() ? "" : ", "); os << " }"; return os; } 90dd89d9af 2012-03-17 kinaba: void verify_case(const long long& Expected, const long long& Received) { 90dd89d9af 2012-03-17 kinaba: bool ok = (Expected == Received); 90dd89d9af 2012-03-17 kinaba: if(ok) cerr << "PASSED" << timer() << endl; else { cerr << "FAILED" << timer() << endl; 90dd89d9af 2012-03-17 kinaba: cerr << "\to: \"" << Expected << '\"' << endl << "\tx: \"" << Received << '\"' << endl; } } 90dd89d9af 2012-03-17 kinaba: #define CASE(N) {cerr << "Test Case #" << N << "..." << flush; start_time=clock(); 90dd89d9af 2012-03-17 kinaba: #define END verify_case(_, RollingDiceDivOne().mostLikely(dice));} 90dd89d9af 2012-03-17 kinaba: int main(){ 90dd89d9af 2012-03-17 kinaba: 90dd89d9af 2012-03-17 kinaba: CASE(0) 90dd89d9af 2012-03-17 kinaba: int dice_[] = {6, 6, 8}; 90dd89d9af 2012-03-17 kinaba: vector <int> dice(dice_, dice_+sizeof(dice_)/sizeof(*dice_)); 90dd89d9af 2012-03-17 kinaba: long long _ = 11LL; 90dd89d9af 2012-03-17 kinaba: END 90dd89d9af 2012-03-17 kinaba: CASE(1) 90dd89d9af 2012-03-17 kinaba: int dice_[] = {10}; 90dd89d9af 2012-03-17 kinaba: vector <int> dice(dice_, dice_+sizeof(dice_)/sizeof(*dice_)); 90dd89d9af 2012-03-17 kinaba: long long _ = 1LL; 90dd89d9af 2012-03-17 kinaba: END 90dd89d9af 2012-03-17 kinaba: CASE(2) 90dd89d9af 2012-03-17 kinaba: int dice_[] = {2, 3, 4, 5}; 90dd89d9af 2012-03-17 kinaba: vector <int> dice(dice_, dice_+sizeof(dice_)/sizeof(*dice_)); 90dd89d9af 2012-03-17 kinaba: long long _ = 9LL; 90dd89d9af 2012-03-17 kinaba: END 90dd89d9af 2012-03-17 kinaba: CASE(3) 90dd89d9af 2012-03-17 kinaba: int dice_[] = {1, 10, 1}; 90dd89d9af 2012-03-17 kinaba: vector <int> dice(dice_, dice_+sizeof(dice_)/sizeof(*dice_)); 90dd89d9af 2012-03-17 kinaba: long long _ = 3LL; 90dd89d9af 2012-03-17 kinaba: END 90dd89d9af 2012-03-17 kinaba: CASE(4) 90dd89d9af 2012-03-17 kinaba: int dice_[] = {382828264, 942663792, 291832707, 887961277, 546603677, 545185615, 146267547, 6938117, 167567032, 84232402, 90dd89d9af 2012-03-17 kinaba: 700781193, 452172304, 816532384, 951089120, 448136091, 280899512, 256093435, 39595226, 631504901, 154772240}; 90dd89d9af 2012-03-17 kinaba: vector <int> dice(dice_, dice_+sizeof(dice_)/sizeof(*dice_)); 90dd89d9af 2012-03-17 kinaba: long long _ = 4366828428LL; 90dd89d9af 2012-03-17 kinaba: END 90dd89d9af 2012-03-17 kinaba: CASE(5) 90dd89d9af 2012-03-17 kinaba: int dice_[] = {686070183,764446558,958676845,711114086,307405925,18345836,534933273,884410953,402311475,699530578,734067293,586174895,653276411,461102667,361634525,515961596,53576037,909418211,678589501,398850606,279452824,544186770,203263120,85451598,330889574,93199510,730144410,620028986,247001511,285471536,706978584,976668932,10197700,550812603,440712526,127306784,280595874,519698127,482194343,519518638,680491824,236933627,69469348,993453692,817501995,678439028,166742435,200336684,724838900,525355524}; 90dd89d9af 2012-03-17 kinaba: vector <int> dice(dice_, dice_+sizeof(dice_)/sizeof(*dice_)); 90dd89d9af 2012-03-17 kinaba: long long _ = -1LL; 90dd89d9af 2012-03-17 kinaba: END 90dd89d9af 2012-03-17 kinaba: CASE(6) 90dd89d9af 2012-03-17 kinaba: int dice_[] = {1}; 90dd89d9af 2012-03-17 kinaba: vector <int> dice(dice_, dice_+sizeof(dice_)/sizeof(*dice_)); 90dd89d9af 2012-03-17 kinaba: long long _ = 1LL; 90dd89d9af 2012-03-17 kinaba: END 90dd89d9af 2012-03-17 kinaba: 90dd89d9af 2012-03-17 kinaba: } 90dd89d9af 2012-03-17 kinaba: // END CUT HERE