結果

問題 No.5005 3-SAT
ユーザー 👑 NachiaNachia
提出日時 2022-04-29 16:52:43
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 7,120 bytes
コンパイル時間 1,273 ms
実行使用メモリ 3,456 KB
スコア 0
最終ジャッジ日時 2022-04-29 16:53:23
合計ジャッジ時間 39,525 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 RE -
testcase_02 RE -
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 RE -
testcase_28 RE -
testcase_29 RE -
testcase_30 RE -
testcase_31 RE -
testcase_32 RE -
testcase_33 RE -
testcase_34 RE -
testcase_35 RE -
testcase_36 RE -
testcase_37 RE -
testcase_38 RE -
testcase_39 RE -
testcase_40 RE -
testcase_41 RE -
testcase_42 RE -
testcase_43 RE -
testcase_44 RE -
testcase_45 RE -
testcase_46 RE -
testcase_47 RE -
testcase_48 RE -
testcase_49 RE -
testcase_50 RE -
testcase_51 RE -
testcase_52 RE -
testcase_53 RE -
testcase_54 RE -
testcase_55 RE -
testcase_56 RE -
testcase_57 RE -
testcase_58 RE -
testcase_59 RE -
testcase_60 RE -
testcase_61 RE -
testcase_62 RE -
testcase_63 RE -
testcase_64 RE -
testcase_65 RE -
testcase_66 RE -
testcase_67 RE -
testcase_68 RE -
testcase_69 RE -
testcase_70 RE -
testcase_71 RE -
testcase_72 RE -
testcase_73 RE -
testcase_74 RE -
testcase_75 RE -
testcase_76 RE -
testcase_77 RE -
testcase_78 RE -
testcase_79 RE -
testcase_80 RE -
testcase_81 RE -
testcase_82 RE -
testcase_83 RE -
testcase_84 RE -
testcase_85 RE -
testcase_86 RE -
testcase_87 RE -
testcase_88 RE -
testcase_89 RE -
testcase_90 RE -
testcase_91 RE -
testcase_92 RE -
testcase_93 RE -
testcase_94 RE -
testcase_95 RE -
testcase_96 RE -
testcase_97 RE -
testcase_98 RE -
testcase_99 RE -
権限があれば一括ダウンロードができます

ソースコード

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 <bitset>
#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 = 700;

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

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

int final_score = -1;
vector<int> final_ans = vector<int>(BIT_SIZE, 0);

const int N_BITSET = 128;
u64 beg_satisfied[N_BITSET] = {};
u64 satisfied[N_BITSET] = {};

int calc_score(const vector<int>& ans){
    rep(i,N){
        bool ok = false;
        if((beg_satisfied[i/64]>>(i%64)) & 1) continue;
        rep(t,3) if(ans[A[i][t][0]] == A[i][t][1]){ ok = true; break; }
        if(!ok) return i;
    }
    return N;
}

void update_satisfied(const vector<int>& ans, int p){
    for(int ei=edges_i[p]; ei<edges_i[p+1]; ei++){
        int i = edges[ei];
        if((beg_satisfied[i/64]>>(i%64)) & 1) continue;
        bool ok = false;
        rep(t,3) if(ans[A[i][t][0]] == A[i][t][1]){ ok = true; break; }
        u64 mask = (u64)1 << (i%64);
        satisfied[i/64] &= ~mask;
        satisfied[i/64] |= (ok ? (u64)1 : (u64)0) << (i%64);
    }
}

void initialize_satisfied(const vector<int>& ans){
    rep(i,N){
        bool ok = false;
        if((beg_satisfied[i/64]>>(i%64)) & 1) continue;
        rep(t,3) if(ans[A[i][t][0]] == A[i][t][1]){ ok = true; break; }
        u64 mask = (u64)1 << (i%64);
        satisfied[i/64] &= ~mask;
        satisfied[i/64] |= (ok ? (u64)1 : (u64)0) << (i%64);
    }
}

int calc_score2(){
    rep(i,N_BITSET) if(satisfied[i] != ~(u64)0) return i * 64 + __builtin_ctzll(~satisfied[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());
    
    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;

    rep(i,N_BITSET) satisfied[i] = beg_satisfied[i];

    edges_i.assign(BIT_SIZE + 1, 0);
    rep(i,N) rep(t,3) edges_i[A[i][t][0]]++;
    rep(i,BIT_SIZE) edges_i[i+1] += edges_i[i];
    edges.resize(edges_i.back());
    rep(i,N) rep(t,3) edges[--edges_i[A[i][t][0]]] = i;

    const int TIME_SPLIT_COUNT = 1;
    rep(time_split, TIME_SPLIT_COUNT){
        vector<int> ans = final_ans;
        rep(i,BIT_SIZE) ans[i] = rng.rng32() % 2;
        initialize_satisfied(ans);
        int pscore = calc_score2();
        while(true){
            auto end_time = chrono::high_resolution_clock::now();
            if((end_time - start_time).count() >= 1'000'000'000  * 1.5 / TIME_SPLIT_COUNT * (time_split + 1)) break;
            
            rep(t,1000){
                int p = rng.rng32() & 255;
                int q = rng.rng32() & 255;
                ans[p] ^= 1;
                ans[q] ^= 1;
                update_satisfied(ans, p);
                update_satisfied(ans, q);
                int score = calc_score2();
                if(final_score <= score){
                    final_ans = ans;
                    final_score = score;
                }
                if(pscore > score){
                    ans[p] ^= 1;
                    ans[q] ^= 1;
                    update_satisfied(ans, p);
                    update_satisfied(ans, q);
                }
                else pscore = score;
            }
        }
    }

    rep(i,BIT_SIZE) if(final_ans[i] == -1) final_ans[i] = 0;
    rep(i,BIT_SIZE) cout << final_ans[i];
    final_score = calc_score(final_ans);
    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