Artifact Content
Not logged in

Artifact ce107d8a36905d3191c487a0c85755f4ab48d70e


#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 complex<double> CMP;

class CheckerFreeness { public:
	string isFree(vector <string> whiteX, vector <string> whiteY, vector <string> blackX, vector <string> blackY)
	{
		stringstream swx(accumulate(whiteX.begin(), whiteX.end(), string("")));
		stringstream swy(accumulate(whiteY.begin(), whiteY.end(), string("")));
		stringstream sbx(accumulate(blackX.begin(), blackX.end(), string("")));
		stringstream sby(accumulate(blackY.begin(), blackY.end(), string("")));

		vector<CMP> w;
		for(int x,y; (swx>>x)&&(swy>>y); )
			w.push_back(CMP(x,y));

		vector<CMP> b;
		for(int x,y; (sbx>>x)&&(sby>>y); )
			b.push_back(CMP(x,y));

		return has_checker(w,b) ? "NO" : "YES";
	}

	bool has_checker(const vector<CMP>& w, const vector<CMP>& b)
	{
		for(int i=0; i<w.size(); ++i)
		for(int k=i+1; k<w.size(); ++k)
			if(has_crosser(w[i], w[k], b))
				return true;
		return false;
	}

	bool has_crosser(CMP a, CMP b, const vector<CMP>& ps)
	{
		vector<double> arg_a, arg_b;
		vector<CMP> qs;
		for(int i=0; i<ps.size(); ++i)
		{
			double d = arg( (ps[i]-a)/(b-a) );
			if(d > 0) {
				arg_a.push_back(d);
				d = arg( (ps[i]-b)/(b-a) );
				arg_b.push_back(d);
			} else {
				qs.push_back(ps[i]);
			}
		}
		sort(arg_a.begin(), arg_a.end());
		sort(arg_b.begin(), arg_b.end());
		for(int i=0; i<qs.size(); ++i)
		{
			CMP q = qs[i];
			double aMax = arg((a-q) / (b-a));
			double bMax = arg((b-q) / (b-a));
			int aNum = lower_bound(arg_a.begin(), arg_a.end(), aMax) - arg_a.begin();
			int bNum = lower_bound(arg_b.begin(), arg_b.end(), bMax) - arg_b.begin();
			if(aNum != bNum)
				return true;
		}
		return false;
	}
};

// 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(_, CheckerFreeness().isFree(whiteX, whiteY, blackX, blackY));}
int main(){

CASE(0)
	string whiteX_[] = {"1 2"};
	  vector <string> whiteX(whiteX_, whiteX_+sizeof(whiteX_)/sizeof(*whiteX_)); 
	string whiteY_[] = {"2 1"};
	  vector <string> whiteY(whiteY_, whiteY_+sizeof(whiteY_)/sizeof(*whiteY_)); 
	string blackX_[] = {"1 2"};
	  vector <string> blackX(blackX_, blackX_+sizeof(blackX_)/sizeof(*blackX_)); 
	string blackY_[] = {"1 2"};
	  vector <string> blackY(blackY_, blackY_+sizeof(blackY_)/sizeof(*blackY_)); 
	string _ = "NO"; 
END
CASE(1)
	string whiteX_[] = {"2", "5", "3", " ", "1", "7", "3"};
	  vector <string> whiteX(whiteX_, whiteX_+sizeof(whiteX_)/sizeof(*whiteX_)); 
	string whiteY_[] = {"180 254"};
	  vector <string> whiteY(whiteY_, whiteY_+sizeof(whiteY_)/sizeof(*whiteY_)); 
	string blackX_[] = {"32", "5 1", "42"};
	  vector <string> blackX(blackX_, blackX_+sizeof(blackX_)/sizeof(*blackX_)); 
	string blackY_[] = {"462 423"};
	  vector <string> blackY(blackY_, blackY_+sizeof(blackY_)/sizeof(*blackY_)); 
	string _ = "YES"; 
END
CASE(2)
	string whiteX_[] = {"1 10000000 9999999"};
	  vector <string> whiteX(whiteX_, whiteX_+sizeof(whiteX_)/sizeof(*whiteX_)); 
	string whiteY_[] = {"1 9999999 1"};
	  vector <string> whiteY(whiteY_, whiteY_+sizeof(whiteY_)/sizeof(*whiteY_)); 
	string blackX_[] = {"2 5000000 9999998"};
	  vector <string> blackX(blackX_, blackX_+sizeof(blackX_)/sizeof(*blackX_)); 
	string blackY_[] = {"2 5000001 9999999"};
	  vector <string> blackY(blackY_, blackY_+sizeof(blackY_)/sizeof(*blackY_)); 
	string _ = "YES"; 
END
CASE(3)
	string whiteX_[] = {"1"};
	  vector <string> whiteX(whiteX_, whiteX_+sizeof(whiteX_)/sizeof(*whiteX_)); 
	string whiteY_[] = {"2"};
	  vector <string> whiteY(whiteY_, whiteY_+sizeof(whiteY_)/sizeof(*whiteY_)); 
	string blackX_[] = {"3"};
	  vector <string> blackX(blackX_, blackX_+sizeof(blackX_)/sizeof(*blackX_)); 
	string blackY_[] = {"4"};
	  vector <string> blackY(blackY_, blackY_+sizeof(blackY_)/sizeof(*blackY_)); 
	string _ = "YES"; 
END
CASE(4)
	string whiteX_[] = {"6115 9723 3794 2275 2268 2702 3657 915 7953 2743 7"
,"716 9645 2547 9490 9365 326 6601 5215 6771 7153 72"
,"93 5922 714 2258 4369 9524 302 8417 6620 1143"};
	  vector <string> whiteX(whiteX_, whiteX_+sizeof(whiteX_)/sizeof(*whiteX_)); 
	string whiteY_[] = {"621 1611 7140 503 5345 7202 681 4908 2510 5908 279"
,"6 6286 6873 6682 9197 6710 8517 1913 7784 8533 665"
,"4 446 3561 7241 6168 2025 4739 9501 5340 6446"};
	  vector <string> whiteY(whiteY_, whiteY_+sizeof(whiteY_)/sizeof(*whiteY_)); 
	string blackX_[] = {"6833 131 4151 1776 1959 7210 1903 6107 598 6220 94"
,"24 5374 6718 2919 6068 6644 5070 710 7121 1630 370"
,"3 1051 5739 9294 8798 3371 8107 2130 6608 534"};
	  vector <string> blackX(blackX_, blackX_+sizeof(blackX_)/sizeof(*blackX_)); 
	string blackY_[] = {"7496 2412 2801 3473 5810 2714 7853 9714 5470 3558 "
,"8143 2391 8234 7292 9311 1636 8978 1107 2262 9175 "
,"7259 8842 5294 7209 2317 3825 3413 820 3774 5393"};
	  vector <string> blackY(blackY_, blackY_+sizeof(blackY_)/sizeof(*blackY_)); 
	string _ = "NO"; 
END
CASE(5)
	string whiteX_[] = {"219211 1996214 1706774 3634920 909831 1774128 8503"
,"52 2233050 2099138 3380396 1128982 3682525 1483700"
," 763080 487867 8203 1791027 463556 1103323 1406861"
," 6374234 760949 4340236 727393 2073832 1289052 103"
,"8147 4448130 151066 412440 1068735 377239 2677933 "
,"1299598 339843 289973 3707319 555280 230418 431719"};
	  vector <string> whiteX(whiteX_, whiteX_+sizeof(whiteX_)/sizeof(*whiteX_)); 
	string whiteY_[] = {"1638083 5698739 3105504 9726902 9745795 5049444 15"
,"80592 3952120 6606668 7460527 7239299 8726128 4913"
,"547 6264100 5701660 8865937 4969114 8014845 327236"
,"1 6389154 9739755 2561669 9412417 5452337 3150506 "
,"5832197 1571976 8779325 3306446 948271 5133709 949"
,"394 6919798 7525636 3568024 6833196 9237472 733313"
,"1 9939064 9720014"};
	  vector <string> whiteY(whiteY_, whiteY_+sizeof(whiteY_)/sizeof(*whiteY_)); 
	string blackX_[] = {"5860334 8007503 7455523 4864927 9573526 2718360 81"
,"12104 6684287 9921506 4840886 5415948 3451454 5320"
,"996 9268757 9261724 8254668 2292750 8035828 233352"
,"1 7676906 5234406 8533320 6562751 4884098 4971897 "
,"5569360 8519168 3100295 9351613 7733878 7579030 32"
,"46775 7297460 8370542 7099759 5782969 2978083 3390"
,"488 7482758 1332401 6094629 9717305 5503121 572842"
,"1 4903563 6331656 2867455 3410007 7751527 7228221 "
,"4111694 5171296 6847697 4601273 7599828 5515929 94"
,"60593 9332762 5389080 4512091 8668538 5711743 5838"
,"534 4825079 8145628 3810005 2964724 5594550 785748"
,"3 6283769"};
	  vector <string> blackX(blackX_, blackX_+sizeof(blackX_)/sizeof(*blackX_)); 
	string blackY_[] = {"5911694 8009943 212555 5838688 9896256 607434 5857"
,"663 4616750 1477573 7168026 3090917 4379806 326465"
,"7 4189076 2104028 3279691 94211 8503556 78457 4394"
,"360 3344176 3223317 2624498 4883494 1532240 732937"
,"1 1518674 1353567 892134 5536454 8527392 2603965 6"
,"623264 8830827 2030444 3002706 83058 4475866 20876"
,"25 1790695 4034441 5409379 3571098 4600050 736561 "
,"250475 3733256 3011439 2144994 4523046 3119883 607"
,"582 8361403 6525451 7518329 926803 4884524 8424659"
," 7088689 5762049 9532481 4914186 7314621 4339084 3"
,"741685 3837953 3177252 612550 9688871 5872931"};
	  vector <string> blackY(blackY_, blackY_+sizeof(blackY_)/sizeof(*blackY_)); 
	string _ = "YES"; 
END
/*
CASE(6)
	string whiteX_[] = ;
	  vector <string> whiteX(whiteX_, whiteX_+sizeof(whiteX_)/sizeof(*whiteX_)); 
	string whiteY_[] = ;
	  vector <string> whiteY(whiteY_, whiteY_+sizeof(whiteY_)/sizeof(*whiteY_)); 
	string blackX_[] = ;
	  vector <string> blackX(blackX_, blackX_+sizeof(blackX_)/sizeof(*blackX_)); 
	string blackY_[] = ;
	  vector <string> blackY(blackY_, blackY_+sizeof(blackY_)/sizeof(*blackY_)); 
	string _ = ; 
END
CASE(7)
	string whiteX_[] = ;
	  vector <string> whiteX(whiteX_, whiteX_+sizeof(whiteX_)/sizeof(*whiteX_)); 
	string whiteY_[] = ;
	  vector <string> whiteY(whiteY_, whiteY_+sizeof(whiteY_)/sizeof(*whiteY_)); 
	string blackX_[] = ;
	  vector <string> blackX(blackX_, blackX_+sizeof(blackX_)/sizeof(*blackX_)); 
	string blackY_[] = ;
	  vector <string> blackY(blackY_, blackY_+sizeof(blackY_)/sizeof(*blackY_)); 
	string _ = ; 
END
*/
}
// END CUT HERE