結果

問題 No.5005 3-SAT
ユーザー 👑 NachiaNachia
提出日時 2022-04-29 16:01:07
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,503 ms / 2,000 ms
コード長 6,691 bytes
コンパイル時間 1,531 ms
実行使用メモリ 3,868 KB
スコア 50,920
最終ジャッジ日時 2022-04-29 16:03:46
合計ジャッジ時間 158,024 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
純コード判定しない問題か言語
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,502 ms
3,708 KB
testcase_01 AC 1,503 ms
3,684 KB
testcase_02 AC 1,502 ms
3,688 KB
testcase_03 AC 1,502 ms
3,764 KB
testcase_04 AC 1,503 ms
3,624 KB
testcase_05 AC 1,502 ms
3,692 KB
testcase_06 AC 1,502 ms
3,640 KB
testcase_07 AC 1,503 ms
3,760 KB
testcase_08 AC 1,502 ms
3,620 KB
testcase_09 AC 1,502 ms
3,724 KB
testcase_10 AC 1,501 ms
3,704 KB
testcase_11 AC 1,502 ms
3,736 KB
testcase_12 AC 1,502 ms
3,728 KB
testcase_13 AC 1,503 ms
3,764 KB
testcase_14 AC 1,503 ms
3,736 KB
testcase_15 AC 1,502 ms
3,728 KB
testcase_16 AC 1,502 ms
3,664 KB
testcase_17 AC 1,502 ms
3,608 KB
testcase_18 AC 1,502 ms
3,676 KB
testcase_19 AC 1,502 ms
3,724 KB
testcase_20 AC 1,502 ms
3,624 KB
testcase_21 AC 1,502 ms
3,728 KB
testcase_22 AC 1,501 ms
3,672 KB
testcase_23 AC 1,502 ms
3,680 KB
testcase_24 AC 1,503 ms
3,680 KB
testcase_25 AC 1,502 ms
3,628 KB
testcase_26 AC 1,502 ms
3,756 KB
testcase_27 AC 1,503 ms
3,660 KB
testcase_28 AC 1,502 ms
3,752 KB
testcase_29 AC 1,501 ms
3,804 KB
testcase_30 AC 1,502 ms
3,612 KB
testcase_31 AC 1,502 ms
3,756 KB
testcase_32 AC 1,502 ms
3,720 KB
testcase_33 AC 1,502 ms
3,660 KB
testcase_34 AC 1,503 ms
3,752 KB
testcase_35 AC 1,503 ms
3,688 KB
testcase_36 AC 1,503 ms
3,636 KB
testcase_37 AC 1,502 ms
3,676 KB
testcase_38 AC 1,502 ms
3,712 KB
testcase_39 AC 1,503 ms
3,636 KB
testcase_40 AC 1,502 ms
3,684 KB
testcase_41 AC 1,502 ms
3,608 KB
testcase_42 AC 1,503 ms
3,740 KB
testcase_43 AC 1,502 ms
3,672 KB
testcase_44 AC 1,502 ms
3,708 KB
testcase_45 AC 1,502 ms
3,696 KB
testcase_46 AC 1,502 ms
3,668 KB
testcase_47 AC 1,502 ms
3,704 KB
testcase_48 AC 1,503 ms
3,616 KB
testcase_49 AC 1,502 ms
3,672 KB
testcase_50 AC 1,502 ms
3,752 KB
testcase_51 AC 1,502 ms
3,672 KB
testcase_52 AC 1,502 ms
3,608 KB
testcase_53 AC 1,502 ms
3,668 KB
testcase_54 AC 1,503 ms
3,620 KB
testcase_55 AC 1,502 ms
3,628 KB
testcase_56 AC 1,502 ms
3,616 KB
testcase_57 AC 1,502 ms
3,816 KB
testcase_58 AC 1,502 ms
3,668 KB
testcase_59 AC 1,503 ms
3,716 KB
testcase_60 AC 1,503 ms
3,724 KB
testcase_61 AC 1,503 ms
3,732 KB
testcase_62 AC 1,502 ms
3,612 KB
testcase_63 AC 1,502 ms
3,720 KB
testcase_64 AC 1,502 ms
3,708 KB
testcase_65 AC 1,502 ms
3,756 KB
testcase_66 AC 1,503 ms
3,756 KB
testcase_67 AC 1,502 ms
3,720 KB
testcase_68 AC 1,502 ms
3,692 KB
testcase_69 AC 1,502 ms
3,756 KB
testcase_70 AC 1,501 ms
3,668 KB
testcase_71 AC 1,503 ms
3,680 KB
testcase_72 AC 1,503 ms
3,656 KB
testcase_73 AC 1,502 ms
3,724 KB
testcase_74 AC 1,502 ms
3,724 KB
testcase_75 AC 1,502 ms
3,612 KB
testcase_76 AC 1,502 ms
3,624 KB
testcase_77 AC 1,502 ms
3,864 KB
testcase_78 AC 1,502 ms
3,756 KB
testcase_79 AC 1,502 ms
3,780 KB
testcase_80 AC 1,502 ms
3,708 KB
testcase_81 AC 1,503 ms
3,864 KB
testcase_82 AC 1,503 ms
3,748 KB
testcase_83 AC 1,502 ms
3,628 KB
testcase_84 AC 1,502 ms
3,632 KB
testcase_85 AC 1,502 ms
3,704 KB
testcase_86 AC 1,503 ms
3,764 KB
testcase_87 AC 1,502 ms
3,808 KB
testcase_88 AC 1,503 ms
3,708 KB
testcase_89 AC 1,502 ms
3,868 KB
testcase_90 AC 1,502 ms
3,720 KB
testcase_91 AC 1,502 ms
3,672 KB
testcase_92 AC 1,502 ms
3,744 KB
testcase_93 AC 1,502 ms
3,760 KB
testcase_94 AC 1,502 ms
3,768 KB
testcase_95 AC 1,503 ms
3,796 KB
testcase_96 AC 1,503 ms
3,708 KB
testcase_97 AC 1,502 ms
3,720 KB
testcase_98 AC 1,502 ms
3,636 KB
testcase_99 AC 1,502 ms
3,816 KB
権限があれば一括ダウンロードができます

ソースコード

diff #



#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;
int TARGET = 500;

struct Constraint{
    pair<int,int> a[3];
};

Randomizer_NV rng;
vector<array<array<int, 2>, 3>> A;

void shuffle_A_order(int n){
    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<array<double, 3>> base_weight;
vector<vector<pair<int,int>>> edges;

vector<array<double, 2>> weight;
vector<int> beg_satisfied;
vector<int> 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<int>& 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<int> ans(BIT_SIZE, -1);
        int score = N;
        rep(i,N){
            if(satisfied[i]) continue;
            initialize_weight();
            pair<double, int> 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;
0