#include #include #include #include #include class Randomizer_NV{ public: using i32 = int32_t; using u32 = uint32_t; using i64 = int64_t; using u64 = uint64_t; private: u32 rngx = 1234567890; u32 rngy = 987654321; u32 rngz = 998244353; u32 rngw = 1000000007; public: void seed(u32 x = 1234567890, u32 y = 987654321, u32 z = 998244353, u32 w = 1000000007){ rngx = x; rngy = y; rngz = z; rngw = w; } u32 rng32() { const u32 t = rngx ^ (rngx << 11); rngx = rngy; rngy = rngz; rngz = rngw; return rngw = rngw ^ (rngw >> 19) ^ t ^ (t >> 8); } u64 rng64() { return (u64)rng32() << 32 | rng32(); } // generate x : l <= x <= r u64 random_unsigned(u64 l,u64 r){ assert(l<=r); r-=l; auto res = rng64(); if(res<=r) return res+l; u64 d = r+1; u64 max_valid = 0xffffffffffffffff/d*d; while(true){ auto res = rng64(); if(res<=max_valid) break; } return res%d+l; } // generate x : l <= x <= r i64 random_signed(i64 l,i64 r){ assert(l<=r); u64 unsigned_l = (u64)l ^ (1ull<<63); u64 unsigned_r = (u64)r ^ (1ull<<63); u64 unsigned_res = random_unsigned(unsigned_l,unsigned_r) ^ (1ull<<63); return (i64)unsigned_res; } // permute x : n_left <= x <= n_right // output r from the front std::vector random_nPr(i64 n_left,i64 n_right,i64 r){ i64 n = n_right-n_left; assert(n>=0); assert(r<=(1ll<<27)); if(r==0) return {}; assert(n>=r-1); if(n==0) return {}; std::vector V; std::unordered_map G; for(int i=0; i void permute_inplace(std::vector& V,std::vector perm){ assert(V.size() == perm.size()); int N=V.size(); for(int i=0; i std::vector shuffle(const std::vector& V){ int N=V.size(); auto P = random_nPr(0,N-1,N); std::vector res; res.reserve(N); for(int i=0; i void shuffle_inplace(std::vector& V){ int N=V.size(); permute_inplace(V,random_nPr(0,N-1,N)); } }; #include #include #include #include #include using namespace std; using i32 = int; using u32 = unsigned int; using i64 = long long; using u64 = unsigned long long; #define rep(i,n) for(int i=0; i<(int)(n); i++) using m32 = atcoder::static_modint<998244353>; const int N = 2048; const int BIT_SIZE = 256; int TARGET = 500; struct Constraint{ pair a[3]; }; Randomizer_NV rng; vector, 3>> A; void shuffle_A_order(int n){ vector shuffle_seed((n+63)/64); for(auto& a : shuffle_seed) a = rng.rng64(); rep(i,n){ int d = ((shuffle_seed[i/64] >> (i%64)) & 1) + 1; swap(A[i][0], A[i][d]); } } int final_score = -1; vector final_ans = vector(BIT_SIZE, 0); vector> base_weight; vector>> edges; vector> weight; vector beg_satisfied; vector satisfied; void initialize_weight(){ rep(i,N) if(!satisfied[i]) { rep(t,3){ weight[A[i][t][0]][A[i][t][1]] += base_weight[i][t]; weight[A[i][t][0]][A[i][t][1] ^ 1] -= base_weight[i][t]; } } } int calc_score(const vector& ans){ rep(i,N){ bool ok = false; if(beg_satisfied[i]) continue; rep(t,3) if(ans[A[i][t][0]] == A[i][t][1]){ ok = true; break; } if(!ok) return i; } return N; } int main(){ auto start_time = chrono::high_resolution_clock::now(); A.resize(N); rep(i,N) rep(c,2) rep(t,3) cin >> A[i][t][c]; rep(i,N) rep(t,3) A[i][t][0] = BIT_SIZE - 1 - A[i][t][0]; rep(i,N) sort(A[i].begin(), A[i].end()); beg_satisfied.assign(N, 0); rep(i,N) rep(t,2) if(A[i][t][0] == A[i][t+1][0] && A[i][t][1] != A[i][t+1][1]) beg_satisfied[i] = 1; base_weight.resize(N); rep(i,TARGET) if(!beg_satisfied[i]) rep(t,3) base_weight[i][t] = TARGET - i; weight.resize(BIT_SIZE + 1); rep(i,BIT_SIZE) rep(t,2) weight[i][t] = 0.0; edges.resize(BIT_SIZE * 2); rep(i,N) rep(t,3) if(!beg_satisfied[i]) edges[A[i][t][0] * 2 + A[i][t][1]].push_back(make_pair(i,t)); { i64 seed = 0; rep(i,N) seed = (seed * 3 + A[i][0][0]) % 998244353; rng.seed(seed); } while(true){ auto end_time = chrono::high_resolution_clock::now(); if((end_time - start_time).count() >= 1'000'000'000 * 1.5) break; base_weight.resize(N); rep(i,TARGET) if(!beg_satisfied[i]) rep(t,3) base_weight[i][t] = rng.rng32() * rng.rng32(); satisfied = beg_satisfied; vector ans(BIT_SIZE, -1); int score = N; rep(i,N){ if(satisfied[i]) continue; initialize_weight(); pair nx_comp = make_pair(-1e100, -1); for(auto [u,v] : A[i]) if(ans[u] == -1) nx_comp = max(nx_comp, make_pair(weight[u][v], u*2+v)); if(nx_comp.second == -1){ score = i; break; } int nx = nx_comp.second; int nxu = nx / 2, nxv = nx % 2; ans[nxu] = nxv; for(auto [ii,t] : edges[nx]) if(!satisfied[ii]) satisfied[ii] = 1; } if(final_score < score){ final_ans = ans; final_score = score; } } rep(i,BIT_SIZE) if(final_ans[i] == -1) final_ans[i] = 0; rep(i,BIT_SIZE) cout << final_ans[i]; cerr << "Final Score = " << final_score << endl; cout << endl; return 0; } struct ios_do_not_sync{ ios_do_not_sync(){ std::ios::sync_with_stdio(false); std::cin.tie(nullptr); } } ios_do_not_sync_instance;