結果

問題 No.1355 AND OR GAME
ユーザー tarattata1tarattata1
提出日時 2021-01-17 14:42:10
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 92 ms / 2,000 ms
コード長 2,611 bytes
コンパイル時間 2,550 ms
コンパイル使用メモリ 93,776 KB
実行使用メモリ 5,688 KB
最終ジャッジ日時 2023-08-19 20:39:50
合計ジャッジ時間 11,583 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 1 ms
4,376 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 1 ms
4,380 KB
testcase_23 AC 1 ms
4,380 KB
testcase_24 AC 1 ms
4,380 KB
testcase_25 AC 1 ms
4,376 KB
testcase_26 AC 1 ms
4,376 KB
testcase_27 AC 1 ms
4,380 KB
testcase_28 AC 1 ms
4,380 KB
testcase_29 AC 1 ms
4,380 KB
testcase_30 AC 1 ms
4,376 KB
testcase_31 AC 1 ms
4,376 KB
testcase_32 AC 1 ms
4,376 KB
testcase_33 AC 2 ms
4,376 KB
testcase_34 AC 7 ms
4,376 KB
testcase_35 AC 55 ms
5,316 KB
testcase_36 AC 50 ms
5,368 KB
testcase_37 AC 1 ms
4,376 KB
testcase_38 AC 54 ms
5,688 KB
testcase_39 AC 17 ms
4,380 KB
testcase_40 AC 27 ms
4,376 KB
testcase_41 AC 54 ms
5,428 KB
testcase_42 AC 54 ms
5,484 KB
testcase_43 AC 26 ms
4,732 KB
testcase_44 AC 9 ms
4,380 KB
testcase_45 AC 54 ms
5,484 KB
testcase_46 AC 21 ms
4,376 KB
testcase_47 AC 55 ms
5,368 KB
testcase_48 AC 39 ms
4,652 KB
testcase_49 AC 54 ms
5,408 KB
testcase_50 AC 1 ms
4,380 KB
testcase_51 AC 28 ms
4,376 KB
testcase_52 AC 48 ms
5,048 KB
testcase_53 AC 34 ms
4,384 KB
testcase_54 AC 55 ms
5,372 KB
testcase_55 AC 39 ms
5,400 KB
testcase_56 AC 39 ms
5,404 KB
testcase_57 AC 38 ms
4,688 KB
testcase_58 AC 12 ms
4,380 KB
testcase_59 AC 1 ms
4,376 KB
testcase_60 AC 36 ms
4,732 KB
testcase_61 AC 2 ms
4,376 KB
testcase_62 AC 20 ms
4,380 KB
testcase_63 AC 54 ms
5,408 KB
testcase_64 AC 39 ms
5,372 KB
testcase_65 AC 2 ms
4,376 KB
testcase_66 AC 14 ms
4,380 KB
testcase_67 AC 19 ms
4,380 KB
testcase_68 AC 18 ms
4,380 KB
testcase_69 AC 2 ms
4,376 KB
testcase_70 AC 21 ms
4,376 KB
testcase_71 AC 56 ms
5,372 KB
testcase_72 AC 54 ms
5,408 KB
testcase_73 AC 54 ms
5,436 KB
testcase_74 AC 55 ms
5,668 KB
testcase_75 AC 54 ms
5,464 KB
testcase_76 AC 55 ms
5,404 KB
testcase_77 AC 54 ms
5,524 KB
testcase_78 AC 1 ms
4,380 KB
testcase_79 AC 1 ms
4,380 KB
testcase_80 AC 54 ms
5,364 KB
testcase_81 AC 55 ms
5,524 KB
testcase_82 AC 55 ms
5,652 KB
testcase_83 AC 39 ms
5,432 KB
testcase_84 AC 27 ms
4,380 KB
testcase_85 AC 72 ms
4,844 KB
testcase_86 AC 47 ms
4,380 KB
testcase_87 AC 41 ms
4,380 KB
testcase_88 AC 4 ms
4,380 KB
testcase_89 AC 3 ms
4,376 KB
testcase_90 AC 92 ms
5,264 KB
testcase_91 AC 10 ms
4,376 KB
testcase_92 AC 6 ms
4,376 KB
testcase_93 AC 66 ms
4,896 KB
testcase_94 AC 40 ms
4,376 KB
testcase_95 AC 28 ms
4,380 KB
testcase_96 AC 22 ms
4,376 KB
testcase_97 AC 5 ms
4,380 KB
testcase_98 AC 81 ms
5,404 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <cassert>
#include <numeric>
#include <functional>
#include <ctime>
#pragma warning(disable:4996) 

//#define ATCODER
#ifdef ATCODER
#include <atcoder/all>
#endif

typedef long long ll;
typedef unsigned long long ull;
#define LINF  9223300000000000000
#define LINF2 1223300000000000000
#define LINF3 1000000000000
#define INF 2140000000
//const long long MOD = 1000000007;
const long long MOD = 998244353;

using namespace std;
#ifdef ATCODER
using namespace atcoder;
#endif


void solve()
{
    int n; ll x, y;
    scanf("%d%lld%lld", &n, &x, &y);
    n++;
    vector<ll> a(n);
    a[0] = x;
    int i;
    for (i = 1; i < n; i++) {
        scanf("%lld", &a[i]);
    }
    vector<int> curr(60);
    for (i = 0; i < 60; i++) {
        curr[i] = ((y & (1LL<<i))?1:0);
    }
    int found = 0;
    vector<int> ans(n, 1);
    for (i = n - 1; i >= 0; i--) {
        int bad0 = 0, bad1 = 0;
        vector<int> vtmp(60);
        int k;
        for (k = 0; k < 60; k++) {
            vtmp[k]= ((a[i] & (1LL << k)) ? 1 : 0);
            if (vtmp[k] && curr[k] == 0) bad1 = 1;
            if (vtmp[k] == 0 && curr[k] == 1) bad0 = 1;
        }
        if (bad0 && bad1) {
            printf("-1\n"); return;
        }
        if (bad0 == 0 && bad1 == 0) {
            ans[i] = 3;
            found = 1;
            break;
        }
        if (bad1) {
            ans[i] = 1;
            vector<int> ne(60);
            for (k = 0; k < 60; k++) {
                ne[k] = 2;
                if (vtmp[k] == 1 && curr[k] == 0) ne[k] = 0;
                if (vtmp[k] == 1 && curr[k] == 1) ne[k] = 1;
            }
            curr.swap(ne);
        }
        else {
            ans[i] = 2;
            vector<int> ne(60);
            for (k = 0; k < 60; k++) {
                ne[k] = 2;
                if (vtmp[k] == 0 && curr[k] == 1) ne[k] = 1;
                if (vtmp[k] == 0 && curr[k] == 0) ne[k] = 0;
            }
            curr.swap(ne);
        }
    }
    if (found) {
        for (i = 1; i < n; i++) {
            printf("%d", ans[i]);
            if (i < n - 1) printf(" ");
            else printf("\n");
        }
    }
    else {
        printf("-1\n");
    }

    return;
}

int main()
{
#if 1
    solve();
#else
    int T, t;
    cin >> T;
    for (t = 0; t < T; t++) {
        //cout << "Case #" << t + 1 << ": ";
        solve();
    }
#endif
    return 0;
}
0