7448b5f610 2012-11-20 kinaba: #include <iostream> 7448b5f610 2012-11-20 kinaba: #include <sstream> 7448b5f610 2012-11-20 kinaba: #include <iomanip> 7448b5f610 2012-11-20 kinaba: #include <vector> 7448b5f610 2012-11-20 kinaba: #include <string> 7448b5f610 2012-11-20 kinaba: #include <map> 7448b5f610 2012-11-20 kinaba: #include <set> 7448b5f610 2012-11-20 kinaba: #include <algorithm> 7448b5f610 2012-11-20 kinaba: #include <numeric> 7448b5f610 2012-11-20 kinaba: #include <iterator> 7448b5f610 2012-11-20 kinaba: #include <functional> 7448b5f610 2012-11-20 kinaba: #include <complex> 7448b5f610 2012-11-20 kinaba: #include <queue> 7448b5f610 2012-11-20 kinaba: #include <stack> 7448b5f610 2012-11-20 kinaba: #include <cmath> 7448b5f610 2012-11-20 kinaba: #include <cassert> 7448b5f610 2012-11-20 kinaba: using namespace std; 7448b5f610 2012-11-20 kinaba: typedef long long LL; 7448b5f610 2012-11-20 kinaba: typedef long double LD; 7448b5f610 2012-11-20 kinaba: typedef complex<LD> CMP; 7448b5f610 2012-11-20 kinaba: 7448b5f610 2012-11-20 kinaba: class DrawingPointsDivOne { public: 7448b5f610 2012-11-20 kinaba: int maxSteps(vector <int> x, vector <int> y) 7448b5f610 2012-11-20 kinaba: { 7448b5f610 2012-11-20 kinaba: static const int INF = 300; 7448b5f610 2012-11-20 kinaba: int L=0, R=INF+1; 7448b5f610 2012-11-20 kinaba: while(R-L>1) { 7448b5f610 2012-11-20 kinaba: int C = (L+R)/2; 7448b5f610 2012-11-20 kinaba: (possible(x,y,C) ? L : R) = C; 7448b5f610 2012-11-20 kinaba: } 7448b5f610 2012-11-20 kinaba: return L==INF ? -1 : L; 7448b5f610 2012-11-20 kinaba: } 7448b5f610 2012-11-20 kinaba: 7448b5f610 2012-11-20 kinaba: bool possible(const vector<int>& x, const vector<int>& y, int C) 7448b5f610 2012-11-20 kinaba: { 7448b5f610 2012-11-20 kinaba: int N = x.size(); 7448b5f610 2012-11-20 kinaba: int Z = C+10+280+C+10; 7448b5f610 2012-11-20 kinaba: int MID = C+10+140; 7448b5f610 2012-11-20 kinaba: vector<int> m(Z*Z); 7448b5f610 2012-11-20 kinaba: 7448b5f610 2012-11-20 kinaba: // paint 7448b5f610 2012-11-20 kinaba: for(int i=0; i<N; ++i) { 7448b5f610 2012-11-20 kinaba: int yy = MID+y[i]*2; 7448b5f610 2012-11-20 kinaba: int xx = MID+x[i]*2; 7448b5f610 2012-11-20 kinaba: m[ (yy+C )*Z+(xx+C ) ] += 1; 7448b5f610 2012-11-20 kinaba: m[ (yy-C-2)*Z+(xx+C ) ] -= 1; 7448b5f610 2012-11-20 kinaba: m[ (yy+C )*Z+(xx-C-2) ] -= 1; 7448b5f610 2012-11-20 kinaba: m[ (yy-C-2)*Z+(xx-C-2) ] += 1; 7448b5f610 2012-11-20 kinaba: } 7448b5f610 2012-11-20 kinaba: 7448b5f610 2012-11-20 kinaba: // sum 7448b5f610 2012-11-20 kinaba: for(int y=Z-3; y>=0; --y) 7448b5f610 2012-11-20 kinaba: for(int x=Z-3; x>=0; --x) 7448b5f610 2012-11-20 kinaba: m[y*Z+x] += m[(y+2)*Z+x]+m[y*Z+(x+2)]-m[(y+2)*Z+(x+2)]; 7448b5f610 2012-11-20 kinaba: 7448b5f610 2012-11-20 kinaba: for(int y=0; y<Z; ++y) for(int x=0; x<Z; ++x) m[y*Z+x] = !!m[y*Z+x]; 7448b5f610 2012-11-20 kinaba: 7448b5f610 2012-11-20 kinaba: // sum 7448b5f610 2012-11-20 kinaba: for(int y=Z-3; y>=0; --y) 7448b5f610 2012-11-20 kinaba: for(int x=Z-3; x>=0; --x) 7448b5f610 2012-11-20 kinaba: m[y*Z+x] += m[(y+2)*Z+x]+m[y*Z+(x+2)]-m[(y+2)*Z+(x+2)]; 7448b5f610 2012-11-20 kinaba: 7448b5f610 2012-11-20 kinaba: // count 7448b5f610 2012-11-20 kinaba: int cnt = 0; 7448b5f610 2012-11-20 kinaba: int S = (MID&1); 7448b5f610 2012-11-20 kinaba: for(int yy=S; yy<Z; yy+=2) 7448b5f610 2012-11-20 kinaba: for(int xx=S; xx<Z; xx+=2) 7448b5f610 2012-11-20 kinaba: if(yy+C+2<Z && xx+C+2<Z && yy-C>=0 && xx-C>=0) { 7448b5f610 2012-11-20 kinaba: int s = 7448b5f610 2012-11-20 kinaba: +m[ (yy+C+2)*Z+(xx+C+2) ] 7448b5f610 2012-11-20 kinaba: -m[ (yy-C )*Z+(xx+C+2) ] 7448b5f610 2012-11-20 kinaba: -m[ (yy+C+2)*Z+(xx-C ) ] 7448b5f610 2012-11-20 kinaba: +m[ (yy-C )*Z+(xx-C ) ]; 7448b5f610 2012-11-20 kinaba: if(s==(C+1)*(C+1)) 7448b5f610 2012-11-20 kinaba: ++cnt; 7448b5f610 2012-11-20 kinaba: } 7448b5f610 2012-11-20 kinaba: return cnt == N; 7448b5f610 2012-11-20 kinaba: } 7448b5f610 2012-11-20 kinaba: }; 7448b5f610 2012-11-20 kinaba: 7448b5f610 2012-11-20 kinaba: // BEGIN CUT HERE 7448b5f610 2012-11-20 kinaba: #include <ctime> 7448b5f610 2012-11-20 kinaba: double start_time; string timer() 7448b5f610 2012-11-20 kinaba: { ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) << " msec)"; return os.str(); } 7448b5f610 2012-11-20 kinaba: template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) 7448b5f610 2012-11-20 kinaba: { os << "{ "; 7448b5f610 2012-11-20 kinaba: for(typename vector<T>::const_iterator it=v.begin(); it!=v.end(); ++it) 7448b5f610 2012-11-20 kinaba: os << '\"' << *it << '\"' << (it+1==v.end() ? "" : ", "); os << " }"; return os; } 7448b5f610 2012-11-20 kinaba: void verify_case(const int& Expected, const int& Received) { 7448b5f610 2012-11-20 kinaba: bool ok = (Expected == Received); 7448b5f610 2012-11-20 kinaba: if(ok) cerr << "PASSED" << timer() << endl; else { cerr << "FAILED" << timer() << endl; 7448b5f610 2012-11-20 kinaba: cerr << "\to: \"" << Expected << '\"' << endl << "\tx: \"" << Received << '\"' << endl; } } 7448b5f610 2012-11-20 kinaba: #define CASE(N) {cerr << "Test Case #" << N << "..." << flush; start_time=clock(); 7448b5f610 2012-11-20 kinaba: #define END verify_case(_, DrawingPointsDivOne().maxSteps(x, y));} 7448b5f610 2012-11-20 kinaba: int main(){ 7448b5f610 2012-11-20 kinaba: 7448b5f610 2012-11-20 kinaba: CASE(0) 7448b5f610 2012-11-20 kinaba: int x_[] = {0, 3}; 7448b5f610 2012-11-20 kinaba: vector <int> x(x_, x_+sizeof(x_)/sizeof(*x_)); 7448b5f610 2012-11-20 kinaba: int y_[] = {0, 0}; 7448b5f610 2012-11-20 kinaba: vector <int> y(y_, y_+sizeof(y_)/sizeof(*y_)); 7448b5f610 2012-11-20 kinaba: int _ = 1; 7448b5f610 2012-11-20 kinaba: END 7448b5f610 2012-11-20 kinaba: CASE(1) 7448b5f610 2012-11-20 kinaba: int x_[] = {0,2}; 7448b5f610 2012-11-20 kinaba: vector <int> x(x_, x_+sizeof(x_)/sizeof(*x_)); 7448b5f610 2012-11-20 kinaba: int y_[] = {0,0}; 7448b5f610 2012-11-20 kinaba: vector <int> y(y_, y_+sizeof(y_)/sizeof(*y_)); 7448b5f610 2012-11-20 kinaba: int _ = 0; 7448b5f610 2012-11-20 kinaba: END 7448b5f610 2012-11-20 kinaba: CASE(2) 7448b5f610 2012-11-20 kinaba: int x_[] = {-70}; 7448b5f610 2012-11-20 kinaba: vector <int> x(x_, x_+sizeof(x_)/sizeof(*x_)); 7448b5f610 2012-11-20 kinaba: int y_[] = {3}; 7448b5f610 2012-11-20 kinaba: vector <int> y(y_, y_+sizeof(y_)/sizeof(*y_)); 7448b5f610 2012-11-20 kinaba: int _ = -1; 7448b5f610 2012-11-20 kinaba: END 7448b5f610 2012-11-20 kinaba: CASE(3) 7448b5f610 2012-11-20 kinaba: int x_[] = {-41,-40,1,-11,-32,-7,24,-11,49,-15,-22,20,-8,54,54,69,16,-30,36,-6,-30,40,64,20,-66, 7448b5f610 2012-11-20 kinaba: -37,-33,-18,-35,36,9,61,-43,45,5,60,-8,-58,65,-66,41,12,34,-11,-57,-38,46,63,-55,3}; 7448b5f610 2012-11-20 kinaba: vector <int> x(x_, x_+sizeof(x_)/sizeof(*x_)); 7448b5f610 2012-11-20 kinaba: int y_[] = {5,-24,-2,-4,23,14,1,70,-26,45,15,48,32,-41,54,-47,-67,-46,-9,-53,54,28,-61,11,53,68, 7448b5f610 2012-11-20 kinaba: -33,62,37,-8,-17,-17,48,19,-49,56,-41,16,17,-50,28,59,10,50,23,-16,56,31,-70,-44}; 7448b5f610 2012-11-20 kinaba: vector <int> y(y_, y_+sizeof(y_)/sizeof(*y_)); 7448b5f610 2012-11-20 kinaba: int _ = 9; 7448b5f610 2012-11-20 kinaba: END 7448b5f610 2012-11-20 kinaba: /* 7448b5f610 2012-11-20 kinaba: CASE(4) 7448b5f610 2012-11-20 kinaba: int x_[] = ; 7448b5f610 2012-11-20 kinaba: vector <int> x(x_, x_+sizeof(x_)/sizeof(*x_)); 7448b5f610 2012-11-20 kinaba: int y_[] = ; 7448b5f610 2012-11-20 kinaba: vector <int> y(y_, y_+sizeof(y_)/sizeof(*y_)); 7448b5f610 2012-11-20 kinaba: int _ = ; 7448b5f610 2012-11-20 kinaba: END 7448b5f610 2012-11-20 kinaba: CASE(5) 7448b5f610 2012-11-20 kinaba: int x_[] = ; 7448b5f610 2012-11-20 kinaba: vector <int> x(x_, x_+sizeof(x_)/sizeof(*x_)); 7448b5f610 2012-11-20 kinaba: int y_[] = ; 7448b5f610 2012-11-20 kinaba: vector <int> y(y_, y_+sizeof(y_)/sizeof(*y_)); 7448b5f610 2012-11-20 kinaba: int _ = ; 7448b5f610 2012-11-20 kinaba: END 7448b5f610 2012-11-20 kinaba: */ 7448b5f610 2012-11-20 kinaba: } 7448b5f610 2012-11-20 kinaba: // END CUT HERE