結果

問題 No.1355 AND OR GAME
ユーザー milanis48663220milanis48663220
提出日時 2021-05-11 22:21:49
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,399 bytes
コンパイル時間 1,211 ms
コンパイル使用メモリ 123,292 KB
実行使用メモリ 6,764 KB
最終ジャッジ日時 2023-10-22 03:45:55
合計ジャッジ時間 23,047 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 WA -
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 RE -
testcase_06 AC 2 ms
4,348 KB
testcase_07 RE -
testcase_08 RE -
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 WA -
testcase_16 RE -
testcase_17 AC 2 ms
4,348 KB
testcase_18 RE -
testcase_19 AC 2 ms
4,348 KB
testcase_20 RE -
testcase_21 RE -
testcase_22 AC 2 ms
4,348 KB
testcase_23 AC 2 ms
4,348 KB
testcase_24 WA -
testcase_25 RE -
testcase_26 RE -
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 RE -
testcase_32 RE -
testcase_33 AC 2 ms
4,348 KB
testcase_34 RE -
testcase_35 RE -
testcase_36 RE -
testcase_37 AC 2 ms
4,348 KB
testcase_38 RE -
testcase_39 AC 16 ms
4,348 KB
testcase_40 AC 24 ms
4,788 KB
testcase_41 RE -
testcase_42 RE -
testcase_43 AC 25 ms
4,788 KB
testcase_44 RE -
testcase_45 RE -
testcase_46 AC 19 ms
4,348 KB
testcase_47 RE -
testcase_48 RE -
testcase_49 RE -
testcase_50 WA -
testcase_51 RE -
testcase_52 RE -
testcase_53 RE -
testcase_54 RE -
testcase_55 AC 37 ms
5,580 KB
testcase_56 AC 37 ms
5,580 KB
testcase_57 RE -
testcase_58 RE -
testcase_59 AC 2 ms
4,348 KB
testcase_60 RE -
testcase_61 AC 2 ms
4,348 KB
testcase_62 AC 19 ms
4,348 KB
testcase_63 RE -
testcase_64 AC 38 ms
5,580 KB
testcase_65 RE -
testcase_66 AC 14 ms
4,348 KB
testcase_67 RE -
testcase_68 RE -
testcase_69 AC 2 ms
4,348 KB
testcase_70 RE -
testcase_71 RE -
testcase_72 RE -
testcase_73 AC 49 ms
6,372 KB
testcase_74 RE -
testcase_75 RE -
testcase_76 AC 48 ms
6,372 KB
testcase_77 RE -
testcase_78 AC 2 ms
4,348 KB
testcase_79 AC 2 ms
4,348 KB
testcase_80 RE -
testcase_81 RE -
testcase_82 RE -
testcase_83 AC 37 ms
5,580 KB
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 -
権限があれば一括ダウンロードができます

ソースコード

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) return false;
    auto u = as_vec(a[i]);
    bool ok_or = [&](){
        for(int i = 0; i <  60; i++) {
            if(u[i] != 1) continue;
            if(v[i] == 0) return false;
        }
        return true;
    }();

    bool ok_and = [&](){
        for(int i = 0; i < 60; i++) {
            if(u[i] != 0) continue;
            if(v[i] == 1) 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) 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) 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