f0a8c39350 2013-09-16 kinaba: #include <iostream> f0a8c39350 2013-09-16 kinaba: #include <sstream> f0a8c39350 2013-09-16 kinaba: #include <iomanip> f0a8c39350 2013-09-16 kinaba: #include <vector> f0a8c39350 2013-09-16 kinaba: #include <string> f0a8c39350 2013-09-16 kinaba: #include <map> f0a8c39350 2013-09-16 kinaba: #include <set> f0a8c39350 2013-09-16 kinaba: #include <algorithm> f0a8c39350 2013-09-16 kinaba: #include <numeric> f0a8c39350 2013-09-16 kinaba: #include <iterator> f0a8c39350 2013-09-16 kinaba: #include <functional> f0a8c39350 2013-09-16 kinaba: #include <complex> f0a8c39350 2013-09-16 kinaba: #include <queue> f0a8c39350 2013-09-16 kinaba: #include <stack> f0a8c39350 2013-09-16 kinaba: #include <cmath> f0a8c39350 2013-09-16 kinaba: #include <cassert> f0a8c39350 2013-09-16 kinaba: #include <tuple> f0a8c39350 2013-09-16 kinaba: using namespace std; f0a8c39350 2013-09-16 kinaba: typedef long long LL; f0a8c39350 2013-09-16 kinaba: typedef complex<double> CMP; f0a8c39350 2013-09-16 kinaba: f0a8c39350 2013-09-16 kinaba: class FoxAndChess { public: f0a8c39350 2013-09-16 kinaba: string ableToMove(string begin, string target) f0a8c39350 2013-09-16 kinaba: { f0a8c39350 2013-09-16 kinaba: return solve(cb(begin), cb(target)) ? "Possible" : "Impossible"; f0a8c39350 2013-09-16 kinaba: } f0a8c39350 2013-09-16 kinaba: f0a8c39350 2013-09-16 kinaba: vector<pair<char,int>> cb(string s) f0a8c39350 2013-09-16 kinaba: { f0a8c39350 2013-09-16 kinaba: vector<pair<char,int>> v; f0a8c39350 2013-09-16 kinaba: for(int i=0; i<s.size(); ++i) f0a8c39350 2013-09-16 kinaba: if(s[i]!='.') f0a8c39350 2013-09-16 kinaba: v.emplace_back(s[i], i); f0a8c39350 2013-09-16 kinaba: return v; f0a8c39350 2013-09-16 kinaba: } f0a8c39350 2013-09-16 kinaba: f0a8c39350 2013-09-16 kinaba: bool solve(const vector<pair<char,int>>& b, const vector<pair<char,int>>& e) f0a8c39350 2013-09-16 kinaba: { f0a8c39350 2013-09-16 kinaba: if(b.size() != e.size()) f0a8c39350 2013-09-16 kinaba: return false; f0a8c39350 2013-09-16 kinaba: for(int i=0; i<b.size(); ++i) { f0a8c39350 2013-09-16 kinaba: if(b[i].first != e[i].first) f0a8c39350 2013-09-16 kinaba: return false; f0a8c39350 2013-09-16 kinaba: if(b[i].first == 'L' && b[i].second<e[i].second) f0a8c39350 2013-09-16 kinaba: return false; f0a8c39350 2013-09-16 kinaba: if(b[i].first == 'R' && b[i].second>e[i].second) f0a8c39350 2013-09-16 kinaba: return false; f0a8c39350 2013-09-16 kinaba: } f0a8c39350 2013-09-16 kinaba: return true; f0a8c39350 2013-09-16 kinaba: } f0a8c39350 2013-09-16 kinaba: }; f0a8c39350 2013-09-16 kinaba: f0a8c39350 2013-09-16 kinaba: // BEGIN CUT HERE f0a8c39350 2013-09-16 kinaba: #include <ctime> f0a8c39350 2013-09-16 kinaba: double start_time; string timer() f0a8c39350 2013-09-16 kinaba: { ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) << " msec)"; return os.str(); } f0a8c39350 2013-09-16 kinaba: template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) f0a8c39350 2013-09-16 kinaba: { os << "{ "; f0a8c39350 2013-09-16 kinaba: for(typename vector<T>::const_iterator it=v.begin(); it!=v.end(); ++it) f0a8c39350 2013-09-16 kinaba: os << '\"' << *it << '\"' << (it+1==v.end() ? "" : ", "); os << " }"; return os; } f0a8c39350 2013-09-16 kinaba: void verify_case(const string& Expected, const string& Received) { f0a8c39350 2013-09-16 kinaba: bool ok = (Expected == Received); f0a8c39350 2013-09-16 kinaba: if(ok) cerr << "PASSED" << timer() << endl; else { cerr << "FAILED" << timer() << endl; f0a8c39350 2013-09-16 kinaba: cerr << "\to: \"" << Expected << '\"' << endl << "\tx: \"" << Received << '\"' << endl; } } f0a8c39350 2013-09-16 kinaba: #define CASE(N) {cerr << "Test Case #" << N << "..." << flush; start_time=clock(); f0a8c39350 2013-09-16 kinaba: #define END verify_case(_, FoxAndChess().ableToMove(begin, target));} f0a8c39350 2013-09-16 kinaba: int main(){ f0a8c39350 2013-09-16 kinaba: f0a8c39350 2013-09-16 kinaba: CASE(0) f0a8c39350 2013-09-16 kinaba: string begin = "R..."; f0a8c39350 2013-09-16 kinaba: string target = "..R."; f0a8c39350 2013-09-16 kinaba: string _ = "Possible"; f0a8c39350 2013-09-16 kinaba: END f0a8c39350 2013-09-16 kinaba: CASE(1) f0a8c39350 2013-09-16 kinaba: string begin = "..R."; f0a8c39350 2013-09-16 kinaba: string target = "R..."; f0a8c39350 2013-09-16 kinaba: string _ = "Impossible"; f0a8c39350 2013-09-16 kinaba: END f0a8c39350 2013-09-16 kinaba: CASE(2) f0a8c39350 2013-09-16 kinaba: string begin = ".L.R.R."; f0a8c39350 2013-09-16 kinaba: string target = "L...R.R"; f0a8c39350 2013-09-16 kinaba: string _ = "Possible"; f0a8c39350 2013-09-16 kinaba: END f0a8c39350 2013-09-16 kinaba: CASE(3) f0a8c39350 2013-09-16 kinaba: string begin = ".L.R."; f0a8c39350 2013-09-16 kinaba: string target = ".R.L."; f0a8c39350 2013-09-16 kinaba: string _ = "Impossible"; f0a8c39350 2013-09-16 kinaba: END f0a8c39350 2013-09-16 kinaba: CASE(4) f0a8c39350 2013-09-16 kinaba: string begin = "LRLLRLRLLRLLRLRLRL"; f0a8c39350 2013-09-16 kinaba: string target = "LRLLRLRLLRLLRLRLRL"; f0a8c39350 2013-09-16 kinaba: string _ = "Possible"; f0a8c39350 2013-09-16 kinaba: END f0a8c39350 2013-09-16 kinaba: CASE(5) f0a8c39350 2013-09-16 kinaba: string begin = "L"; f0a8c39350 2013-09-16 kinaba: string target = "."; f0a8c39350 2013-09-16 kinaba: string _ = "Impossible"; f0a8c39350 2013-09-16 kinaba: END f0a8c39350 2013-09-16 kinaba: /* f0a8c39350 2013-09-16 kinaba: CASE(6) f0a8c39350 2013-09-16 kinaba: string begin = ; f0a8c39350 2013-09-16 kinaba: string target = ; f0a8c39350 2013-09-16 kinaba: string _ = ; f0a8c39350 2013-09-16 kinaba: END f0a8c39350 2013-09-16 kinaba: CASE(7) f0a8c39350 2013-09-16 kinaba: string begin = ; f0a8c39350 2013-09-16 kinaba: string target = ; f0a8c39350 2013-09-16 kinaba: string _ = ; f0a8c39350 2013-09-16 kinaba: END f0a8c39350 2013-09-16 kinaba: */ f0a8c39350 2013-09-16 kinaba: } f0a8c39350 2013-09-16 kinaba: // END CUT HERE