4fd800b3a8 2011-02-23 kinaba: #include <iostream> 4fd800b3a8 2011-02-23 kinaba: #include <sstream> 4fd800b3a8 2011-02-23 kinaba: #include <iomanip> 4fd800b3a8 2011-02-23 kinaba: #include <vector> 4fd800b3a8 2011-02-23 kinaba: #include <string> 4fd800b3a8 2011-02-23 kinaba: #include <map> 4fd800b3a8 2011-02-23 kinaba: #include <set> 4fd800b3a8 2011-02-23 kinaba: #include <algorithm> 4fd800b3a8 2011-02-23 kinaba: #include <numeric> 4fd800b3a8 2011-02-23 kinaba: #include <iterator> 4fd800b3a8 2011-02-23 kinaba: #include <functional> 4fd800b3a8 2011-02-23 kinaba: #include <complex> 4fd800b3a8 2011-02-23 kinaba: #include <queue> 4fd800b3a8 2011-02-23 kinaba: #include <stack> 4fd800b3a8 2011-02-23 kinaba: #include <cmath> 4fd800b3a8 2011-02-23 kinaba: #include <cassert> 4fd800b3a8 2011-02-23 kinaba: #include <cstring> 4fd800b3a8 2011-02-23 kinaba: using namespace std; 4fd800b3a8 2011-02-23 kinaba: typedef long long LL; 4fd800b3a8 2011-02-23 kinaba: typedef complex<double> CMP; 4fd800b3a8 2011-02-23 kinaba: 4fd800b3a8 2011-02-23 kinaba: class TheBoringGameDivOne { public: 4fd800b3a8 2011-02-23 kinaba: vector <int> find(int sJ, int kJ, int sB, int kB, int sF, int kF) 4fd800b3a8 2011-02-23 kinaba: { 4fd800b3a8 2011-02-23 kinaba: // init: 4fd800b3a8 2011-02-23 kinaba: // ( 0, 0, 0, 0, 0, 0) 4fd800b3a8 2011-02-23 kinaba: // possible transitions: 4fd800b3a8 2011-02-23 kinaba: // (+1,+1, 0, 0, 0, 0) 4fd800b3a8 2011-02-23 kinaba: // ( 0, 0,+1,+1, 0, 0) 4fd800b3a8 2011-02-23 kinaba: // ( 0,+2, 0, 0, 0, 0) 4fd800b3a8 2011-02-23 kinaba: // ( 0, 0, 0,+2, 0, 0) 4fd800b3a8 2011-02-23 kinaba: // (+1,+1, 0, 0,+1,+1) 4fd800b3a8 2011-02-23 kinaba: // ( 0, 0,+1,+1,+1,+1) 4fd800b3a8 2011-02-23 kinaba: // ( 0, 0, 0, 0,+2,+2) 4fd800b3a8 2011-02-23 kinaba: // (-1,+1, 0, 0,+1,+1) 4fd800b3a8 2011-02-23 kinaba: // ( 0, 0,-1,+1,+1,+1) 4fd800b3a8 2011-02-23 kinaba: vector<int> result; 4fd800b3a8 2011-02-23 kinaba: if(sF!=kF) 4fd800b3a8 2011-02-23 kinaba: return result; 4fd800b3a8 2011-02-23 kinaba: 4fd800b3a8 2011-02-23 kinaba: for(int f=0; 2*f<=sF; ++f) 4fd800b3a8 2011-02-23 kinaba: { 4fd800b3a8 2011-02-23 kinaba: int ff = sF - 2*f; 4fd800b3a8 2011-02-23 kinaba: if( kJ-ff>=0 && sB-ff>=0 ) 4fd800b3a8 2011-02-23 kinaba: { 4fd800b3a8 2011-02-23 kinaba: vector<int> c = calc(sJ+ff, kJ-ff, sB+ff, kB-ff); 4fd800b3a8 2011-02-23 kinaba: if( !c.empty() ) 4fd800b3a8 2011-02-23 kinaba: { 4fd800b3a8 2011-02-23 kinaba: c[0] += f+ff; 4fd800b3a8 2011-02-23 kinaba: c[1] += f+ff; 4fd800b3a8 2011-02-23 kinaba: if( result.empty() ) 4fd800b3a8 2011-02-23 kinaba: result = c; 4fd800b3a8 2011-02-23 kinaba: else { 4fd800b3a8 2011-02-23 kinaba: result[0] = min(result[0],c[0]); 4fd800b3a8 2011-02-23 kinaba: result[1] = max(result[1],c[1]); 4fd800b3a8 2011-02-23 kinaba: } 4fd800b3a8 2011-02-23 kinaba: } 4fd800b3a8 2011-02-23 kinaba: } 4fd800b3a8 2011-02-23 kinaba: } 4fd800b3a8 2011-02-23 kinaba: return result; 4fd800b3a8 2011-02-23 kinaba: } 4fd800b3a8 2011-02-23 kinaba: vector<int> calc(int sJ, int kJ, int sB, int kB) 4fd800b3a8 2011-02-23 kinaba: { 4fd800b3a8 2011-02-23 kinaba: // init: 4fd800b3a8 2011-02-23 kinaba: // ( 0, 0, 0, 0,) 4fd800b3a8 2011-02-23 kinaba: // possible transitions: 4fd800b3a8 2011-02-23 kinaba: // (+1,+1, 0, 0) 4fd800b3a8 2011-02-23 kinaba: // ( 0, 0,+1,+1) 4fd800b3a8 2011-02-23 kinaba: // ( 0,+2, 0, 0) 4fd800b3a8 2011-02-23 kinaba: // ( 0, 0, 0,+2) 4fd800b3a8 2011-02-23 kinaba: if(kJ<sJ || kB<sB || (kJ-sJ)%2==1 || (kB-sB)%2==1) 4fd800b3a8 2011-02-23 kinaba: return vector<int>(); 4fd800b3a8 2011-02-23 kinaba: return vector<int>(2, sJ+(kJ-sJ)/2 + sB+(kB-sB)/2); 4fd800b3a8 2011-02-23 kinaba: } 4fd800b3a8 2011-02-23 kinaba: }; 4fd800b3a8 2011-02-23 kinaba: 4fd800b3a8 2011-02-23 kinaba: // BEGIN CUT HERE 4fd800b3a8 2011-02-23 kinaba: #include <ctime> 4fd800b3a8 2011-02-23 kinaba: double start_time; string timer() 4fd800b3a8 2011-02-23 kinaba: { ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) << " msec)"; return os.str(); } 4fd800b3a8 2011-02-23 kinaba: template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) 4fd800b3a8 2011-02-23 kinaba: { os << "{ "; 4fd800b3a8 2011-02-23 kinaba: for(typename vector<T>::const_iterator it=v.begin(); it!=v.end(); ++it) 4fd800b3a8 2011-02-23 kinaba: os << '\"' << *it << '\"' << (it+1==v.end() ? "" : ", "); os << " }"; return os; } 4fd800b3a8 2011-02-23 kinaba: void verify_case(const vector <int>& Expected, const vector <int>& Received) { 4fd800b3a8 2011-02-23 kinaba: bool ok = (Expected == Received); 4fd800b3a8 2011-02-23 kinaba: if(ok) cerr << "PASSED" << timer() << endl; else { cerr << "FAILED" << timer() << endl; 4fd800b3a8 2011-02-23 kinaba: cerr << "\to: " << Expected << endl << "\tx: " << Received << endl; } } 4fd800b3a8 2011-02-23 kinaba: #define CASE(N) {cerr << "Test Case #" << N << "..." << flush; start_time=clock(); 4fd800b3a8 2011-02-23 kinaba: #define END verify_case(_, TheBoringGameDivOne().find(scoreJ, killedJ, scoreB, killedB, scoreF, killedF));} 4fd800b3a8 2011-02-23 kinaba: int main(){ 4fd800b3a8 2011-02-23 kinaba: 4fd800b3a8 2011-02-23 kinaba: CASE(0) 4fd800b3a8 2011-02-23 kinaba: int scoreJ = 1; 4fd800b3a8 2011-02-23 kinaba: int killedJ = 1; 4fd800b3a8 2011-02-23 kinaba: int scoreB = 1; 4fd800b3a8 2011-02-23 kinaba: int killedB = 1; 4fd800b3a8 2011-02-23 kinaba: int scoreF = 2; 4fd800b3a8 2011-02-23 kinaba: int killedF = 2; 4fd800b3a8 2011-02-23 kinaba: int __[] = {2, 3 }; 4fd800b3a8 2011-02-23 kinaba: vector <int> _(__, __+sizeof(__)/sizeof(*__)); 4fd800b3a8 2011-02-23 kinaba: END 4fd800b3a8 2011-02-23 kinaba: CASE(1) 4fd800b3a8 2011-02-23 kinaba: int scoreJ = 0; 4fd800b3a8 2011-02-23 kinaba: int killedJ = 0; 4fd800b3a8 2011-02-23 kinaba: int scoreB = 0; 4fd800b3a8 2011-02-23 kinaba: int killedB = 0; 4fd800b3a8 2011-02-23 kinaba: int scoreF = 0; 4fd800b3a8 2011-02-23 kinaba: int killedF = 0; 4fd800b3a8 2011-02-23 kinaba: int __[] = {0, 0 }; 4fd800b3a8 2011-02-23 kinaba: vector <int> _(__, __+sizeof(__)/sizeof(*__)); 4fd800b3a8 2011-02-23 kinaba: END 4fd800b3a8 2011-02-23 kinaba: CASE(2) 4fd800b3a8 2011-02-23 kinaba: int scoreJ = 4; 4fd800b3a8 2011-02-23 kinaba: int killedJ = 7; 4fd800b3a8 2011-02-23 kinaba: int scoreB = -2; 4fd800b3a8 2011-02-23 kinaba: int killedB = 5; 4fd800b3a8 2011-02-23 kinaba: int scoreF = 1; 4fd800b3a8 2011-02-23 kinaba: int killedF = 9; 4fd800b3a8 2011-02-23 kinaba: vector <int> _; 4fd800b3a8 2011-02-23 kinaba: END 4fd800b3a8 2011-02-23 kinaba: CASE(3) 4fd800b3a8 2011-02-23 kinaba: int scoreJ = 1; 4fd800b3a8 2011-02-23 kinaba: int killedJ = 5; 4fd800b3a8 2011-02-23 kinaba: int scoreB = -1; 4fd800b3a8 2011-02-23 kinaba: int killedB = 4; 4fd800b3a8 2011-02-23 kinaba: int scoreF = 3; 4fd800b3a8 2011-02-23 kinaba: int killedF = 6; 4fd800b3a8 2011-02-23 kinaba: int __[] = {8, 9 }; 4fd800b3a8 2011-02-23 kinaba: vector <int> _(__, __+sizeof(__)/sizeof(*__)); 4fd800b3a8 2011-02-23 kinaba: END 4fd800b3a8 2011-02-23 kinaba: /* 4fd800b3a8 2011-02-23 kinaba: CASE(4) 4fd800b3a8 2011-02-23 kinaba: int scoreJ = ; 4fd800b3a8 2011-02-23 kinaba: int killedJ = ; 4fd800b3a8 2011-02-23 kinaba: int scoreB = ; 4fd800b3a8 2011-02-23 kinaba: int killedB = ; 4fd800b3a8 2011-02-23 kinaba: int scoreF = ; 4fd800b3a8 2011-02-23 kinaba: int killedF = ; 4fd800b3a8 2011-02-23 kinaba: int __[] = ; 4fd800b3a8 2011-02-23 kinaba: vector <int> _(__, __+sizeof(__)/sizeof(*__)); 4fd800b3a8 2011-02-23 kinaba: END 4fd800b3a8 2011-02-23 kinaba: CASE(5) 4fd800b3a8 2011-02-23 kinaba: int scoreJ = ; 4fd800b3a8 2011-02-23 kinaba: int killedJ = ; 4fd800b3a8 2011-02-23 kinaba: int scoreB = ; 4fd800b3a8 2011-02-23 kinaba: int killedB = ; 4fd800b3a8 2011-02-23 kinaba: int scoreF = ; 4fd800b3a8 2011-02-23 kinaba: int killedF = ; 4fd800b3a8 2011-02-23 kinaba: int __[] = ; 4fd800b3a8 2011-02-23 kinaba: vector <int> _(__, __+sizeof(__)/sizeof(*__)); 4fd800b3a8 2011-02-23 kinaba: END 4fd800b3a8 2011-02-23 kinaba: */ 4fd800b3a8 2011-02-23 kinaba: } 4fd800b3a8 2011-02-23 kinaba: // END CUT HERE