結果

問題 No.1355 AND OR GAME
ユーザー maguromaguro
提出日時 2021-01-12 22:14:15
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 3,003 bytes
コンパイル時間 2,309 ms
コンパイル使用メモリ 208,120 KB
実行使用メモリ 58,824 KB
最終ジャッジ日時 2024-05-01 08:40:23
合計ジャッジ時間 18,439 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 3 ms
6,940 KB
testcase_03 AC 3 ms
6,944 KB
testcase_04 AC 3 ms
6,944 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 3 ms
6,944 KB
testcase_07 AC 3 ms
6,944 KB
testcase_08 AC 3 ms
6,940 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 2 ms
6,940 KB
testcase_11 AC 2 ms
6,944 KB
testcase_12 AC 2 ms
6,940 KB
testcase_13 AC 1 ms
6,940 KB
testcase_14 AC 1 ms
6,940 KB
testcase_15 AC 1 ms
6,940 KB
testcase_16 AC 1 ms
6,940 KB
testcase_17 AC 2 ms
6,940 KB
testcase_18 AC 1 ms
6,940 KB
testcase_19 AC 2 ms
6,940 KB
testcase_20 AC 1 ms
6,940 KB
testcase_21 AC 1 ms
6,944 KB
testcase_22 AC 1 ms
6,940 KB
testcase_23 AC 2 ms
6,940 KB
testcase_24 AC 1 ms
6,944 KB
testcase_25 AC 2 ms
6,940 KB
testcase_26 AC 2 ms
6,944 KB
testcase_27 AC 2 ms
6,940 KB
testcase_28 AC 2 ms
6,940 KB
testcase_29 AC 2 ms
6,940 KB
testcase_30 AC 1 ms
6,944 KB
testcase_31 AC 2 ms
6,944 KB
testcase_32 AC 2 ms
6,944 KB
testcase_33 AC 1 ms
6,940 KB
testcase_34 AC 22 ms
8,576 KB
testcase_35 AC 209 ms
58,648 KB
testcase_36 AC 187 ms
54,184 KB
testcase_37 AC 2 ms
6,940 KB
testcase_38 AC 215 ms
58,692 KB
testcase_39 AC 75 ms
25,344 KB
testcase_40 AC 97 ms
29,952 KB
testcase_41 AC 204 ms
58,528 KB
testcase_42 AC 208 ms
58,796 KB
testcase_43 AC 127 ms
39,580 KB
testcase_44 AC 33 ms
11,392 KB
testcase_45 AC 205 ms
58,668 KB
testcase_46 AC 77 ms
23,680 KB
testcase_47 AC 202 ms
58,512 KB
testcase_48 AC 143 ms
42,792 KB
testcase_49 AC 200 ms
58,784 KB
testcase_50 AC 1 ms
6,944 KB
testcase_51 AC 102 ms
30,976 KB
testcase_52 AC 181 ms
52,412 KB
testcase_53 AC 133 ms
37,188 KB
testcase_54 AC 208 ms
58,684 KB
testcase_55 AC 187 ms
58,636 KB
testcase_56 AC 199 ms
58,628 KB
testcase_57 AC 143 ms
41,564 KB
testcase_58 AC 39 ms
13,824 KB
testcase_59 AC 2 ms
6,944 KB
testcase_60 AC 139 ms
39,936 KB
testcase_61 AC 1 ms
6,940 KB
testcase_62 AC 94 ms
30,208 KB
testcase_63 AC 203 ms
58,632 KB
testcase_64 AC 189 ms
58,772 KB
testcase_65 AC 3 ms
6,944 KB
testcase_66 AC 64 ms
21,888 KB
testcase_67 AC 65 ms
20,864 KB
testcase_68 AC 64 ms
20,608 KB
testcase_69 AC 1 ms
6,940 KB
testcase_70 AC 76 ms
23,936 KB
testcase_71 AC 220 ms
58,720 KB
testcase_72 AC 201 ms
58,720 KB
testcase_73 AC 201 ms
58,820 KB
testcase_74 AC 209 ms
58,764 KB
testcase_75 AC 211 ms
58,656 KB
testcase_76 AC 209 ms
58,824 KB
testcase_77 AC 218 ms
58,796 KB
testcase_78 AC 2 ms
6,944 KB
testcase_79 AC 2 ms
6,940 KB
testcase_80 AC 210 ms
58,700 KB
testcase_81 AC 203 ms
58,680 KB
testcase_82 AC 212 ms
58,732 KB
testcase_83 AC 188 ms
58,540 KB
testcase_84 AC 54 ms
20,352 KB
testcase_85 RE -
testcase_86 RE -
testcase_87 RE -
testcase_88 AC 8 ms
6,944 KB
testcase_89 RE -
testcase_90 RE -
testcase_91 AC 20 ms
9,216 KB
testcase_92 RE -
testcase_93 AC 151 ms
48,328 KB
testcase_94 AC 81 ms
29,824 KB
testcase_95 AC 59 ms
22,144 KB
testcase_96 AC 45 ms
17,664 KB
testcase_97 AC 9 ms
6,944 KB
testcase_98 AC 177 ms
58,468 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;
    if(N == 1) {
        ll A;
        cin >> A;
        if(A == Y) {
            cout << 3 << endl;
        }
        else if((X & A) == Y) {
            cout << 1 << endl;
        }
        else if((X | A) == Y) {
            cout << 2 << endl;
        }
        else {
            cout << -1 << endl;
        }
        return 0;
    }
    vector<vector<int>> vec(N + 1,vector<int>(62));
    for(int i = 0;i < N;i++) {
        ll A;
        cin >> A;
        for(int j = 0;j < 62;j++) {
            vec.at(i + 1).at(j) = A % 2;
            A /= 2;
        }
    }
    reverse(vec.begin(),vec.end());
    for(int i = 0;i < 62;i++) {
        vec.at(N).at(i) = X % 2;
        X /= 2;
    }
    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(!ret) cout << -1 << endl;
    else {
        reverse(ret2.begin(),ret2.end());
        for(int i = 0;i < N;i++) {
            cout << ret2.at(i) << " ";
        }
        cout << endl;
    }
}
0