Artifact Content
Not logged in

Artifact 51b78e2d0929a6eb667ddca94df7a5d1cabec3dc


#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>
using namespace std;
typedef long long LL;
typedef long double LD;
typedef complex<LD> CMP;

class FoxAndMountainEasy { public:
	string possible(int n, int h0, int hn, string history)
	{
		int z = 0;
		int min_z = 0;
		for(int i=0; i<history.size(); ++i) {
			z += (history[i]=='U' ? +1 : -1);
			min_z = min(z, min_z);
		}

		for(int x=0; x+history.size()<=n; ++x)
		{
			int hx = h0 + x;
			if(hx+min_z < 0)
				continue;
			int hy = hx + z;
			if( possible(hn-hy, n-(x+history.size())) )
				return "YES";
		}
		return "NO";
	}

	bool possible(int dh, int k)
	{
		if((k+dh)%2 != 0)
			return false;
		int u = (k+dh)/2;
		int d = k - u;
		return 0<=u && u<=k && u+d==k && u-d==dh;
	}
};

// 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(_, FoxAndMountainEasy().possible(n, h0, hn, history));}
int main(){

CASE(0)
	int n = 4; 
	int h0 = 0; 
	int hn = 4; 
	string history = "UU"; 
	string _ = "YES"; 
END
CASE(1)
	int n = 4; 
	int h0 = 0; 
	int hn = 4; 
	string history = "D"; 
	string _ = "NO"; 
END
CASE(2)
	int n = 4; 
	int h0 = 100000; 
	int hn = 100000; 
	string history = "DDU"; 
	string _ = "YES"; 
END
CASE(3)
	int n = 4; 
	int h0 = 0; 
	int hn = 0; 
	string history = "DDU"; 
	string _ = "NO"; 
END
CASE(4)
	int n = 20; 
	int h0 = 20; 
	int hn = 20; 
	string history = "UDUDUDUDUD"; 
	string _ = "YES"; 
END
CASE(5)
	int n = 20; 
	int h0 = 0; 
	int hn = 0; 
	string history = "UUUUUUUUUU"; 
	string _ = "YES"; 
END
CASE(6)
	int n = 20; 
	int h0 = 0; 
	int hn = 0; 
	string history = "UUUUUUUUUUU"; 
	string _ = "NO"; 
END
CASE(7)
	int n = 4; 
	int h0 = 3; 
	int hn = 1; 
	string history = "U"; 
	string _ = "YES"; 
END
CASE(8)
	int n = 1; 
	int h0 = 0; 
	int hn = 1; 
	string history = "U"; 
	string _ = "YES"; 
END
CASE(8)
	int n = 2; 
	int h0 = 0; 
	int hn = 0; 
	string history = "DU"; 
	string _ = "NO"; 
END
}
// END CUT HERE