結果

問題 No.5005 3-SAT
ユーザー 👑 NachiaNachia
提出日時 2022-04-29 19:00:11
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 1,802 ms / 2,000 ms
コード長 4,301 bytes
コンパイル時間 1,235 ms
実行使用メモリ 6,948 KB
スコア 103,204
最終ジャッジ日時 2022-04-29 19:03:19
合計ジャッジ時間 187,301 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
純コード判定しない問題か言語
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,802 ms
3,484 KB
testcase_01 AC 1,801 ms
3,576 KB
testcase_02 AC 1,801 ms
3,664 KB
testcase_03 AC 1,802 ms
3,624 KB
testcase_04 AC 1,802 ms
3,528 KB
testcase_05 AC 1,802 ms
3,636 KB
testcase_06 AC 1,802 ms
3,540 KB
testcase_07 AC 1,801 ms
3,632 KB
testcase_08 AC 1,801 ms
3,480 KB
testcase_09 AC 1,802 ms
3,632 KB
testcase_10 AC 1,802 ms
3,572 KB
testcase_11 AC 1,802 ms
3,664 KB
testcase_12 AC 1,802 ms
3,528 KB
testcase_13 AC 1,801 ms
3,576 KB
testcase_14 AC 1,801 ms
3,600 KB
testcase_15 AC 1,801 ms
3,476 KB
testcase_16 AC 1,801 ms
3,544 KB
testcase_17 AC 1,802 ms
3,624 KB
testcase_18 AC 1,802 ms
3,528 KB
testcase_19 AC 1,801 ms
3,660 KB
testcase_20 AC 1,802 ms
3,480 KB
testcase_21 AC 1,802 ms
3,632 KB
testcase_22 AC 1,802 ms
3,528 KB
testcase_23 AC 1,802 ms
3,480 KB
testcase_24 AC 1,802 ms
3,620 KB
testcase_25 AC 1,801 ms
3,480 KB
testcase_26 AC 1,801 ms
3,572 KB
testcase_27 AC 1,802 ms
3,716 KB
testcase_28 AC 1,802 ms
3,624 KB
testcase_29 AC 1,802 ms
3,548 KB
testcase_30 AC 1,801 ms
3,528 KB
testcase_31 AC 1,802 ms
3,596 KB
testcase_32 AC 1,800 ms
3,712 KB
testcase_33 AC 1,802 ms
3,476 KB
testcase_34 AC 1,802 ms
3,544 KB
testcase_35 AC 1,801 ms
3,608 KB
testcase_36 AC 1,801 ms
3,476 KB
testcase_37 AC 1,802 ms
3,576 KB
testcase_38 AC 1,801 ms
3,716 KB
testcase_39 AC 1,801 ms
3,612 KB
testcase_40 AC 1,802 ms
3,716 KB
testcase_41 AC 1,802 ms
3,604 KB
testcase_42 AC 1,801 ms
3,712 KB
testcase_43 AC 1,801 ms
3,716 KB
testcase_44 AC 1,802 ms
3,600 KB
testcase_45 AC 1,801 ms
3,544 KB
testcase_46 AC 1,802 ms
3,480 KB
testcase_47 AC 1,801 ms
3,544 KB
testcase_48 AC 1,802 ms
3,480 KB
testcase_49 AC 1,801 ms
3,632 KB
testcase_50 AC 1,802 ms
3,628 KB
testcase_51 AC 1,801 ms
3,712 KB
testcase_52 AC 1,801 ms
3,576 KB
testcase_53 AC 1,801 ms
3,624 KB
testcase_54 AC 1,802 ms
3,612 KB
testcase_55 AC 1,801 ms
3,716 KB
testcase_56 AC 1,802 ms
3,544 KB
testcase_57 AC 1,802 ms
4,904 KB
testcase_58 AC 1,802 ms
5,160 KB
testcase_59 AC 1,801 ms
4,900 KB
testcase_60 AC 1,802 ms
4,908 KB
testcase_61 AC 1,801 ms
4,904 KB
testcase_62 AC 1,802 ms
5,160 KB
testcase_63 AC 1,802 ms
4,900 KB
testcase_64 AC 1,800 ms
4,900 KB
testcase_65 AC 1,802 ms
4,900 KB
testcase_66 AC 1,802 ms
4,904 KB
testcase_67 AC 1,802 ms
4,904 KB
testcase_68 AC 1,802 ms
4,904 KB
testcase_69 AC 1,801 ms
4,904 KB
testcase_70 AC 1,801 ms
3,572 KB
testcase_71 AC 1,801 ms
4,904 KB
testcase_72 AC 1,802 ms
5,160 KB
testcase_73 AC 1,801 ms
4,908 KB
testcase_74 AC 1,801 ms
4,904 KB
testcase_75 AC 1,801 ms
4,908 KB
testcase_76 AC 1,800 ms
4,900 KB
testcase_77 AC 1,801 ms
5,160 KB
testcase_78 AC 1,802 ms
5,156 KB
testcase_79 AC 1,801 ms
4,904 KB
testcase_80 AC 1,802 ms
4,904 KB
testcase_81 AC 1,802 ms
5,164 KB
testcase_82 AC 1,801 ms
4,900 KB
testcase_83 AC 1,800 ms
4,900 KB
testcase_84 AC 1,802 ms
4,904 KB
testcase_85 AC 1,801 ms
4,904 KB
testcase_86 AC 1,802 ms
4,900 KB
testcase_87 AC 1,801 ms
5,160 KB
testcase_88 AC 1,801 ms
4,900 KB
testcase_89 AC 1,801 ms
4,904 KB
testcase_90 AC 1,802 ms
4,900 KB
testcase_91 AC 1,802 ms
3,472 KB
testcase_92 AC 1,802 ms
4,904 KB
testcase_93 AC 1,801 ms
6,948 KB
testcase_94 AC 1,801 ms
4,904 KB
testcase_95 AC 1,801 ms
4,900 KB
testcase_96 AC 1,801 ms
6,948 KB
testcase_97 AC 1,802 ms
6,948 KB
testcase_98 AC 1,802 ms
4,900 KB
testcase_99 AC 1,801 ms
4,900 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")


#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);
    }
};

#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;
int A[N][3][2] = {};
int edges[N*6] = {};
int edges_i[N+1] = {};

int final_score = -1;
int ans[BIT_SIZE] = {};
int final_ans[BIT_SIZE] = {};

const int N_BITSET = 32;
u64 satisfied[N_BITSET] = {};

int calc_score(int* ans){
    rep(i,N){
        bool ok = false;
        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(int* ans, int p){
    for(int ei=edges_i[p]; ei<edges_i[p+1]; ei++){
        int i = edges[ei];
        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(int* ans){
    rep(i,N){
        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);
    }
}

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();

    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_BITSET) satisfied[i] = 0;

    for(int i=0; i<=BIT_SIZE; i++) edges_i[i] = 0;
    rep(i,1200) rep(t,3) edges_i[A[i][t][0]]++;
    rep(i,BIT_SIZE) edges_i[i+1] += edges_i[i];
    rep(i,1200) rep(t,3) edges[--edges_i[A[i][t][0]]] = i;

    int attempts = 0;

    const int TIME_SPLIT_COUNT = 10;
    rep(time_split, TIME_SPLIT_COUNT){
        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.8 / TIME_SPLIT_COUNT * (time_split + 1)) break;
            
            rep(t,1000){
                attempts++;
                int p = rng.rng32() & 255;
                ans[p] ^= 1;
                update_satisfied(ans, p);
                int score = calc_score2();
                if(final_score < score){
                    rep(i,BIT_SIZE) final_ans[i] = ans[i];
                    final_score = score;
                }
                if(pscore > score){
                    ans[p] ^= 1;
                    update_satisfied(ans, p);
                }
                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;

    cerr << "attempts = " << attempts << 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