aca31be9a5 2011-12-24 kinaba: #include <iostream> aca31be9a5 2011-12-24 kinaba: #include <sstream> aca31be9a5 2011-12-24 kinaba: #include <iomanip> aca31be9a5 2011-12-24 kinaba: #include <vector> aca31be9a5 2011-12-24 kinaba: #include <string> aca31be9a5 2011-12-24 kinaba: #include <map> aca31be9a5 2011-12-24 kinaba: #include <set> aca31be9a5 2011-12-24 kinaba: #include <algorithm> aca31be9a5 2011-12-24 kinaba: #include <numeric> aca31be9a5 2011-12-24 kinaba: #include <iterator> aca31be9a5 2011-12-24 kinaba: #include <functional> aca31be9a5 2011-12-24 kinaba: #include <complex> aca31be9a5 2011-12-24 kinaba: #include <queue> aca31be9a5 2011-12-24 kinaba: #include <stack> aca31be9a5 2011-12-24 kinaba: #include <cmath> aca31be9a5 2011-12-24 kinaba: #include <cassert> aca31be9a5 2011-12-24 kinaba: #include <cstring> aca31be9a5 2011-12-24 kinaba: #ifdef __GNUC__ aca31be9a5 2011-12-24 kinaba: #include <ext/hash_map> aca31be9a5 2011-12-24 kinaba: #define unordered_map __gnu_cxx::hash_map aca31be9a5 2011-12-24 kinaba: #else aca31be9a5 2011-12-24 kinaba: #include <unordered_map> aca31be9a5 2011-12-24 kinaba: #endif aca31be9a5 2011-12-24 kinaba: using namespace std; aca31be9a5 2011-12-24 kinaba: typedef long long LL; aca31be9a5 2011-12-24 kinaba: typedef complex<double> CMP; aca31be9a5 2011-12-24 kinaba: aca31be9a5 2011-12-24 kinaba: class P8XMatrixTransformation { public: aca31be9a5 2011-12-24 kinaba: string solve(vector <string> original, vector <string> target) aca31be9a5 2011-12-24 kinaba: { aca31be9a5 2011-12-24 kinaba: int so = 0, st = 0; aca31be9a5 2011-12-24 kinaba: for(int y=0; y<original.size(); ++y) { aca31be9a5 2011-12-24 kinaba: so += accumulate(original[y].begin(), original[y].end(), 0); aca31be9a5 2011-12-24 kinaba: st += accumulate(target[y].begin(), target[y].end(), 0); aca31be9a5 2011-12-24 kinaba: } aca31be9a5 2011-12-24 kinaba: return so==st ? "YES" : "NO"; aca31be9a5 2011-12-24 kinaba: } aca31be9a5 2011-12-24 kinaba: }; aca31be9a5 2011-12-24 kinaba: aca31be9a5 2011-12-24 kinaba: // BEGIN CUT HERE aca31be9a5 2011-12-24 kinaba: #include <ctime> aca31be9a5 2011-12-24 kinaba: double start_time; string timer() aca31be9a5 2011-12-24 kinaba: { ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) << " msec)"; return os.str(); } aca31be9a5 2011-12-24 kinaba: template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) aca31be9a5 2011-12-24 kinaba: { os << "{ "; aca31be9a5 2011-12-24 kinaba: for(typename vector<T>::const_iterator it=v.begin(); it!=v.end(); ++it) aca31be9a5 2011-12-24 kinaba: os << '\"' << *it << '\"' << (it+1==v.end() ? "" : ", "); os << " }"; return os; } aca31be9a5 2011-12-24 kinaba: void verify_case(const string& Expected, const string& Received) { aca31be9a5 2011-12-24 kinaba: bool ok = (Expected == Received); aca31be9a5 2011-12-24 kinaba: if(ok) cerr << "PASSED" << timer() << endl; else { cerr << "FAILED" << timer() << endl; aca31be9a5 2011-12-24 kinaba: cerr << "\to: \"" << Expected << '\"' << endl << "\tx: \"" << Received << '\"' << endl; } } aca31be9a5 2011-12-24 kinaba: #define CASE(N) {cerr << "Test Case #" << N << "..." << flush; start_time=clock(); aca31be9a5 2011-12-24 kinaba: #define END verify_case(_, P8XMatrixTransformation().solve(original, target));} aca31be9a5 2011-12-24 kinaba: int main(){ aca31be9a5 2011-12-24 kinaba: aca31be9a5 2011-12-24 kinaba: CASE(0) aca31be9a5 2011-12-24 kinaba: string original_[] = {"01" aca31be9a5 2011-12-24 kinaba: ,"11"}; aca31be9a5 2011-12-24 kinaba: vector <string> original(original_, original_+sizeof(original_)/sizeof(*original_)); aca31be9a5 2011-12-24 kinaba: string target_[] = {"11" aca31be9a5 2011-12-24 kinaba: ,"10"}; aca31be9a5 2011-12-24 kinaba: vector <string> target(target_, target_+sizeof(target_)/sizeof(*target_)); aca31be9a5 2011-12-24 kinaba: string _ = "YES"; aca31be9a5 2011-12-24 kinaba: END aca31be9a5 2011-12-24 kinaba: CASE(1) aca31be9a5 2011-12-24 kinaba: string original_[] = {"0111" aca31be9a5 2011-12-24 kinaba: ,"0011"}; aca31be9a5 2011-12-24 kinaba: vector <string> original(original_, original_+sizeof(original_)/sizeof(*original_)); aca31be9a5 2011-12-24 kinaba: string target_[] = {"1011" aca31be9a5 2011-12-24 kinaba: ,"1100"}; aca31be9a5 2011-12-24 kinaba: vector <string> target(target_, target_+sizeof(target_)/sizeof(*target_)); aca31be9a5 2011-12-24 kinaba: string _ = "YES"; aca31be9a5 2011-12-24 kinaba: END aca31be9a5 2011-12-24 kinaba: CASE(2) aca31be9a5 2011-12-24 kinaba: string original_[] = {"0"}; aca31be9a5 2011-12-24 kinaba: vector <string> original(original_, original_+sizeof(original_)/sizeof(*original_)); aca31be9a5 2011-12-24 kinaba: string target_[] = {"1"}; aca31be9a5 2011-12-24 kinaba: vector <string> target(target_, target_+sizeof(target_)/sizeof(*target_)); aca31be9a5 2011-12-24 kinaba: string _ = "NO"; aca31be9a5 2011-12-24 kinaba: END aca31be9a5 2011-12-24 kinaba: CASE(3) aca31be9a5 2011-12-24 kinaba: string original_[] = {"1111" aca31be9a5 2011-12-24 kinaba: ,"1111" aca31be9a5 2011-12-24 kinaba: ,"0000" aca31be9a5 2011-12-24 kinaba: ,"0000"}; aca31be9a5 2011-12-24 kinaba: vector <string> original(original_, original_+sizeof(original_)/sizeof(*original_)); aca31be9a5 2011-12-24 kinaba: string target_[] = {"1111" aca31be9a5 2011-12-24 kinaba: ,"1111" aca31be9a5 2011-12-24 kinaba: ,"0000" aca31be9a5 2011-12-24 kinaba: ,"0000"}; aca31be9a5 2011-12-24 kinaba: vector <string> target(target_, target_+sizeof(target_)/sizeof(*target_)); aca31be9a5 2011-12-24 kinaba: string _ = "YES"; aca31be9a5 2011-12-24 kinaba: END aca31be9a5 2011-12-24 kinaba: CASE(4) aca31be9a5 2011-12-24 kinaba: string original_[] = {"0110" aca31be9a5 2011-12-24 kinaba: ,"1001" aca31be9a5 2011-12-24 kinaba: ,"0110"}; aca31be9a5 2011-12-24 kinaba: vector <string> original(original_, original_+sizeof(original_)/sizeof(*original_)); aca31be9a5 2011-12-24 kinaba: string target_[] = {"1111" aca31be9a5 2011-12-24 kinaba: ,"0110" aca31be9a5 2011-12-24 kinaba: ,"0000"}; aca31be9a5 2011-12-24 kinaba: vector <string> target(target_, target_+sizeof(target_)/sizeof(*target_)); aca31be9a5 2011-12-24 kinaba: string _ = "YES"; aca31be9a5 2011-12-24 kinaba: END aca31be9a5 2011-12-24 kinaba: CASE(5) aca31be9a5 2011-12-24 kinaba: string original_[] = {"0000" aca31be9a5 2011-12-24 kinaba: ,"1111" aca31be9a5 2011-12-24 kinaba: ,"0000"}; aca31be9a5 2011-12-24 kinaba: vector <string> original(original_, original_+sizeof(original_)/sizeof(*original_)); aca31be9a5 2011-12-24 kinaba: string target_[] = {"1111" aca31be9a5 2011-12-24 kinaba: ,"0000" aca31be9a5 2011-12-24 kinaba: ,"1111"}; aca31be9a5 2011-12-24 kinaba: vector <string> target(target_, target_+sizeof(target_)/sizeof(*target_)); aca31be9a5 2011-12-24 kinaba: string _ = "NO"; aca31be9a5 2011-12-24 kinaba: END aca31be9a5 2011-12-24 kinaba: /* aca31be9a5 2011-12-24 kinaba: CASE(6) aca31be9a5 2011-12-24 kinaba: string original_[] = ; aca31be9a5 2011-12-24 kinaba: vector <string> original(original_, original_+sizeof(original_)/sizeof(*original_)); aca31be9a5 2011-12-24 kinaba: string target_[] = ; aca31be9a5 2011-12-24 kinaba: vector <string> target(target_, target_+sizeof(target_)/sizeof(*target_)); aca31be9a5 2011-12-24 kinaba: string _ = ; aca31be9a5 2011-12-24 kinaba: END aca31be9a5 2011-12-24 kinaba: CASE(7) aca31be9a5 2011-12-24 kinaba: string original_[] = ; aca31be9a5 2011-12-24 kinaba: vector <string> original(original_, original_+sizeof(original_)/sizeof(*original_)); aca31be9a5 2011-12-24 kinaba: string target_[] = ; aca31be9a5 2011-12-24 kinaba: vector <string> target(target_, target_+sizeof(target_)/sizeof(*target_)); aca31be9a5 2011-12-24 kinaba: string _ = ; aca31be9a5 2011-12-24 kinaba: END aca31be9a5 2011-12-24 kinaba: */ aca31be9a5 2011-12-24 kinaba: } aca31be9a5 2011-12-24 kinaba: // END CUT HERE