結果

問題 No.1969 XOR Equation
ユーザー 👑 NachiaNachia
提出日時 2022-06-03 21:56:56
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 60 ms / 2,000 ms
コード長 2,101 bytes
コンパイル時間 899 ms
コンパイル使用メモリ 88,504 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-21 02:30:37
合計ジャッジ時間 3,203 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 3 ms
4,348 KB
testcase_03 AC 1 ms
4,348 KB
testcase_04 AC 1 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 30 ms
4,348 KB
testcase_10 AC 31 ms
4,348 KB
testcase_11 AC 31 ms
4,348 KB
testcase_12 AC 31 ms
4,348 KB
testcase_13 AC 21 ms
4,348 KB
testcase_14 AC 18 ms
4,348 KB
testcase_15 AC 57 ms
4,348 KB
testcase_16 AC 55 ms
4,348 KB
testcase_17 AC 58 ms
4,348 KB
testcase_18 AC 56 ms
4,348 KB
testcase_19 AC 54 ms
4,348 KB
testcase_20 AC 26 ms
4,348 KB
testcase_21 AC 39 ms
4,348 KB
testcase_22 AC 50 ms
4,348 KB
testcase_23 AC 28 ms
4,348 KB
testcase_24 AC 41 ms
4,348 KB
testcase_25 AC 37 ms
4,348 KB
testcase_26 AC 35 ms
4,348 KB
testcase_27 AC 56 ms
4,348 KB
testcase_28 AC 55 ms
4,348 KB
testcase_29 AC 55 ms
4,348 KB
testcase_30 AC 56 ms
4,348 KB
testcase_31 AC 58 ms
4,348 KB
testcase_32 AC 57 ms
4,348 KB
testcase_33 AC 58 ms
4,348 KB
testcase_34 AC 55 ms
4,348 KB
testcase_35 AC 46 ms
4,348 KB
testcase_36 AC 60 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <atcoder/modint>
using namespace std;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
#define rep(i,n) for(int i=0; i<(int)(n); i++)


const i64 INF = 1001001001001001001;
using modint = atcoder::static_modint<998244353>;


void testcase(){
    int N; cin >> N;
    u64 Y; cin >> Y;
    vector<u64> A(N); rep(i,N) cin >> A[i];
    vector<u64> B = A;
    const u64 IMPOSSIBLE = ~(u64)0;
    vector<u64> dp = {0};
    rep(d,61){
        u64 lowerBit1 = ((u64)1 << d) - 1;
        u64 lowerBit = ((u64)1 << (d + 1)) - 1;
        auto cmpByLowerBit1 = [lowerBit1](u64 l, u64 r) -> bool { return (l & lowerBit1) < (r & lowerBit1); };
        auto cmpByLowerBit = [lowerBit](u64 l, u64 r) -> bool { return (l & lowerBit) < (r & lowerBit); };
        sort(A.begin(), A.end(), cmpByLowerBit1);
        sort(B.begin(), B.end(), cmpByLowerBit);
        vector<u64> tmp(N + 1, IMPOSSIBLE);

        int rawcnt = 0;
        for(u64 a : A) if(a & ((u64)1 << d)) rawcnt ^= 1;
        int tgcnt = (Y >> d) & 1;

        for(u64 x : dp){
            int p = A.end() - lower_bound(A.begin(), A.end(), ((u64)1 << d) - x, cmpByLowerBit1);
            if(x == 0) p = 0;
            rep(t,2) if(d != 60 || t == 0){
                u64 nx = x | ((u64)t << d);
                int q = p & 1;
                if((rawcnt ^ q ^ ((t*N)&1)) != tgcnt) continue;

                int pp = B.end() - lower_bound(B.begin(), B.end(), ((u64)1 << (d + 1)) - nx, cmpByLowerBit);
                if(nx == 0) pp = 0;
                tmp[pp] = min(tmp[pp], nx);
            }
        }

        dp.clear();
        for(u64 x : tmp) if(x != IMPOSSIBLE) dp.push_back(x);

    }

    u64 ans = IMPOSSIBLE;
    for(auto a : dp) ans = min(ans, a);
    cout << (i64)ans << '\n';

}


int main(){
    int T; cin >> T;
    while(T --> 0) testcase();
    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