9b65a86a4f 2011-05-03 kinaba: #include <iostream> 9b65a86a4f 2011-05-03 kinaba: #include <sstream> 9b65a86a4f 2011-05-03 kinaba: #include <iomanip> 9b65a86a4f 2011-05-03 kinaba: #include <vector> 9b65a86a4f 2011-05-03 kinaba: #include <string> 9b65a86a4f 2011-05-03 kinaba: #include <map> 9b65a86a4f 2011-05-03 kinaba: #include <set> 9b65a86a4f 2011-05-03 kinaba: #include <algorithm> 9b65a86a4f 2011-05-03 kinaba: #include <numeric> 9b65a86a4f 2011-05-03 kinaba: #include <iterator> 9b65a86a4f 2011-05-03 kinaba: #include <functional> 9b65a86a4f 2011-05-03 kinaba: #include <complex> 9b65a86a4f 2011-05-03 kinaba: #include <queue> 9b65a86a4f 2011-05-03 kinaba: #include <stack> 9b65a86a4f 2011-05-03 kinaba: #include <cmath> 9b65a86a4f 2011-05-03 kinaba: #include <cassert> 9b65a86a4f 2011-05-03 kinaba: #include <cstring> 9b65a86a4f 2011-05-03 kinaba: using namespace std; 9b65a86a4f 2011-05-03 kinaba: typedef long long LL; 9b65a86a4f 2011-05-03 kinaba: typedef complex<double> CMP; 9b65a86a4f 2011-05-03 kinaba: 9b65a86a4f 2011-05-03 kinaba: class ToastXToast { public: 9b65a86a4f 2011-05-03 kinaba: int bake(vector <int> undertoasted, vector <int> overtoasted) 9b65a86a4f 2011-05-03 kinaba: { 9b65a86a4f 2011-05-03 kinaba: vector< pair<int,bool> > t_o; 9b65a86a4f 2011-05-03 kinaba: for(int i=0; i<undertoasted.size(); ++i) 9b65a86a4f 2011-05-03 kinaba: t_o.push_back( make_pair(undertoasted[i], false) ); 9b65a86a4f 2011-05-03 kinaba: for(int i=0; i<overtoasted.size(); ++i) 9b65a86a4f 2011-05-03 kinaba: t_o.push_back( make_pair(overtoasted[i], true) ); 9b65a86a4f 2011-05-03 kinaba: sort(t_o.begin(), t_o.end()); 9b65a86a4f 2011-05-03 kinaba: 9b65a86a4f 2011-05-03 kinaba: vector<bool> o; 9b65a86a4f 2011-05-03 kinaba: for(int i=0; i<t_o.size(); ++i) 9b65a86a4f 2011-05-03 kinaba: o.push_back( t_o[i].second ); 9b65a86a4f 2011-05-03 kinaba: 9b65a86a4f 2011-05-03 kinaba: if( o.front() || !o.back() ) 9b65a86a4f 2011-05-03 kinaba: return -1; 9b65a86a4f 2011-05-03 kinaba: for(int i=0; i+1<o.size(); ++i) 9b65a86a4f 2011-05-03 kinaba: if( o[i] && !o[i+1] ) 9b65a86a4f 2011-05-03 kinaba: return 2; 9b65a86a4f 2011-05-03 kinaba: return 1; 9b65a86a4f 2011-05-03 kinaba: } 9b65a86a4f 2011-05-03 kinaba: }; 9b65a86a4f 2011-05-03 kinaba: 9b65a86a4f 2011-05-03 kinaba: // BEGIN CUT HERE 9b65a86a4f 2011-05-03 kinaba: #include <ctime> 9b65a86a4f 2011-05-03 kinaba: double start_time; string timer() 9b65a86a4f 2011-05-03 kinaba: { ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) << " msec)"; return os.str(); } 9b65a86a4f 2011-05-03 kinaba: template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) 9b65a86a4f 2011-05-03 kinaba: { os << "{ "; 9b65a86a4f 2011-05-03 kinaba: for(typename vector<T>::const_iterator it=v.begin(); it!=v.end(); ++it) 9b65a86a4f 2011-05-03 kinaba: os << '\"' << *it << '\"' << (it+1==v.end() ? "" : ", "); os << " }"; return os; } 9b65a86a4f 2011-05-03 kinaba: void verify_case(const int& Expected, const int& Received) { 9b65a86a4f 2011-05-03 kinaba: bool ok = (Expected == Received); 9b65a86a4f 2011-05-03 kinaba: if(ok) cerr << "PASSED" << timer() << endl; else { cerr << "FAILED" << timer() << endl; 9b65a86a4f 2011-05-03 kinaba: cerr << "\to: \"" << Expected << '\"' << endl << "\tx: \"" << Received << '\"' << endl; } } 9b65a86a4f 2011-05-03 kinaba: #define CASE(N) {cerr << "Test Case #" << N << "..." << flush; start_time=clock(); 9b65a86a4f 2011-05-03 kinaba: #define END verify_case(_, ToastXToast().bake(undertoasted, overtoasted));} 9b65a86a4f 2011-05-03 kinaba: int main(){ 9b65a86a4f 2011-05-03 kinaba: 9b65a86a4f 2011-05-03 kinaba: CASE(0) 9b65a86a4f 2011-05-03 kinaba: int undertoasted_[] = {2,4}; 9b65a86a4f 2011-05-03 kinaba: vector <int> undertoasted(undertoasted_, undertoasted_+sizeof(undertoasted_)/sizeof(*undertoasted_)); 9b65a86a4f 2011-05-03 kinaba: int overtoasted_[] = {5,6,3}; 9b65a86a4f 2011-05-03 kinaba: vector <int> overtoasted(overtoasted_, overtoasted_+sizeof(overtoasted_)/sizeof(*overtoasted_)); 9b65a86a4f 2011-05-03 kinaba: int _ = 2; 9b65a86a4f 2011-05-03 kinaba: END 9b65a86a4f 2011-05-03 kinaba: CASE(1) 9b65a86a4f 2011-05-03 kinaba: int undertoasted_[] = {5}; 9b65a86a4f 2011-05-03 kinaba: vector <int> undertoasted(undertoasted_, undertoasted_+sizeof(undertoasted_)/sizeof(*undertoasted_)); 9b65a86a4f 2011-05-03 kinaba: int overtoasted_[] = {4}; 9b65a86a4f 2011-05-03 kinaba: vector <int> overtoasted(overtoasted_, overtoasted_+sizeof(overtoasted_)/sizeof(*overtoasted_)); 9b65a86a4f 2011-05-03 kinaba: int _ = -1; 9b65a86a4f 2011-05-03 kinaba: END 9b65a86a4f 2011-05-03 kinaba: CASE(2) 9b65a86a4f 2011-05-03 kinaba: int undertoasted_[] = {1,2,3}; 9b65a86a4f 2011-05-03 kinaba: vector <int> undertoasted(undertoasted_, undertoasted_+sizeof(undertoasted_)/sizeof(*undertoasted_)); 9b65a86a4f 2011-05-03 kinaba: int overtoasted_[] = {5,6,7}; 9b65a86a4f 2011-05-03 kinaba: vector <int> overtoasted(overtoasted_, overtoasted_+sizeof(overtoasted_)/sizeof(*overtoasted_)); 9b65a86a4f 2011-05-03 kinaba: int _ = 1; 9b65a86a4f 2011-05-03 kinaba: END 9b65a86a4f 2011-05-03 kinaba: CASE(3) 9b65a86a4f 2011-05-03 kinaba: int undertoasted_[] = {1,3,5}; 9b65a86a4f 2011-05-03 kinaba: vector <int> undertoasted(undertoasted_, undertoasted_+sizeof(undertoasted_)/sizeof(*undertoasted_)); 9b65a86a4f 2011-05-03 kinaba: int overtoasted_[] = {2,4,6}; 9b65a86a4f 2011-05-03 kinaba: vector <int> overtoasted(overtoasted_, overtoasted_+sizeof(overtoasted_)/sizeof(*overtoasted_)); 9b65a86a4f 2011-05-03 kinaba: int _ = 2; 9b65a86a4f 2011-05-03 kinaba: END 9b65a86a4f 2011-05-03 kinaba: /* 9b65a86a4f 2011-05-03 kinaba: CASE(4) 9b65a86a4f 2011-05-03 kinaba: int undertoasted_[] = ; 9b65a86a4f 2011-05-03 kinaba: vector <int> undertoasted(undertoasted_, undertoasted_+sizeof(undertoasted_)/sizeof(*undertoasted_)); 9b65a86a4f 2011-05-03 kinaba: int overtoasted_[] = ; 9b65a86a4f 2011-05-03 kinaba: vector <int> overtoasted(overtoasted_, overtoasted_+sizeof(overtoasted_)/sizeof(*overtoasted_)); 9b65a86a4f 2011-05-03 kinaba: int _ = ; 9b65a86a4f 2011-05-03 kinaba: END 9b65a86a4f 2011-05-03 kinaba: CASE(5) 9b65a86a4f 2011-05-03 kinaba: int undertoasted_[] = ; 9b65a86a4f 2011-05-03 kinaba: vector <int> undertoasted(undertoasted_, undertoasted_+sizeof(undertoasted_)/sizeof(*undertoasted_)); 9b65a86a4f 2011-05-03 kinaba: int overtoasted_[] = ; 9b65a86a4f 2011-05-03 kinaba: vector <int> overtoasted(overtoasted_, overtoasted_+sizeof(overtoasted_)/sizeof(*overtoasted_)); 9b65a86a4f 2011-05-03 kinaba: int _ = ; 9b65a86a4f 2011-05-03 kinaba: END 9b65a86a4f 2011-05-03 kinaba: */ 9b65a86a4f 2011-05-03 kinaba: } 9b65a86a4f 2011-05-03 kinaba: // END CUT HERE