結果
| 問題 |
No.5005 3-SAT
|
| ユーザー |
Nachia
|
| 提出日時 | 2022-04-29 14:55:38 |
| 言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 1,503 ms / 2,000 ms |
| コード長 | 5,486 bytes |
| コンパイル時間 | 1,492 ms |
| 実行使用メモリ | 3,692 KB |
| スコア | 44,144 |
| 最終ジャッジ日時 | 2022-04-29 14:58:18 |
| 合計ジャッジ時間 | 158,139 ms |
|
ジャッジサーバーID (参考情報) |
judge14 / judge15 |
| 純コード判定しない問題か言語 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 100 |
ソースコード
#include <vector>
#include <algorithm>
#include <unordered_map>
#include <cassert>
#include <cstdint>
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<i64> 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<i64> V;
std::unordered_map<i64,i64> G;
for(int i=0; i<r; i++){
i64 p = random_signed(i,n);
i64 x = p - G[p];
V.push_back(x);
G[p] = p - (i - G[i]);
}
for(i64& v : V) v+=n_left;
return move(V);
}
// V[i] := V[perm[i]]
// using swap
template<class E,class PermInt_t>
void permute_inplace(std::vector<E>& V,std::vector<PermInt_t> perm){
assert(V.size() == perm.size());
int N=V.size();
for(int i=0; i<N; i++){
int p=i;
while(perm[p]!=i){
assert(0 <= perm[p] && perm[p] < N);
assert(perm[p] != perm[perm[p]]);
std::swap(V[p],V[perm[p]]);
int pbuf = perm[p]; perm[p] = p; p = pbuf;
}
perm[p] = p;
}
}
template<class E>
std::vector<E> shuffle(const std::vector<E>& V){
int N=V.size();
auto P = random_nPr(0,N-1,N);
std::vector<E> res;
res.reserve(N);
for(int i=0; i<N; i++) res.push_back(V[P[i]]);
}
// shuffle using swap
template<class E>
void shuffle_inplace(std::vector<E>& V){
int N=V.size();
permute_inplace(V,random_nPr(0,N-1,N));
}
};
#include <iostream>
#include <set>
#include <array>
#include <chrono>
#include <atcoder/modint>
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;
struct Constraint{
pair<int,int> a[3];
};
Randomizer_NV rng;
vector<array<array<int, 2>, 3>> A;
void shuffle_A_order(){
vector<u64> 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<int> final_ans = vector<int>(BIT_SIZE, 0);
vector<int> dfs_ans = vector<int>(BIT_SIZE + 1, -1);
int dfs_cnt = 0;
void dfs(int i){
if(dfs_cnt >= 100'000) return;
dfs_cnt++;
if(final_score < i){
final_ans = dfs_ans;
final_score = i;
}
if(final_score >= N) return;
bool ok = false;
rep(t,3) if(dfs_ans[A[i][t][0]] == A[i][t][1]) ok = true;
if(ok) return dfs(i+1);
rep(t,3) if(dfs_ans[A[i][t][0]] == -1){
dfs_ans[A[i][t][0]] = A[i][t][1];
dfs(i+1);
dfs_ans[A[i][t][0]] = -1;
}
}
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());
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]){
A[i][t][0] = A[i][t+1][0] = BIT_SIZE;
A[i][t][1] = A[i][t+1][1] = -1;
}
}
{
i64 seed = 0;
rep(i,N) seed = (seed * 3 + A[i][0][0]) % 998244353;
rng.seed(seed);
}
rep(t,10000){
shuffle_A_order();
dfs_cnt = 0;
dfs(0);
auto end_time = chrono::high_resolution_clock::now();
if((end_time - start_time).count() >= 1'500'000'000) break;
}
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;
Nachia