e6ccb20270 2014-05-17 kinaba: #include <iostream> e6ccb20270 2014-05-17 kinaba: #include <sstream> e6ccb20270 2014-05-17 kinaba: #include <iomanip> e6ccb20270 2014-05-17 kinaba: #include <vector> e6ccb20270 2014-05-17 kinaba: #include <string> e6ccb20270 2014-05-17 kinaba: #include <map> e6ccb20270 2014-05-17 kinaba: #include <set> e6ccb20270 2014-05-17 kinaba: #include <algorithm> e6ccb20270 2014-05-17 kinaba: #include <numeric> e6ccb20270 2014-05-17 kinaba: #include <iterator> e6ccb20270 2014-05-17 kinaba: #include <functional> e6ccb20270 2014-05-17 kinaba: #include <complex> e6ccb20270 2014-05-17 kinaba: #include <queue> e6ccb20270 2014-05-17 kinaba: #include <stack> e6ccb20270 2014-05-17 kinaba: #include <cmath> e6ccb20270 2014-05-17 kinaba: #include <cassert> e6ccb20270 2014-05-17 kinaba: #include <tuple> e6ccb20270 2014-05-17 kinaba: using namespace std; e6ccb20270 2014-05-17 kinaba: typedef long long LL; e6ccb20270 2014-05-17 kinaba: typedef complex<double> CMP; e6ccb20270 2014-05-17 kinaba: e6ccb20270 2014-05-17 kinaba: class PairGame { public: e6ccb20270 2014-05-17 kinaba: int maxSum(int a, int b, int c, int d) e6ccb20270 2014-05-17 kinaba: { e6ccb20270 2014-05-17 kinaba: vector<pair<int,int>> s1 = seq(a,b); e6ccb20270 2014-05-17 kinaba: vector<pair<int,int>> s2 = seq(c,d); e6ccb20270 2014-05-17 kinaba: int cand = -1; e6ccb20270 2014-05-17 kinaba: for(auto& p1: s1) e6ccb20270 2014-05-17 kinaba: for(auto& p2: s2) e6ccb20270 2014-05-17 kinaba: if(p1 == p2) e6ccb20270 2014-05-17 kinaba: cand = max(cand, p1.first + p1.second); e6ccb20270 2014-05-17 kinaba: return cand; e6ccb20270 2014-05-17 kinaba: } e6ccb20270 2014-05-17 kinaba: e6ccb20270 2014-05-17 kinaba: vector<pair<int,int>> seq(int a, int b) e6ccb20270 2014-05-17 kinaba: { e6ccb20270 2014-05-17 kinaba: vector<pair<int,int>> s; e6ccb20270 2014-05-17 kinaba: do { e6ccb20270 2014-05-17 kinaba: s.emplace_back(a, b); e6ccb20270 2014-05-17 kinaba: if(a<b) e6ccb20270 2014-05-17 kinaba: b-=a; e6ccb20270 2014-05-17 kinaba: else e6ccb20270 2014-05-17 kinaba: a-=b; e6ccb20270 2014-05-17 kinaba: } while(a && b); e6ccb20270 2014-05-17 kinaba: return s; e6ccb20270 2014-05-17 kinaba: } e6ccb20270 2014-05-17 kinaba: }; e6ccb20270 2014-05-17 kinaba: e6ccb20270 2014-05-17 kinaba: // BEGIN CUT HERE e6ccb20270 2014-05-17 kinaba: #include <ctime> e6ccb20270 2014-05-17 kinaba: double start_time; string timer() e6ccb20270 2014-05-17 kinaba: { ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) << " msec)"; return os.str(); } e6ccb20270 2014-05-17 kinaba: template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) e6ccb20270 2014-05-17 kinaba: { os << "{ "; e6ccb20270 2014-05-17 kinaba: for(typename vector<T>::const_iterator it=v.begin(); it!=v.end(); ++it) e6ccb20270 2014-05-17 kinaba: os << '\"' << *it << '\"' << (it+1==v.end() ? "" : ", "); os << " }"; return os; } e6ccb20270 2014-05-17 kinaba: void verify_case(const int& Expected, const int& Received) { e6ccb20270 2014-05-17 kinaba: bool ok = (Expected == Received); e6ccb20270 2014-05-17 kinaba: if(ok) cerr << "PASSED" << timer() << endl; else { cerr << "FAILED" << timer() << endl; e6ccb20270 2014-05-17 kinaba: cerr << "\to: \"" << Expected << '\"' << endl << "\tx: \"" << Received << '\"' << endl; } } e6ccb20270 2014-05-17 kinaba: #define CASE(N) {cerr << "Test Case #" << N << "..." << flush; start_time=clock(); e6ccb20270 2014-05-17 kinaba: #define END verify_case(_, PairGame().maxSum(a, b, c, d));} e6ccb20270 2014-05-17 kinaba: int main(){ e6ccb20270 2014-05-17 kinaba: e6ccb20270 2014-05-17 kinaba: CASE(0) e6ccb20270 2014-05-17 kinaba: int a = 1; e6ccb20270 2014-05-17 kinaba: int b = 2; e6ccb20270 2014-05-17 kinaba: int c = 2; e6ccb20270 2014-05-17 kinaba: int d = 1; e6ccb20270 2014-05-17 kinaba: int _ = 2; e6ccb20270 2014-05-17 kinaba: END e6ccb20270 2014-05-17 kinaba: CASE(1) e6ccb20270 2014-05-17 kinaba: int a = 15; e6ccb20270 2014-05-17 kinaba: int b = 4; e6ccb20270 2014-05-17 kinaba: int c = 10; e6ccb20270 2014-05-17 kinaba: int d = 7; e6ccb20270 2014-05-17 kinaba: int _ = 7; e6ccb20270 2014-05-17 kinaba: END e6ccb20270 2014-05-17 kinaba: CASE(2) e6ccb20270 2014-05-17 kinaba: int a = 1; e6ccb20270 2014-05-17 kinaba: int b = 1; e6ccb20270 2014-05-17 kinaba: int c = 10; e6ccb20270 2014-05-17 kinaba: int d = 10; e6ccb20270 2014-05-17 kinaba: int _ = -1; e6ccb20270 2014-05-17 kinaba: END e6ccb20270 2014-05-17 kinaba: CASE(3) e6ccb20270 2014-05-17 kinaba: int a = 1000; e6ccb20270 2014-05-17 kinaba: int b = 1001; e6ccb20270 2014-05-17 kinaba: int c = 2000; e6ccb20270 2014-05-17 kinaba: int d = 2001; e6ccb20270 2014-05-17 kinaba: int _ = 1001; e6ccb20270 2014-05-17 kinaba: END e6ccb20270 2014-05-17 kinaba: CASE(4) e6ccb20270 2014-05-17 kinaba: int a = 10944; e6ccb20270 2014-05-17 kinaba: int b = 17928; e6ccb20270 2014-05-17 kinaba: int c = 7704; e6ccb20270 2014-05-17 kinaba: int d = 21888; e6ccb20270 2014-05-17 kinaba: int _ = 144; e6ccb20270 2014-05-17 kinaba: END e6ccb20270 2014-05-17 kinaba: CASE(5) e6ccb20270 2014-05-17 kinaba: int a = 1; e6ccb20270 2014-05-17 kinaba: int b = 1; e6ccb20270 2014-05-17 kinaba: int c = 1; e6ccb20270 2014-05-17 kinaba: int d = 1; e6ccb20270 2014-05-17 kinaba: int _ = 2; e6ccb20270 2014-05-17 kinaba: END e6ccb20270 2014-05-17 kinaba: /* e6ccb20270 2014-05-17 kinaba: CASE(6) e6ccb20270 2014-05-17 kinaba: int a = ; e6ccb20270 2014-05-17 kinaba: int b = ; e6ccb20270 2014-05-17 kinaba: int c = ; e6ccb20270 2014-05-17 kinaba: int d = ; e6ccb20270 2014-05-17 kinaba: int _ = ; e6ccb20270 2014-05-17 kinaba: END e6ccb20270 2014-05-17 kinaba: CASE(7) e6ccb20270 2014-05-17 kinaba: int a = ; e6ccb20270 2014-05-17 kinaba: int b = ; e6ccb20270 2014-05-17 kinaba: int c = ; e6ccb20270 2014-05-17 kinaba: int d = ; e6ccb20270 2014-05-17 kinaba: int _ = ; e6ccb20270 2014-05-17 kinaba: END e6ccb20270 2014-05-17 kinaba: */ e6ccb20270 2014-05-17 kinaba: } e6ccb20270 2014-05-17 kinaba: // END CUT HERE