Artifact Content
Not logged in

Artifact 5207bb27f05cf2823e969bb4aa5d07f14643c229


#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 DistanceZeroAndOne { public:
	vector <string> construct(vector <int> dist0, vector <int> dist1)
	{
		const vector<string> IMPOSSIBLE;
		const int N = dist0.size();
		const int d01 = dist0[1];
		if (dist0[0] != 0) return IMPOSSIBLE;
		if (dist1[1] != 0) return IMPOSSIBLE;
		if (dist0[1] != dist1[0]) return IMPOSSIBLE;

		map<pair<int, int>, int> repr;
		for (int x = 0; x < N; ++x)
			repr[make_pair(dist0[x], dist1[x])] = x;

		vector<string> ans(N, string(N, 'N'));
		ans[0][1] = ans[1][0] = d01 == 1 ? 'Y' : 'N';
		for (int x = 2; x < N; ++x) {
			const int d0 = dist0[x];
			const int d1 = dist1[x];
			if (d0==0 || d1==0 || d0+d1<d01)
				return IMPOSSIBLE;
			if (d0 == 1) ans[0][x] = ans[x][0] = 'Y';
			if (d1 == 1) ans[1][x] = ans[x][1] = 'Y';

			if (d0 + d1 == d01) { // bone
				if (repr.count(make_pair(d0 - 1, d1 + 1))) {
					int p = repr[make_pair(d0 - 1, d1 + 1)];
					ans[p][x] = ans[x][p] = 'Y';
				}
				else {
					return IMPOSSIBLE;
				}

				if (repr.count(make_pair(d0 + 1, d1 - 1))) {
					int p = repr[make_pair(d0 + 1, d1 - 1)];
					ans[p][x] = ans[x][p] = 'Y';
				}
				else {
					return IMPOSSIBLE;
				}
			}
			else if(abs(d0 - d1) == d01) { // d0/d1 children
				if (repr.count(make_pair(d0 - 1, d1 - 1))) {
					int p = repr[make_pair(d0 - 1, d1 - 1)];
					ans[p][x] = ans[x][p] = 'Y';
				}
				else {
					return IMPOSSIBLE;
				}
			}
			else {
				// mid
				if (repr.count(make_pair(d0 - 1, d1 - 1))) {
					int p = repr[make_pair(d0 - 1, d1 - 1)];
					ans[p][x] = ans[x][p] = 'Y';
				}
				else {
					if (repr.count(make_pair(d0 - 1, d1 + 1))) {
						int p = repr[make_pair(d0 - 1, d1 + 1)];
						ans[p][x] = ans[x][p] = 'Y';
					}
					else if (repr.count(make_pair(d0 - 1, d1))) {
						int p = repr[make_pair(d0 - 1, d1)];
						ans[p][x] = ans[x][p] = 'Y';
					} else {
						return IMPOSSIBLE;
					}

					if (repr.count(make_pair(d0 + 1, d1 - 1))) {
						int p = repr[make_pair(d0 + 1, d1 - 1)];
						ans[p][x] = ans[x][p] = 'Y';
					}
					else if (repr.count(make_pair(d0, d1 - 1))) {
						int p = repr[make_pair(d0, d1 - 1)];
						ans[p][x] = ans[x][p] = 'Y';
					} else {
						return IMPOSSIBLE;
					}
				}
			}
		}
		return ans;
	}
};

// 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 vector <string>& Expected, const vector <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(_, DistanceZeroAndOne().construct(dist0, dist1));}
int main(){

CASE(0)
	int dist0_[] = {0,2,1};
	  vector <int> dist0(dist0_, dist0_+sizeof(dist0_)/sizeof(*dist0_)); 
	int dist1_[] = {2,0,1};
	  vector <int> dist1(dist1_, dist1_+sizeof(dist1_)/sizeof(*dist1_)); 
	string __[] = {"NNY", "NNY", "YYN" };
	  vector <string> _(__, __+sizeof(__)/sizeof(*__)); 
END
CASE(1)
	int dist0_[] = {0,2,1};
	  vector <int> dist0(dist0_, dist0_+sizeof(dist0_)/sizeof(*dist0_)); 
	int dist1_[] = {1,0,2};
	  vector <int> dist1(dist1_, dist1_+sizeof(dist1_)/sizeof(*dist1_)); 
	vector <string> _; 
END
CASE(2)
	int dist0_[] = {3,1,1,1};
	  vector <int> dist0(dist0_, dist0_+sizeof(dist0_)/sizeof(*dist0_)); 
	int dist1_[] = {1,0,1,1};
	  vector <int> dist1(dist1_, dist1_+sizeof(dist1_)/sizeof(*dist1_)); 
	vector <string> _; 
END
CASE(3)
	int dist0_[] = {0,1,1,1};
	  vector <int> dist0(dist0_, dist0_+sizeof(dist0_)/sizeof(*dist0_)); 
	int dist1_[] = {1,0,1,1};
	  vector <int> dist1(dist1_, dist1_+sizeof(dist1_)/sizeof(*dist1_)); 
	string __[] = {"NYYY", "YNYY", "YYNN", "YYNN" };
	  vector <string> _(__, __+sizeof(__)/sizeof(*__)); 
END
CASE(4)
	int dist0_[] = {0,3,1,2,2,3,4,4};
	  vector <int> dist0(dist0_, dist0_+sizeof(dist0_)/sizeof(*dist0_)); 
	int dist1_[] = {3,0,2,1,2,3,4,4};
	  vector <int> dist1(dist1_, dist1_+sizeof(dist1_)/sizeof(*dist1_)); 
	string __[] = {"NNYNNNNN", "NNNYNNNN", "YNNYYNNN", "NYYNYNNN", "NNYYNYNN", "NNNNYNYY", "NNNNNYNN", "NNNNNYNN" };
	  vector <string> _(__, __+sizeof(__)/sizeof(*__)); 
END
CASE(5)
	int dist0_[] = {0,1};
	  vector <int> dist0(dist0_, dist0_+sizeof(dist0_)/sizeof(*dist0_)); 
	int dist1_[] = {1,0};
	  vector <int> dist1(dist1_, dist1_+sizeof(dist1_)/sizeof(*dist1_)); 
	string __[] = {"NY", "YN" };
	  vector <string> _(__, __+sizeof(__)/sizeof(*__)); 
END
/*
CASE(6)
	int dist0_[] = ;
	  vector <int> dist0(dist0_, dist0_+sizeof(dist0_)/sizeof(*dist0_)); 
	int dist1_[] = ;
	  vector <int> dist1(dist1_, dist1_+sizeof(dist1_)/sizeof(*dist1_)); 
	string __[] = ;
	  vector <string> _(__, __+sizeof(__)/sizeof(*__)); 
END
CASE(7)
	int dist0_[] = ;
	  vector <int> dist0(dist0_, dist0_+sizeof(dist0_)/sizeof(*dist0_)); 
	int dist1_[] = ;
	  vector <int> dist1(dist1_, dist1_+sizeof(dist1_)/sizeof(*dist1_)); 
	string __[] = ;
	  vector <string> _(__, __+sizeof(__)/sizeof(*__)); 
END
*/
}
// END CUT HERE