結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 4 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 4 ms
5,376 KB
testcase_09 AC 3 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 1 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 2 ms
5,376 KB
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 1 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
6,940 KB
testcase_21 AC 2 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 1 ms
5,376 KB
testcase_30 AC 2 ms
5,376 KB
testcase_31 AC 2 ms
5,376 KB
testcase_32 AC 2 ms
5,376 KB
testcase_33 AC 2 ms
5,376 KB
testcase_34 AC 23 ms
8,704 KB
testcase_35 AC 220 ms
58,752 KB
testcase_36 AC 205 ms
54,196 KB
testcase_37 AC 2 ms
5,376 KB
testcase_38 AC 213 ms
58,740 KB
testcase_39 AC 80 ms
25,472 KB
testcase_40 AC 104 ms
29,952 KB
testcase_41 AC 218 ms
58,752 KB
testcase_42 AC 214 ms
58,624 KB
testcase_43 AC 131 ms
39,808 KB
testcase_44 AC 34 ms
11,392 KB
testcase_45 AC 220 ms
58,624 KB
testcase_46 AC 83 ms
23,680 KB
testcase_47 AC 219 ms
58,736 KB
testcase_48 AC 159 ms
42,752 KB
testcase_49 AC 221 ms
58,624 KB
testcase_50 AC 2 ms
5,376 KB
testcase_51 AC 114 ms
30,976 KB
testcase_52 AC 195 ms
52,480 KB
testcase_53 AC 140 ms
37,248 KB
testcase_54 AC 219 ms
58,880 KB
testcase_55 AC 203 ms
58,624 KB
testcase_56 AC 198 ms
58,688 KB
testcase_57 AC 150 ms
41,840 KB
testcase_58 AC 45 ms
13,696 KB
testcase_59 AC 2 ms
5,376 KB
testcase_60 AC 146 ms
39,936 KB
testcase_61 AC 2 ms
5,376 KB
testcase_62 AC 102 ms
30,336 KB
testcase_63 AC 214 ms
58,624 KB
testcase_64 AC 200 ms
58,724 KB
testcase_65 AC 4 ms
5,376 KB
testcase_66 AC 69 ms
22,016 KB
testcase_67 AC 71 ms
20,736 KB
testcase_68 AC 70 ms
20,608 KB
testcase_69 AC 2 ms
5,376 KB
testcase_70 AC 84 ms
24,064 KB
testcase_71 AC 216 ms
58,752 KB
testcase_72 AC 216 ms
58,720 KB
testcase_73 AC 218 ms
58,732 KB
testcase_74 AC 211 ms
58,664 KB
testcase_75 AC 209 ms
58,640 KB
testcase_76 AC 213 ms
58,640 KB
testcase_77 AC 214 ms
58,624 KB
testcase_78 AC 2 ms
5,376 KB
testcase_79 AC 1 ms
5,376 KB
testcase_80 AC 212 ms
58,700 KB
testcase_81 AC 213 ms
58,684 KB
testcase_82 AC 220 ms
58,660 KB
testcase_83 AC 195 ms
58,496 KB
testcase_84 AC 61 ms
20,352 KB
testcase_85 AC 158 ms
44,928 KB
testcase_86 AC 98 ms
29,312 KB
testcase_87 AC 88 ms
26,240 KB
testcase_88 AC 8 ms
5,376 KB
testcase_89 AC 7 ms
5,376 KB
testcase_90 AC 199 ms
55,888 KB
testcase_91 AC 22 ms
9,344 KB
testcase_92 AC 11 ms
5,888 KB
testcase_93 AC 157 ms
48,384 KB
testcase_94 AC 95 ms
29,684 KB
testcase_95 AC 67 ms
22,144 KB
testcase_96 AC 53 ms
17,792 KB
testcase_97 AC 10 ms
5,760 KB
testcase_98 AC 190 ms
58,604 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;
    vector<vector<int>> vec(N,vector<int>(62));
    for(int i = 0;i < N;i++) {
        ll A;
        cin >> A;
        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