289b0513ba 2014-02-03 kinaba: #include <iostream> 289b0513ba 2014-02-03 kinaba: #include <sstream> 289b0513ba 2014-02-03 kinaba: #include <iomanip> 289b0513ba 2014-02-03 kinaba: #include <vector> 289b0513ba 2014-02-03 kinaba: #include <string> 289b0513ba 2014-02-03 kinaba: #include <map> 289b0513ba 2014-02-03 kinaba: #include <set> 289b0513ba 2014-02-03 kinaba: #include <algorithm> 289b0513ba 2014-02-03 kinaba: #include <numeric> 289b0513ba 2014-02-03 kinaba: #include <iterator> 289b0513ba 2014-02-03 kinaba: #include <functional> 289b0513ba 2014-02-03 kinaba: #include <complex> 289b0513ba 2014-02-03 kinaba: #include <queue> 289b0513ba 2014-02-03 kinaba: #include <stack> 289b0513ba 2014-02-03 kinaba: #include <cmath> 289b0513ba 2014-02-03 kinaba: #include <cassert> 289b0513ba 2014-02-03 kinaba: #include <tuple> 289b0513ba 2014-02-03 kinaba: using namespace std; 289b0513ba 2014-02-03 kinaba: typedef long long LL; 289b0513ba 2014-02-03 kinaba: typedef complex<double> CMP; 289b0513ba 2014-02-03 kinaba: 289b0513ba 2014-02-03 kinaba: class EllysNumberGuessing { public: 289b0513ba 2014-02-03 kinaba: int getNumber(vector <int> guesses, vector <int> answers) 289b0513ba 2014-02-03 kinaba: { 289b0513ba 2014-02-03 kinaba: set<int> cand; 289b0513ba 2014-02-03 kinaba: for(int i=0; i<guesses.size(); ++ i) { 289b0513ba 2014-02-03 kinaba: set<int> c; 289b0513ba 2014-02-03 kinaba: int a = guesses[i]+answers[i]; 289b0513ba 2014-02-03 kinaba: if(1<=a && a<=1000000000) c.insert(a); 289b0513ba 2014-02-03 kinaba: a = guesses[i]-answers[i]; 289b0513ba 2014-02-03 kinaba: if(1<=a && a<=1000000000) c.insert(a); 289b0513ba 2014-02-03 kinaba: 289b0513ba 2014-02-03 kinaba: if(i==0) 289b0513ba 2014-02-03 kinaba: cand = c; 289b0513ba 2014-02-03 kinaba: else { 289b0513ba 2014-02-03 kinaba: set<int> cc; 289b0513ba 2014-02-03 kinaba: set_intersection(cand.begin(), cand.end(), c.begin(), c.end(), inserter(cc, cc.begin())); 289b0513ba 2014-02-03 kinaba: cand = cc; 289b0513ba 2014-02-03 kinaba: } 289b0513ba 2014-02-03 kinaba: } 289b0513ba 2014-02-03 kinaba: return cand.size()==1 ? *cand.begin() : cand.size()==2 ? -1 : -2; 289b0513ba 2014-02-03 kinaba: } 289b0513ba 2014-02-03 kinaba: }; 289b0513ba 2014-02-03 kinaba: 289b0513ba 2014-02-03 kinaba: // BEGIN CUT HERE 289b0513ba 2014-02-03 kinaba: #include <ctime> 289b0513ba 2014-02-03 kinaba: double start_time; string timer() 289b0513ba 2014-02-03 kinaba: { ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) << " msec)"; return os.str(); } 289b0513ba 2014-02-03 kinaba: template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) 289b0513ba 2014-02-03 kinaba: { os << "{ "; 289b0513ba 2014-02-03 kinaba: for(typename vector<T>::const_iterator it=v.begin(); it!=v.end(); ++it) 289b0513ba 2014-02-03 kinaba: os << '\"' << *it << '\"' << (it+1==v.end() ? "" : ", "); os << " }"; return os; } 289b0513ba 2014-02-03 kinaba: void verify_case(const int& Expected, const int& Received) { 289b0513ba 2014-02-03 kinaba: bool ok = (Expected == Received); 289b0513ba 2014-02-03 kinaba: if(ok) cerr << "PASSED" << timer() << endl; else { cerr << "FAILED" << timer() << endl; 289b0513ba 2014-02-03 kinaba: cerr << "\to: \"" << Expected << '\"' << endl << "\tx: \"" << Received << '\"' << endl; } } 289b0513ba 2014-02-03 kinaba: #define CASE(N) {cerr << "Test Case #" << N << "..." << flush; start_time=clock(); 289b0513ba 2014-02-03 kinaba: #define END verify_case(_, EllysNumberGuessing().getNumber(guesses, answers));} 289b0513ba 2014-02-03 kinaba: int main(){ 289b0513ba 2014-02-03 kinaba: 289b0513ba 2014-02-03 kinaba: CASE(0) 289b0513ba 2014-02-03 kinaba: int guesses_[] = {600, 594}; 289b0513ba 2014-02-03 kinaba: vector <int> guesses(guesses_, guesses_+sizeof(guesses_)/sizeof(*guesses_)); 289b0513ba 2014-02-03 kinaba: int answers_[] = {6, 12}; 289b0513ba 2014-02-03 kinaba: vector <int> answers(answers_, answers_+sizeof(answers_)/sizeof(*answers_)); 289b0513ba 2014-02-03 kinaba: int _ = 606; 289b0513ba 2014-02-03 kinaba: END 289b0513ba 2014-02-03 kinaba: CASE(1) 289b0513ba 2014-02-03 kinaba: int guesses_[] = {100, 50, 34, 40}; 289b0513ba 2014-02-03 kinaba: vector <int> guesses(guesses_, guesses_+sizeof(guesses_)/sizeof(*guesses_)); 289b0513ba 2014-02-03 kinaba: int answers_[] = {58, 8, 8, 2}; 289b0513ba 2014-02-03 kinaba: vector <int> answers(answers_, answers_+sizeof(answers_)/sizeof(*answers_)); 289b0513ba 2014-02-03 kinaba: int _ = 42; 289b0513ba 2014-02-03 kinaba: END 289b0513ba 2014-02-03 kinaba: CASE(2) 289b0513ba 2014-02-03 kinaba: int guesses_[] = {500000, 600000, 700000}; 289b0513ba 2014-02-03 kinaba: vector <int> guesses(guesses_, guesses_+sizeof(guesses_)/sizeof(*guesses_)); 289b0513ba 2014-02-03 kinaba: int answers_[] = {120013, 220013, 79987}; 289b0513ba 2014-02-03 kinaba: vector <int> answers(answers_, answers_+sizeof(answers_)/sizeof(*answers_)); 289b0513ba 2014-02-03 kinaba: int _ = -2; 289b0513ba 2014-02-03 kinaba: END 289b0513ba 2014-02-03 kinaba: CASE(3) 289b0513ba 2014-02-03 kinaba: int guesses_[] = {500000000}; 289b0513ba 2014-02-03 kinaba: vector <int> guesses(guesses_, guesses_+sizeof(guesses_)/sizeof(*guesses_)); 289b0513ba 2014-02-03 kinaba: int answers_[] = {133742666}; 289b0513ba 2014-02-03 kinaba: vector <int> answers(answers_, answers_+sizeof(answers_)/sizeof(*answers_)); 289b0513ba 2014-02-03 kinaba: int _ = -1; 289b0513ba 2014-02-03 kinaba: END 289b0513ba 2014-02-03 kinaba: CASE(4) 289b0513ba 2014-02-03 kinaba: int guesses_[] = {76938260, 523164588, 14196746, 296286419, 535893832, 289b0513ba 2014-02-03 kinaba: 41243148, 364561227, 270003278, 472017422, 367932361, 289b0513ba 2014-02-03 kinaba: 395758413, 301278456, 186276934, 316343129, 336557549, 289b0513ba 2014-02-03 kinaba: 52536121, 98343562, 356769915, 89249181, 335191879}; 289b0513ba 2014-02-03 kinaba: vector <int> guesses(guesses_, guesses_+sizeof(guesses_)/sizeof(*guesses_)); 289b0513ba 2014-02-03 kinaba: int answers_[] = {466274085, 20047757, 529015599, 246925926, 7318513, 289b0513ba 2014-02-03 kinaba: 501969197, 178651118, 273209067, 71194923, 175279984, 289b0513ba 2014-02-03 kinaba: 147453932, 241933889, 356935411, 226869216, 206654796, 289b0513ba 2014-02-03 kinaba: 490676224, 444868783, 186442430, 453963164, 208020466}; 289b0513ba 2014-02-03 kinaba: vector <int> answers(answers_, answers_+sizeof(answers_)/sizeof(*answers_)); 289b0513ba 2014-02-03 kinaba: int _ = 543212345; 289b0513ba 2014-02-03 kinaba: END 289b0513ba 2014-02-03 kinaba: CASE(5) 289b0513ba 2014-02-03 kinaba: int guesses_[] = {42}; 289b0513ba 2014-02-03 kinaba: vector <int> guesses(guesses_, guesses_+sizeof(guesses_)/sizeof(*guesses_)); 289b0513ba 2014-02-03 kinaba: int answers_[] = {42}; 289b0513ba 2014-02-03 kinaba: vector <int> answers(answers_, answers_+sizeof(answers_)/sizeof(*answers_)); 289b0513ba 2014-02-03 kinaba: int _ = 84; 289b0513ba 2014-02-03 kinaba: END 289b0513ba 2014-02-03 kinaba: CASE(6) 289b0513ba 2014-02-03 kinaba: int guesses_[] = {999900000}; 289b0513ba 2014-02-03 kinaba: vector <int> guesses(guesses_, guesses_+sizeof(guesses_)/sizeof(*guesses_)); 289b0513ba 2014-02-03 kinaba: int answers_[] = {100001}; 289b0513ba 2014-02-03 kinaba: vector <int> answers(answers_, answers_+sizeof(answers_)/sizeof(*answers_)); 289b0513ba 2014-02-03 kinaba: int _ = 999799999; 289b0513ba 2014-02-03 kinaba: END 289b0513ba 2014-02-03 kinaba: /* 289b0513ba 2014-02-03 kinaba: CASE(7) 289b0513ba 2014-02-03 kinaba: int guesses_[] = ; 289b0513ba 2014-02-03 kinaba: vector <int> guesses(guesses_, guesses_+sizeof(guesses_)/sizeof(*guesses_)); 289b0513ba 2014-02-03 kinaba: int answers_[] = ; 289b0513ba 2014-02-03 kinaba: vector <int> answers(answers_, answers_+sizeof(answers_)/sizeof(*answers_)); 289b0513ba 2014-02-03 kinaba: int _ = ; 289b0513ba 2014-02-03 kinaba: END 289b0513ba 2014-02-03 kinaba: CASE(8) 289b0513ba 2014-02-03 kinaba: int guesses_[] = ; 289b0513ba 2014-02-03 kinaba: vector <int> guesses(guesses_, guesses_+sizeof(guesses_)/sizeof(*guesses_)); 289b0513ba 2014-02-03 kinaba: int answers_[] = ; 289b0513ba 2014-02-03 kinaba: vector <int> answers(answers_, answers_+sizeof(answers_)/sizeof(*answers_)); 289b0513ba 2014-02-03 kinaba: int _ = ; 289b0513ba 2014-02-03 kinaba: END 289b0513ba 2014-02-03 kinaba: */ 289b0513ba 2014-02-03 kinaba: } 289b0513ba 2014-02-03 kinaba: // END CUT HERE