Artifact Content
Not logged in

Artifact a209bed380584b53415f9111b546a31303f9e7ba


#include <iostream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <iterator>
#include <functional>
#include <complex>
#include <queue>
#include <stack>
#include <cmath>
#include <cassert>
#include <tuple>
using namespace std;
typedef long long LL;
typedef complex<double> CMP;

class FoxAndChess { public:
	string ableToMove(string begin, string target)
	{
		return solve(cb(begin), cb(target)) ? "Possible" : "Impossible";
	}

	vector<pair<char,int>> cb(string s)
	{
		vector<pair<char,int>> v;
		for(int i=0; i<s.size(); ++i)
			if(s[i]!='.')
				v.emplace_back(s[i], i);
		return v;
	}

	bool solve(const vector<pair<char,int>>& b, const vector<pair<char,int>>& e)
	{
		if(b.size() != e.size())
			return false;
		for(int i=0; i<b.size(); ++i) {
			if(b[i].first != e[i].first)
				return false;
			if(b[i].first == 'L' && b[i].second<e[i].second)
				return false;
			if(b[i].first == 'R' && b[i].second>e[i].second)
				return false;
		}
		return true;
	}
};

// BEGIN CUT HERE
#include <ctime>
double start_time; string timer()
 { ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) << " msec)"; return os.str(); }
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v)
 { os << "{ ";
   for(typename vector<T>::const_iterator it=v.begin(); it!=v.end(); ++it)
   os << '\"' << *it << '\"' << (it+1==v.end() ? "" : ", "); os << " }"; return os; }
void verify_case(const string& Expected, const string& Received) {
 bool ok = (Expected == Received);
 if(ok) cerr << "PASSED" << timer() << endl;  else { cerr << "FAILED" << timer() << endl;
 cerr << "\to: \"" << Expected << '\"' << endl << "\tx: \"" << Received << '\"' << endl; } }
#define CASE(N) {cerr << "Test Case #" << N << "..." << flush; start_time=clock();
#define END	 verify_case(_, FoxAndChess().ableToMove(begin, target));}
int main(){

CASE(0)
	string begin = "R..."; 
	string target = "..R."; 
	string _ = "Possible"; 
END
CASE(1)
	string begin = "..R."; 
	string target = "R..."; 
	string _ = "Impossible"; 
END
CASE(2)
	string begin = ".L.R.R."; 
	string target = "L...R.R"; 
	string _ = "Possible"; 
END
CASE(3)
	string begin = ".L.R."; 
	string target = ".R.L."; 
	string _ = "Impossible"; 
END
CASE(4)
	string begin = "LRLLRLRLLRLLRLRLRL"; 
	string target = "LRLLRLRLLRLLRLRLRL"; 
	string _ = "Possible"; 
END
CASE(5)
	string begin = "L"; 
	string target = "."; 
	string _ = "Impossible"; 
END
/*
CASE(6)
	string begin = ; 
	string target = ; 
	string _ = ; 
END
CASE(7)
	string begin = ; 
	string target = ; 
	string _ = ; 
END
*/
}
// END CUT HERE