結果

問題 No.2024 Xer
ユーザー 👑 Nachia
提出日時 2022-07-29 23:08:54
言語 C++17(gcc12)
(gcc 12.3.0 + boost 1.87.0)
結果
AC  
実行時間 64 ms / 2,000 ms
コード長 1,715 bytes
コンパイル時間 3,843 ms
コンパイル使用メモリ 123,884 KB
最終ジャッジ日時 2025-01-30 15:40:57
ジャッジサーバーID
(参考情報)
judge2 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 47
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#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>;

const int t1 = 525118 ^ 36251;
const int t2 = 575820 ^ 36251;

bool solve(vector<u32> A, u32 X){
    sort(A.begin(), A.end());
    int N = A.size();
    vector<u32> A2[2];
    rep(i,N){
        if(A[i] < (A[i]^X)) A2[0].push_back(A[i]); else A2[1].push_back(A[i]);
    }

    bool ans = false;
    rep(t,2){
        vector<u32> A3;
        rep(i,N) rep(d,2) if(i < (int)A2[d].size()) A3.push_back(A2[d][i]);
        bool ok = true;
        rep(i,N-1) if(A3[i] >= (A3[i+1]^X) || (A3[i]^X) >= A3[i+1]) ok = false;
        ans = ans || ok;
        swap(A2[0], A2[1]);
    }
    return ans;
}

int main(){
    int N; cin >> N;
    u32 X; cin >> X;
    vector<u32> A(N); rep(i,N) cin >> A[i];
    sort(A.begin(), A.end());
    rep(i,N-1) if(A[i] == A[i+1]){ cout << "No\n"; return 0; }
    u32 D = 1; while(D <= X){ D *= 2; } D--;

    bool ans = true;
    while(A.size()){
        vector<u32> tmp = {A.back()}; A.pop_back();
        while(A.size()){
            u32 a = A.back();
            if((a&~D) != (tmp.back()&~D)) break;
            tmp.push_back(a);
            A.pop_back();
        }
        ans = ans && solve(move(tmp), X);
    }

    cout << (ans ? "Yes\n" : "No\n");
    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