2024b9fa5d 2016-01-23 kinaba: #include <iostream> 2024b9fa5d 2016-01-23 kinaba: #include <sstream> 2024b9fa5d 2016-01-23 kinaba: #include <iomanip> 2024b9fa5d 2016-01-23 kinaba: #include <vector> 2024b9fa5d 2016-01-23 kinaba: #include <string> 2024b9fa5d 2016-01-23 kinaba: #include <map> 2024b9fa5d 2016-01-23 kinaba: #include <set> 2024b9fa5d 2016-01-23 kinaba: #include <algorithm> 2024b9fa5d 2016-01-23 kinaba: #include <numeric> 2024b9fa5d 2016-01-23 kinaba: #include <iterator> 2024b9fa5d 2016-01-23 kinaba: #include <functional> 2024b9fa5d 2016-01-23 kinaba: #include <complex> 2024b9fa5d 2016-01-23 kinaba: #include <queue> 2024b9fa5d 2016-01-23 kinaba: #include <stack> 2024b9fa5d 2016-01-23 kinaba: #include <cmath> 2024b9fa5d 2016-01-23 kinaba: #include <cassert> 2024b9fa5d 2016-01-23 kinaba: #include <tuple> 2024b9fa5d 2016-01-23 kinaba: using namespace std; 2024b9fa5d 2016-01-23 kinaba: typedef long long LL; 2024b9fa5d 2016-01-23 kinaba: typedef complex<double> CMP; 2024b9fa5d 2016-01-23 kinaba: 2024b9fa5d 2016-01-23 kinaba: double outer_prod(const CMP& a, const CMP& b) { return imag(conj(a)*b); } 2024b9fa5d 2016-01-23 kinaba: 2024b9fa5d 2016-01-23 kinaba: bool point_in_polygon( vector<CMP>& ps, CMP p ) 2024b9fa5d 2016-01-23 kinaba: { 2024b9fa5d 2016-01-23 kinaba: bool in = false; 2024b9fa5d 2016-01-23 kinaba: for(int i=0; i<ps.size(); ++i) { 2024b9fa5d 2016-01-23 kinaba: CMP a = ps[i] - p; 2024b9fa5d 2016-01-23 kinaba: CMP b = ps[(i+1)%ps.size()] - p; 2024b9fa5d 2016-01-23 kinaba: if(a.imag() > b.imag()) swap(a,b); 2024b9fa5d 2016-01-23 kinaba: if(a.imag()<=0 && 0<b.imag()) { 2024b9fa5d 2016-01-23 kinaba: if( outer_prod(a,b) < 0 ) 2024b9fa5d 2016-01-23 kinaba: in = !in; 2024b9fa5d 2016-01-23 kinaba: } 2024b9fa5d 2016-01-23 kinaba: } 2024b9fa5d 2016-01-23 kinaba: return in; 2024b9fa5d 2016-01-23 kinaba: } 2024b9fa5d 2016-01-23 kinaba: 2024b9fa5d 2016-01-23 kinaba: class RedAndBluePoints { public: 2024b9fa5d 2016-01-23 kinaba: int find(vector <int> blueX, vector <int> blueY, vector <int> redX, vector <int> redY) 2024b9fa5d 2016-01-23 kinaba: { 2024b9fa5d 2016-01-23 kinaba: const int B = blueX.size(); 2024b9fa5d 2016-01-23 kinaba: const int R = redX.size(); 2024b9fa5d 2016-01-23 kinaba: 2024b9fa5d 2016-01-23 kinaba: int best = 0; 2024b9fa5d 2016-01-23 kinaba: for(int b_use=0; b_use<B; ++b_use) 2024b9fa5d 2016-01-23 kinaba: { 2024b9fa5d 2016-01-23 kinaba: vector<vector<int>> G(B); 2024b9fa5d 2016-01-23 kinaba: for(int b1=0; b1<B; ++b1) if(b1 != b_use) 2024b9fa5d 2016-01-23 kinaba: for(int b2=b1+1; b2<B; ++b2) if(b2 != b_use) { 2024b9fa5d 2016-01-23 kinaba: bool bad = false; 2024b9fa5d 2016-01-23 kinaba: 2024b9fa5d 2016-01-23 kinaba: vector<CMP> poly; 2024b9fa5d 2016-01-23 kinaba: poly.emplace_back(blueX[b_use], blueY[b_use]); 2024b9fa5d 2016-01-23 kinaba: poly.emplace_back(blueX[b1], blueY[b1]); 2024b9fa5d 2016-01-23 kinaba: poly.emplace_back(blueX[b2], blueY[b2]); 2024b9fa5d 2016-01-23 kinaba: for(int r=0; r<R; ++r) 2024b9fa5d 2016-01-23 kinaba: if(point_in_polygon(poly, CMP(redX[r], redY[r]))) 2024b9fa5d 2016-01-23 kinaba: { bad=true; break; } 2024b9fa5d 2016-01-23 kinaba: 2024b9fa5d 2016-01-23 kinaba: if(bad) { 2024b9fa5d 2016-01-23 kinaba: G[b1].push_back(b2); 2024b9fa5d 2016-01-23 kinaba: G[b2].push_back(b1); 2024b9fa5d 2016-01-23 kinaba: } 2024b9fa5d 2016-01-23 kinaba: } 2024b9fa5d 2016-01-23 kinaba: best = max(best, max_independent_set(G)); 2024b9fa5d 2016-01-23 kinaba: } 2024b9fa5d 2016-01-23 kinaba: return best; 2024b9fa5d 2016-01-23 kinaba: } 2024b9fa5d 2016-01-23 kinaba: 2024b9fa5d 2016-01-23 kinaba: int max_independent_set(const vector<vector<int>>& G) 2024b9fa5d 2016-01-23 kinaba: { 2024b9fa5d 2016-01-23 kinaba: const int N = G.size(); 2024b9fa5d 2016-01-23 kinaba: vector<LL> badmask(G.size()); 2024b9fa5d 2016-01-23 kinaba: for(int v=0; v<N; ++v) { 2024b9fa5d 2016-01-23 kinaba: LL x = 1LL<<v; 2024b9fa5d 2016-01-23 kinaba: for(int u: G[v]) 2024b9fa5d 2016-01-23 kinaba: x |= 1LL<<u; 2024b9fa5d 2016-01-23 kinaba: badmask[v] = x; 2024b9fa5d 2016-01-23 kinaba: } 2024b9fa5d 2016-01-23 kinaba: 2024b9fa5d 2016-01-23 kinaba: int best = 0; 2024b9fa5d 2016-01-23 kinaba: function<void(int,LL,int)> rec = [&](int v, LL rest, int cur) { 2024b9fa5d 2016-01-23 kinaba: if(best < cur) 2024b9fa5d 2016-01-23 kinaba: best = cur; 2024b9fa5d 2016-01-23 kinaba: if(rest == 0) 2024b9fa5d 2016-01-23 kinaba: return; 2024b9fa5d 2016-01-23 kinaba: if(cur + __builtin_popcountll(rest) <= best) 2024b9fa5d 2016-01-23 kinaba: return; 2024b9fa5d 2016-01-23 kinaba: 2024b9fa5d 2016-01-23 kinaba: LL r1 = rest &~ (1LL<<v); 2024b9fa5d 2016-01-23 kinaba: LL r2 = rest &~ badmask[v]; 2024b9fa5d 2016-01-23 kinaba: if(rest & (1LL<<v)) { 2024b9fa5d 2016-01-23 kinaba: if(r1 != r2) rec(v+1, r1, cur); 2024b9fa5d 2016-01-23 kinaba: rec(v+1, r2, cur+1); 2024b9fa5d 2016-01-23 kinaba: } else { 2024b9fa5d 2016-01-23 kinaba: rec(v+1, r1, cur); 2024b9fa5d 2016-01-23 kinaba: } 2024b9fa5d 2016-01-23 kinaba: }; 2024b9fa5d 2016-01-23 kinaba: rec(0, (1LL<<N)-1, 0); 2024b9fa5d 2016-01-23 kinaba: return best; 2024b9fa5d 2016-01-23 kinaba: } 2024b9fa5d 2016-01-23 kinaba: }; 2024b9fa5d 2016-01-23 kinaba: 2024b9fa5d 2016-01-23 kinaba: // BEGIN CUT HERE 2024b9fa5d 2016-01-23 kinaba: #include <ctime> 2024b9fa5d 2016-01-23 kinaba: double start_time; string timer() 2024b9fa5d 2016-01-23 kinaba: { ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) << " msec)"; return os.str(); } 2024b9fa5d 2016-01-23 kinaba: template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) 2024b9fa5d 2016-01-23 kinaba: { os << "{ "; 2024b9fa5d 2016-01-23 kinaba: for(typename vector<T>::const_iterator it=v.begin(); it!=v.end(); ++it) 2024b9fa5d 2016-01-23 kinaba: os << '\"' << *it << '\"' << (it+1==v.end() ? "" : ", "); os << " }"; return os; } 2024b9fa5d 2016-01-23 kinaba: void verify_case(const int& Expected, const int& Received) { 2024b9fa5d 2016-01-23 kinaba: bool ok = (Expected == Received); 2024b9fa5d 2016-01-23 kinaba: if(ok) cerr << "PASSED" << timer() << endl; else { cerr << "FAILED" << timer() << endl; 2024b9fa5d 2016-01-23 kinaba: cerr << "\to: \"" << Expected << '\"' << endl << "\tx: \"" << Received << '\"' << endl; } } 2024b9fa5d 2016-01-23 kinaba: #define CASE(N) {cerr << "Test Case #" << N << "..." << flush; start_time=clock(); 2024b9fa5d 2016-01-23 kinaba: #define END verify_case(_, RedAndBluePoints().find(blueX, blueY, redX, redY));} 2024b9fa5d 2016-01-23 kinaba: int main(){ 2024b9fa5d 2016-01-23 kinaba: 2024b9fa5d 2016-01-23 kinaba: CASE(0) 2024b9fa5d 2016-01-23 kinaba: int blueX_[] = {0,0,10,10}; 2024b9fa5d 2016-01-23 kinaba: vector <int> blueX(blueX_, blueX_+sizeof(blueX_)/sizeof(*blueX_)); 2024b9fa5d 2016-01-23 kinaba: int blueY_[] = {0,10,0,10}; 2024b9fa5d 2016-01-23 kinaba: vector <int> blueY(blueY_, blueY_+sizeof(blueY_)/sizeof(*blueY_)); 2024b9fa5d 2016-01-23 kinaba: int redX_[] = {100}; 2024b9fa5d 2016-01-23 kinaba: vector <int> redX(redX_, redX_+sizeof(redX_)/sizeof(*redX_)); 2024b9fa5d 2016-01-23 kinaba: int redY_[] = {120}; 2024b9fa5d 2016-01-23 kinaba: vector <int> redY(redY_, redY_+sizeof(redY_)/sizeof(*redY_)); 2024b9fa5d 2016-01-23 kinaba: int _ = 4; 2024b9fa5d 2016-01-23 kinaba: END 2024b9fa5d 2016-01-23 kinaba: CASE(1) 2024b9fa5d 2016-01-23 kinaba: int blueX_[] = {0,0,10,10}; 2024b9fa5d 2016-01-23 kinaba: vector <int> blueX(blueX_, blueX_+sizeof(blueX_)/sizeof(*blueX_)); 2024b9fa5d 2016-01-23 kinaba: int blueY_[] = {0,10,0,10}; 2024b9fa5d 2016-01-23 kinaba: vector <int> blueY(blueY_, blueY_+sizeof(blueY_)/sizeof(*blueY_)); 2024b9fa5d 2016-01-23 kinaba: int redX_[] = {3}; 2024b9fa5d 2016-01-23 kinaba: vector <int> redX(redX_, redX_+sizeof(redX_)/sizeof(*redX_)); 2024b9fa5d 2016-01-23 kinaba: int redY_[] = {4}; 2024b9fa5d 2016-01-23 kinaba: vector <int> redY(redY_, redY_+sizeof(redY_)/sizeof(*redY_)); 2024b9fa5d 2016-01-23 kinaba: int _ = 3; 2024b9fa5d 2016-01-23 kinaba: END 2024b9fa5d 2016-01-23 kinaba: CASE(2) 2024b9fa5d 2016-01-23 kinaba: int blueX_[] = {0,0,10,10}; 2024b9fa5d 2016-01-23 kinaba: vector <int> blueX(blueX_, blueX_+sizeof(blueX_)/sizeof(*blueX_)); 2024b9fa5d 2016-01-23 kinaba: int blueY_[] = {0,10,0,10}; 2024b9fa5d 2016-01-23 kinaba: vector <int> blueY(blueY_, blueY_+sizeof(blueY_)/sizeof(*blueY_)); 2024b9fa5d 2016-01-23 kinaba: int redX_[] = {3,6}; 2024b9fa5d 2016-01-23 kinaba: vector <int> redX(redX_, redX_+sizeof(redX_)/sizeof(*redX_)); 2024b9fa5d 2016-01-23 kinaba: int redY_[] = {2,7}; 2024b9fa5d 2016-01-23 kinaba: vector <int> redY(redY_, redY_+sizeof(redY_)/sizeof(*redY_)); 2024b9fa5d 2016-01-23 kinaba: int _ = 2; 2024b9fa5d 2016-01-23 kinaba: END 2024b9fa5d 2016-01-23 kinaba: CASE(3) 2024b9fa5d 2016-01-23 kinaba: int blueX_[] = {0}; 2024b9fa5d 2016-01-23 kinaba: vector <int> blueX(blueX_, blueX_+sizeof(blueX_)/sizeof(*blueX_)); 2024b9fa5d 2016-01-23 kinaba: int blueY_[] = {0}; 2024b9fa5d 2016-01-23 kinaba: vector <int> blueY(blueY_, blueY_+sizeof(blueY_)/sizeof(*blueY_)); 2024b9fa5d 2016-01-23 kinaba: int redX_[] = {1}; 2024b9fa5d 2016-01-23 kinaba: vector <int> redX(redX_, redX_+sizeof(redX_)/sizeof(*redX_)); 2024b9fa5d 2016-01-23 kinaba: int redY_[] = {1}; 2024b9fa5d 2016-01-23 kinaba: vector <int> redY(redY_, redY_+sizeof(redY_)/sizeof(*redY_)); 2024b9fa5d 2016-01-23 kinaba: int _ = 1; 2024b9fa5d 2016-01-23 kinaba: END 2024b9fa5d 2016-01-23 kinaba: CASE(4) 2024b9fa5d 2016-01-23 kinaba: int blueX_[] = {5, 6, 6}; 2024b9fa5d 2016-01-23 kinaba: vector <int> blueX(blueX_, blueX_+sizeof(blueX_)/sizeof(*blueX_)); 2024b9fa5d 2016-01-23 kinaba: int blueY_[] = {9, 0, 5}; 2024b9fa5d 2016-01-23 kinaba: vector <int> blueY(blueY_, blueY_+sizeof(blueY_)/sizeof(*blueY_)); 2024b9fa5d 2016-01-23 kinaba: int redX_[] = {7}; 2024b9fa5d 2016-01-23 kinaba: vector <int> redX(redX_, redX_+sizeof(redX_)/sizeof(*redX_)); 2024b9fa5d 2016-01-23 kinaba: int redY_[] = {6}; 2024b9fa5d 2016-01-23 kinaba: vector <int> redY(redY_, redY_+sizeof(redY_)/sizeof(*redY_)); 2024b9fa5d 2016-01-23 kinaba: int _ = 3; 2024b9fa5d 2016-01-23 kinaba: END 2024b9fa5d 2016-01-23 kinaba: /* 2024b9fa5d 2016-01-23 kinaba: CASE(5) 2024b9fa5d 2016-01-23 kinaba: int blueX_[] = ; 2024b9fa5d 2016-01-23 kinaba: vector <int> blueX(blueX_, blueX_+sizeof(blueX_)/sizeof(*blueX_)); 2024b9fa5d 2016-01-23 kinaba: int blueY_[] = ; 2024b9fa5d 2016-01-23 kinaba: vector <int> blueY(blueY_, blueY_+sizeof(blueY_)/sizeof(*blueY_)); 2024b9fa5d 2016-01-23 kinaba: int redX_[] = ; 2024b9fa5d 2016-01-23 kinaba: vector <int> redX(redX_, redX_+sizeof(redX_)/sizeof(*redX_)); 2024b9fa5d 2016-01-23 kinaba: int redY_[] = ; 2024b9fa5d 2016-01-23 kinaba: vector <int> redY(redY_, redY_+sizeof(redY_)/sizeof(*redY_)); 2024b9fa5d 2016-01-23 kinaba: int _ = ; 2024b9fa5d 2016-01-23 kinaba: END 2024b9fa5d 2016-01-23 kinaba: CASE(6) 2024b9fa5d 2016-01-23 kinaba: int blueX_[] = ; 2024b9fa5d 2016-01-23 kinaba: vector <int> blueX(blueX_, blueX_+sizeof(blueX_)/sizeof(*blueX_)); 2024b9fa5d 2016-01-23 kinaba: int blueY_[] = ; 2024b9fa5d 2016-01-23 kinaba: vector <int> blueY(blueY_, blueY_+sizeof(blueY_)/sizeof(*blueY_)); 2024b9fa5d 2016-01-23 kinaba: int redX_[] = ; 2024b9fa5d 2016-01-23 kinaba: vector <int> redX(redX_, redX_+sizeof(redX_)/sizeof(*redX_)); 2024b9fa5d 2016-01-23 kinaba: int redY_[] = ; 2024b9fa5d 2016-01-23 kinaba: vector <int> redY(redY_, redY_+sizeof(redY_)/sizeof(*redY_)); 2024b9fa5d 2016-01-23 kinaba: int _ = ; 2024b9fa5d 2016-01-23 kinaba: END 2024b9fa5d 2016-01-23 kinaba: */ 2024b9fa5d 2016-01-23 kinaba: } 2024b9fa5d 2016-01-23 kinaba: // END CUT HERE