結果

問題 No.1355 AND OR GAME
ユーザー milanis48663220milanis48663220
提出日時 2021-05-11 22:28:07
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 182 ms / 2,000 ms
コード長 2,637 bytes
コンパイル時間 1,213 ms
コンパイル使用メモリ 123,228 KB
実行使用メモリ 133,364 KB
最終ジャッジ日時 2023-10-22 03:52:12
合計ジャッジ時間 10,763 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 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 2 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 2 ms
4,348 KB
testcase_14 AC 2 ms
4,348 KB
testcase_15 AC 2 ms
4,348 KB
testcase_16 AC 2 ms
4,348 KB
testcase_17 AC 2 ms
4,348 KB
testcase_18 AC 2 ms
4,348 KB
testcase_19 AC 2 ms
4,348 KB
testcase_20 AC 2 ms
4,348 KB
testcase_21 AC 2 ms
4,348 KB
testcase_22 AC 2 ms
4,348 KB
testcase_23 AC 2 ms
4,348 KB
testcase_24 AC 1 ms
4,348 KB
testcase_25 AC 2 ms
4,348 KB
testcase_26 AC 2 ms
4,348 KB
testcase_27 AC 2 ms
4,348 KB
testcase_28 AC 2 ms
4,348 KB
testcase_29 AC 2 ms
4,348 KB
testcase_30 AC 2 ms
4,348 KB
testcase_31 AC 2 ms
4,348 KB
testcase_32 AC 2 ms
4,348 KB
testcase_33 AC 2 ms
4,348 KB
testcase_34 AC 6 ms
4,348 KB
testcase_35 AC 44 ms
6,380 KB
testcase_36 AC 40 ms
6,116 KB
testcase_37 AC 2 ms
4,348 KB
testcase_38 AC 46 ms
6,380 KB
testcase_39 AC 15 ms
4,348 KB
testcase_40 AC 21 ms
4,796 KB
testcase_41 AC 46 ms
6,380 KB
testcase_42 AC 43 ms
6,380 KB
testcase_43 AC 23 ms
4,796 KB
testcase_44 AC 8 ms
4,348 KB
testcase_45 AC 43 ms
6,380 KB
testcase_46 AC 16 ms
4,348 KB
testcase_47 AC 42 ms
6,380 KB
testcase_48 AC 32 ms
5,588 KB
testcase_49 AC 45 ms
6,380 KB
testcase_50 AC 1 ms
4,348 KB
testcase_51 AC 23 ms
4,796 KB
testcase_52 AC 38 ms
6,116 KB
testcase_53 AC 27 ms
5,060 KB
testcase_54 AC 43 ms
6,380 KB
testcase_55 AC 33 ms
5,588 KB
testcase_56 AC 34 ms
5,588 KB
testcase_57 AC 30 ms
5,324 KB
testcase_58 AC 10 ms
4,348 KB
testcase_59 AC 2 ms
4,348 KB
testcase_60 AC 31 ms
5,324 KB
testcase_61 AC 1 ms
4,348 KB
testcase_62 AC 18 ms
4,348 KB
testcase_63 AC 43 ms
6,380 KB
testcase_64 AC 34 ms
5,588 KB
testcase_65 AC 2 ms
4,348 KB
testcase_66 AC 13 ms
4,348 KB
testcase_67 AC 15 ms
4,348 KB
testcase_68 AC 15 ms
4,348 KB
testcase_69 AC 2 ms
4,348 KB
testcase_70 AC 17 ms
4,532 KB
testcase_71 AC 43 ms
6,380 KB
testcase_72 AC 44 ms
6,380 KB
testcase_73 AC 44 ms
6,380 KB
testcase_74 AC 43 ms
6,380 KB
testcase_75 AC 42 ms
6,380 KB
testcase_76 AC 42 ms
6,380 KB
testcase_77 AC 43 ms
6,380 KB
testcase_78 AC 1 ms
4,348 KB
testcase_79 AC 2 ms
4,348 KB
testcase_80 AC 43 ms
6,380 KB
testcase_81 AC 44 ms
6,380 KB
testcase_82 AC 46 ms
6,380 KB
testcase_83 AC 36 ms
5,588 KB
testcase_84 AC 54 ms
43,604 KB
testcase_85 AC 140 ms
101,156 KB
testcase_86 AC 87 ms
64,460 KB
testcase_87 AC 82 ms
57,068 KB
testcase_88 AC 8 ms
8,248 KB
testcase_89 AC 6 ms
6,512 KB
testcase_90 AC 182 ms
127,028 KB
testcase_91 AC 21 ms
17,532 KB
testcase_92 AC 10 ms
9,412 KB
testcase_93 AC 145 ms
109,076 KB
testcase_94 AC 90 ms
65,516 KB
testcase_95 AC 64 ms
47,828 KB
testcase_96 AC 48 ms
37,100 KB
testcase_97 AC 9 ms
9,032 KB
testcase_98 AC 178 ms
133,364 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <tuple>
#include <cmath>
#include <numeric>
#include <functional>
#include <cassert>

#define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl;
#define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using namespace std;
typedef long long ll;

int n;
ll x, y;
vector<ll> a;

vector<int> as_vec(ll x){
    vector<int> v(60);
    for(int i = 0; i < 60; i++){
        if(((ll)1<<i) & x) v[i] = 1;
        else v[i] = 0;
    }
    return v;
}

bool dfs(int i, vector<int> &p, vector<int> v){
    // debug_value(i);
    if(i < 0) {
        for(int i = 0; i < 60; i++){
            if(x&((ll)1<<i)){
                if(v[i] == 0) return false;
            }else{
                if(v[i] == 1) return false;
            }
        }
        return true;
    }
    auto u = as_vec(a[i]);
    bool ok_or = [&](){
        for(int i = 0; i < 60; i++) {
            if(v[i] != 0) continue;
            if(u[i] == 1) return false;
        }
        return true;
    }();

    bool ok_and = [&](){
        for(int i = 0; i < 60; i++) {
            if(v[i] != 1) continue;
            if(u[i] == 0) return false;
        }
        return true;
    }();

    if(ok_or && ok_and){
        p[i] = 3;
        return true;
    }

    if(ok_or){
        for(int i = 0; i < 60; i++){
            if(v[i] == 1 && u[i] == 1) v[i] = 2;
        }
        p[i] = 2;
        return dfs(i-1, p, v);
    }

    if(ok_and){
        for(int i = 0; i < 60; i++){
            if(v[i] == 0 && u[i] == 0) v[i] = 2;
        }
        p[i] = 1;
        return dfs(i-1, p, v);
    }
    return false;
}

ll test(ll x, vector<int> p){
    for(int i = 0; i < n; i++){
        int t = p[i];
        if(t == 1) x &= a[i];
        if(t == 2) x |= a[i];
        if(t == 3) x = a[i];
    }
    return x;
}

void get_vec(vector<ll> &a){
    int n = a.size();
    for(int i = 0; i < n; i++) cin >> a[i];
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    cin >> n >> x >> y;
    a.resize(n);
    get_vec(a);
    vector<int> p(n, 1);
    vector<int> v = as_vec(y);
    if(dfs(n-1, p, v)) {
        assert(test(x, p) == y);
        for(int x : p) cout << x << ' ';
        cout << endl;
    }else{
        cout << -1 << endl;
    }
}
0