結果

問題 No.1355 AND OR GAME
ユーザー maguromaguro
提出日時 2021-01-12 22:29:02
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 234 ms / 2,000 ms
コード長 3,057 bytes
コンパイル時間 2,299 ms
コンパイル使用メモリ 208,764 KB
実行使用メモリ 58,880 KB
最終ジャッジ日時 2024-05-01 08:55:23
合計ジャッジ時間 17,423 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 3 ms
5,376 KB
testcase_03 AC 3 ms
5,376 KB
testcase_04 AC 3 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 3 ms
5,376 KB
testcase_07 AC 3 ms
5,376 KB
testcase_08 AC 3 ms
5,376 KB
testcase_09 AC 3 ms
5,376 KB
testcase_10 AC 1 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 1 ms
5,376 KB
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 2 ms
5,376 KB
testcase_18 AC 2 ms
5,376 KB
testcase_19 AC 1 ms
5,376 KB
testcase_20 AC 2 ms
5,376 KB
testcase_21 AC 1 ms
5,376 KB
testcase_22 AC 2 ms
5,376 KB
testcase_23 AC 2 ms
5,376 KB
testcase_24 AC 2 ms
5,376 KB
testcase_25 AC 2 ms
5,376 KB
testcase_26 AC 2 ms
5,376 KB
testcase_27 AC 2 ms
5,376 KB
testcase_28 AC 2 ms
5,376 KB
testcase_29 AC 2 ms
5,376 KB
testcase_30 AC 2 ms
5,376 KB
testcase_31 AC 2 ms
5,376 KB
testcase_32 AC 1 ms
5,376 KB
testcase_33 AC 2 ms
5,376 KB
testcase_34 AC 23 ms
8,576 KB
testcase_35 AC 219 ms
58,624 KB
testcase_36 AC 206 ms
54,204 KB
testcase_37 AC 2 ms
5,376 KB
testcase_38 AC 226 ms
58,752 KB
testcase_39 AC 83 ms
25,344 KB
testcase_40 AC 105 ms
29,904 KB
testcase_41 AC 226 ms
58,752 KB
testcase_42 AC 225 ms
58,724 KB
testcase_43 AC 138 ms
39,808 KB
testcase_44 AC 35 ms
11,392 KB
testcase_45 AC 225 ms
58,636 KB
testcase_46 AC 85 ms
23,680 KB
testcase_47 AC 228 ms
58,752 KB
testcase_48 AC 165 ms
42,880 KB
testcase_49 AC 230 ms
58,752 KB
testcase_50 AC 2 ms
5,376 KB
testcase_51 AC 118 ms
30,976 KB
testcase_52 AC 204 ms
52,464 KB
testcase_53 AC 142 ms
37,264 KB
testcase_54 AC 234 ms
58,752 KB
testcase_55 AC 213 ms
58,624 KB
testcase_56 AC 211 ms
58,880 KB
testcase_57 AC 160 ms
41,728 KB
testcase_58 AC 46 ms
13,696 KB
testcase_59 AC 2 ms
5,376 KB
testcase_60 AC 154 ms
39,936 KB
testcase_61 AC 2 ms
5,376 KB
testcase_62 AC 106 ms
30,336 KB
testcase_63 AC 232 ms
58,632 KB
testcase_64 AC 212 ms
58,708 KB
testcase_65 AC 4 ms
5,376 KB
testcase_66 AC 72 ms
21,888 KB
testcase_67 AC 76 ms
20,864 KB
testcase_68 AC 74 ms
20,608 KB
testcase_69 AC 2 ms
5,376 KB
testcase_70 AC 88 ms
23,936 KB
testcase_71 AC 233 ms
58,752 KB
testcase_72 AC 232 ms
58,760 KB
testcase_73 AC 230 ms
58,688 KB
testcase_74 AC 232 ms
58,624 KB
testcase_75 AC 229 ms
58,724 KB
testcase_76 AC 228 ms
58,752 KB
testcase_77 AC 230 ms
58,720 KB
testcase_78 AC 2 ms
5,376 KB
testcase_79 AC 2 ms
5,376 KB
testcase_80 AC 228 ms
58,752 KB
testcase_81 AC 231 ms
58,724 KB
testcase_82 AC 227 ms
58,752 KB
testcase_83 AC 213 ms
58,496 KB
testcase_84 AC 65 ms
20,480 KB
testcase_85 AC 163 ms
44,804 KB
testcase_86 AC 106 ms
29,184 KB
testcase_87 AC 93 ms
26,240 KB
testcase_88 AC 8 ms
5,504 KB
testcase_89 AC 6 ms
5,376 KB
testcase_90 AC 205 ms
55,808 KB
testcase_91 AC 22 ms
9,216 KB
testcase_92 AC 10 ms
6,016 KB
testcase_93 AC 160 ms
48,176 KB
testcase_94 AC 94 ms
29,696 KB
testcase_95 AC 71 ms
22,144 KB
testcase_96 AC 52 ms
17,664 KB
testcase_97 AC 9 ms
5,760 KB
testcase_98 AC 189 ms
58,496 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr int Inf = 1000000030;
constexpr ll INF= 2000000000000000000;
constexpr ll MOD = 1000000007;
const double PI = 3.1415926535897;
typedef pair<ll,ll> P;
typedef pair<ll,P> PP;

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

ll mod(ll val, ll M) {
    val = val % M;
    if(val < 0) {
        val += M;
    }
    return val;
}

template<typename T>
T RS(T N, T P, T M){
    if(P == 0) {
        return 1;
    }
    if(P < 0) {
        return 0;
    }
    if(P % 2 == 0){
        ll t = RS(N, P/2, M);
        if(M == -1) return t * t;
        return t * t % M;
    }
    if(M == -1) {
        return N * RS(N,P - 1,M);
    }
    return N * RS(N, P-1, M) % M;
}

int main() {
    int N;
    ll X,Y;
    cin >> N >> X >> Y;
    assert(1 <= N && N <= 200000);
    assert(0ll <= X && X <= 1000000000000000000ll);
    assert(0ll <= Y && Y <= 1000000000000000000ll);
    vector<vector<int>> vec(N,vector<int>(62));
    for(int i = 0;i < N;i++) {
        ll A;
        cin >> A;
        assert(0ll <= A && A <= 1000000000000000000ll);
        for(int j = 0;j < 62;j++) {
            vec.at(i).at(j) = A % 2;
            A /= 2;
        }
    }
    reverse(vec.begin(),vec.end());
    vector<int> now(62);
    for(int i = 0;i < 62;i++) {
        now.at(i) = Y % 2;
        Y /= 2;
    }
    bool ret = false;
    vector<int> ret2(N,1);
    for(int i = 0;i < N;i++) {
        bool cnt1 = false;
        bool cnt2 = false;
        for(int j = 0;j < 62;j++) {
            if(now.at(j) == 1 && vec.at(i).at(j) == 0) {
                cnt1 = true;
            }
            else if(now.at(j) == 0 && vec.at(i).at(j) == 1) {
                cnt2 = true;
            }
        }
        if(cnt1 && cnt2) {
            break;
        }
        else if(!(cnt1 || cnt2)) {
            ret = true;
            ret2.at(i) = 3;
            break;
        }
        else if(cnt1) {
            ret2.at(i) = 2;
            for(int j = 0;j < 62;j++) {
                if(now.at(j) == 1) {
                    if(vec.at(i).at(j) == 1) now.at(j) = 2;
                }
            }
        }
        else {
            ret2.at(i) = 1;
            for(int j = 0;j < 62;j++) {
                if(now.at(j) == 0) {
                    if(vec.at(i).at(j) == 0) now.at(j) = 2;
                }
            }
        }

        if(i == N - 1) {
            bool cnt3 = true;
            for(int j = 0;j < 62;j++) {
                if(now.at(j) != 2 && now.at(j) != X % 2) {
                    cnt3 = false;
                }
                X /= 2;
            }
            if(cnt3) ret = true;
        }
    }
    
    if(!ret) cout << -1 << endl;
    else {
        reverse(ret2.begin(),ret2.end());
        for(int i = 0;i < N;i++) {
            cout << ret2.at(i) << " ";
        }
        cout << endl;
    }
}
0