Artifact Content
Not logged in

Artifact b84cafe08aca6effffa1496a26f4ad587732c7a7


#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 CandyOnDisk { public:
	string ableToAchieve(vector <int> x_, vector <int> y_, vector <int> r_, int sx, int sy, int tx, int ty)
	{
		if(sx==tx && sy==ty)
			return "YES";

		vector<LL> x,y,r;
		{
			map<pair<LL,LL>,LL> xyr;
			for(int i=0; i<x_.size(); ++i)
				xyr[make_pair(x_[i],y_[i])] = max<LL>(xyr[make_pair(x_[i],y_[i])], r_[i]);
			for(map<pair<LL,LL>,LL>::iterator it=xyr.begin(); it!=xyr.end(); ++it) {
				x.push_back(it->first.first);
				y.push_back(it->first.second);
				r.push_back(it->second);
			}
		}

		const int N = x.size();
		map<int, double> p;
		{
			for(int i=0; i<N; ++i)
			{
				LL dd = (sx-x[i])*(sx-x[i])+(sy-y[i])*(sy-y[i]);
				if( dd <= r[i]*r[i] )
				{
					if( dd == (tx-x[i])*(tx-x[i])+(ty-y[i])*(ty-y[i]) )
						return "YES";
					bool ok = false;
					for(int k=0; k<N; ++k) if(k!=i)
					{
						LL d = (x[i]-x[k])*(x[i]-x[k]) + (y[i]-y[k])*(y[i]-y[k]);
						if( d <= (r[i]+r[k])*(r[i]+r[k]) )
							ok = true;
					}
					if(ok)
						p[i] = sqrt((double)dd);
				}
			}
		}

		for(;;)
		{
			bool upd = false;
			map<int,double> p2 = p;
			for(map<int,double>::iterator it=p.begin(); it!=p.end(); ++it)
			{
				int i = it->first;
				double d = it->second;

				LL dd = (tx-x[i])*(tx-x[i])+(ty-y[i])*(ty-y[i]);
				if(d*d <= dd && dd <= r[i]*r[i])
					return "YES";

				for(int k=0; k<N; ++k) if(k!=i)
				{
					double z = abs(CMP(x[i],y[i])-CMP(x[k],y[k]));
					if(max(0.0, z-r[k]) <= d) {
						double dk = max(0.0, z-r[i]);
						if(!p2.count(k) || p2[k]>dk) {
							upd = true;
							p2[k] = dk;
						}
					}
				}
			}
			if(!upd)
				break;
			p.swap(p2);
		}

		return "NO";
	}
};

// 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(_, CandyOnDisk().ableToAchieve(x, y, r, sx, sy, tx, ty));}
int main(){

CASE(0)
	int x_[] = {0, 4};
	  vector <int> x(x_, x_+sizeof(x_)/sizeof(*x_)); 
	int y_[] = {0, 0};
	  vector <int> y(y_, y_+sizeof(y_)/sizeof(*y_)); 
	int r_[] = {3, 3};
	  vector <int> r(r_, r_+sizeof(r_)/sizeof(*r_)); 
	int sx = -1; 
	int sy = -2; 
	int tx = 6; 
	int ty = 1; 
	string _ = "YES"; 
END
CASE(1)
	int x_[] = {0, 3};
	  vector <int> x(x_, x_+sizeof(x_)/sizeof(*x_)); 
	int y_[] = {0, 0};
	  vector <int> y(y_, y_+sizeof(y_)/sizeof(*y_)); 
	int r_[] = {5, 3};
	  vector <int> r(r_, r_+sizeof(r_)/sizeof(*r_)); 
	int sx = -4; 
	int sy = 0; 
	int tx = -2; 
	int ty = 0; 
	string _ = "YES"; 
END
CASE(2)
	int x_[] = {0};
	  vector <int> x(x_, x_+sizeof(x_)/sizeof(*x_)); 
	int y_[] = {0};
	  vector <int> y(y_, y_+sizeof(y_)/sizeof(*y_)); 
	int r_[] = {1};
	  vector <int> r(r_, r_+sizeof(r_)/sizeof(*r_)); 
	int sx = 0; 
	int sy = 0; 
	int tx = 571; 
	int ty = 571; 
	string _ = "NO"; 
END
CASE(3)
	int x_[] = {0};
	  vector <int> x(x_, x_+sizeof(x_)/sizeof(*x_)); 
	int y_[] = {0};
	  vector <int> y(y_, y_+sizeof(y_)/sizeof(*y_)); 
	int r_[] = {1};
	  vector <int> r(r_, r_+sizeof(r_)/sizeof(*r_)); 
	int sx = 571; 
	int sy = 571; 
	int tx = 571; 
	int ty = 571; 
	string _ = "YES"; 
END
CASE(4)
	int x_[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20};
	  vector <int> x(x_, x_+sizeof(x_)/sizeof(*x_)); 
	int y_[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20};
	  vector <int> y(y_, y_+sizeof(y_)/sizeof(*y_)); 
	int r_[] = {2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2};
	  vector <int> r(r_, r_+sizeof(r_)/sizeof(*r_)); 
	int sx = 2; 
	int sy = 2; 
	int tx = 19; 
	int ty = 19; 
	string _ = "YES"; 
END
CASE(5)
	int x_[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20};
	  vector <int> x(x_, x_+sizeof(x_)/sizeof(*x_)); 
	int y_[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20};
	  vector <int> y(y_, y_+sizeof(y_)/sizeof(*y_)); 
	int r_[] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1};
	  vector <int> r(r_, r_+sizeof(r_)/sizeof(*r_)); 
	int sx = 2; 
	int sy = 2; 
	int tx = 19; 
	int ty = 19; 
	string _ = "NO"; 
END
/*
CASE(6)
	int x_[] = ;
	  vector <int> x(x_, x_+sizeof(x_)/sizeof(*x_)); 
	int y_[] = ;
	  vector <int> y(y_, y_+sizeof(y_)/sizeof(*y_)); 
	int r_[] = ;
	  vector <int> r(r_, r_+sizeof(r_)/sizeof(*r_)); 
	int sx = ; 
	int sy = ; 
	int tx = ; 
	int ty = ; 
	string _ = ; 
END
CASE(7)
	int x_[] = ;
	  vector <int> x(x_, x_+sizeof(x_)/sizeof(*x_)); 
	int y_[] = ;
	  vector <int> y(y_, y_+sizeof(y_)/sizeof(*y_)); 
	int r_[] = ;
	  vector <int> r(r_, r_+sizeof(r_)/sizeof(*r_)); 
	int sx = ; 
	int sy = ; 
	int tx = ; 
	int ty = ; 
	string _ = ; 
END
*/
}
// END CUT HERE