結果

問題 No.1355 AND OR GAME
ユーザー 👑 jupirojupiro
提出日時 2021-01-17 19:29:00
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 71 ms / 2,000 ms
コード長 2,255 bytes
コンパイル時間 3,686 ms
コンパイル使用メモリ 133,752 KB
実行使用メモリ 5,600 KB
最終ジャッジ日時 2023-08-20 01:47:50
合計ジャッジ時間 14,615 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,500 KB
testcase_07 AC 2 ms
4,384 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 1 ms
4,380 KB
testcase_23 AC 1 ms
4,376 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 1 ms
4,380 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 1 ms
4,384 KB
testcase_29 AC 2 ms
4,380 KB
testcase_30 AC 1 ms
4,376 KB
testcase_31 AC 2 ms
4,380 KB
testcase_32 AC 1 ms
4,380 KB
testcase_33 AC 1 ms
4,380 KB
testcase_34 AC 6 ms
4,384 KB
testcase_35 AC 49 ms
5,432 KB
testcase_36 AC 45 ms
5,228 KB
testcase_37 AC 1 ms
4,376 KB
testcase_38 AC 48 ms
5,408 KB
testcase_39 AC 16 ms
4,376 KB
testcase_40 AC 24 ms
4,380 KB
testcase_41 AC 49 ms
5,472 KB
testcase_42 AC 49 ms
5,576 KB
testcase_43 AC 27 ms
4,624 KB
testcase_44 AC 9 ms
4,380 KB
testcase_45 AC 48 ms
5,364 KB
testcase_46 AC 19 ms
4,380 KB
testcase_47 AC 49 ms
5,404 KB
testcase_48 AC 36 ms
4,616 KB
testcase_49 AC 49 ms
5,408 KB
testcase_50 AC 1 ms
4,380 KB
testcase_51 AC 25 ms
4,436 KB
testcase_52 AC 43 ms
5,080 KB
testcase_53 AC 31 ms
4,636 KB
testcase_54 AC 49 ms
5,476 KB
testcase_55 AC 39 ms
5,432 KB
testcase_56 AC 40 ms
5,340 KB
testcase_57 AC 35 ms
4,604 KB
testcase_58 AC 11 ms
4,380 KB
testcase_59 AC 2 ms
4,376 KB
testcase_60 AC 33 ms
4,624 KB
testcase_61 AC 1 ms
4,380 KB
testcase_62 AC 20 ms
4,380 KB
testcase_63 AC 49 ms
5,364 KB
testcase_64 AC 40 ms
5,356 KB
testcase_65 AC 2 ms
4,380 KB
testcase_66 AC 14 ms
4,380 KB
testcase_67 AC 16 ms
4,380 KB
testcase_68 AC 17 ms
4,376 KB
testcase_69 AC 2 ms
4,380 KB
testcase_70 AC 19 ms
4,380 KB
testcase_71 AC 49 ms
5,368 KB
testcase_72 AC 48 ms
5,360 KB
testcase_73 AC 48 ms
5,364 KB
testcase_74 AC 49 ms
5,600 KB
testcase_75 AC 49 ms
5,428 KB
testcase_76 AC 49 ms
5,484 KB
testcase_77 AC 48 ms
5,416 KB
testcase_78 AC 1 ms
4,380 KB
testcase_79 AC 2 ms
4,380 KB
testcase_80 AC 48 ms
5,416 KB
testcase_81 AC 49 ms
5,344 KB
testcase_82 AC 49 ms
5,364 KB
testcase_83 AC 39 ms
5,424 KB
testcase_84 AC 22 ms
4,380 KB
testcase_85 AC 56 ms
4,964 KB
testcase_86 AC 35 ms
4,380 KB
testcase_87 AC 32 ms
4,380 KB
testcase_88 AC 4 ms
4,376 KB
testcase_89 AC 3 ms
4,376 KB
testcase_90 AC 71 ms
5,140 KB
testcase_91 AC 9 ms
4,380 KB
testcase_92 AC 5 ms
4,376 KB
testcase_93 AC 52 ms
4,868 KB
testcase_94 AC 32 ms
4,376 KB
testcase_95 AC 23 ms
4,380 KB
testcase_96 AC 18 ms
4,384 KB
testcase_97 AC 4 ms
4,376 KB
testcase_98 AC 65 ms
5,420 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <queue>
#include <bitset>
#include <iomanip>
#include <limits>
#include <chrono>
#include <random>
#include <array>
#include <unordered_map>
#include <functional>
#include <complex>
#include <numeric>
#include <cctype>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <tuple>
#include <assert.h>
#include <deque>
#include <utility>
#include <fstream>

using namespace std;
typedef long long ll;
using ull = unsigned long long;

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; }
//template<typename T> T gcd(T a, T b) { a = abs(a), b = abs(b); while (b > 0) { tie(a, b) = make_pair(b, a % b); }return a; }
//mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

constexpr long long INF = 1LL << 60;
constexpr int inf = 1000000007;
//constexpr long long mod = 1000000007LL;
constexpr long long  mod = 998244353;

int main()
{

	std::cin.tie(nullptr);
	std::ios::sync_with_stdio(false);

	int n;
	ll X, Y; cin >> n >> X >> Y;
	vector<ll> a(n + 1); for (int i = 1; i <= n; i++) cin >> a[i]; a[0] = X;
	vector<int> b(61); for (int i = 0; i < 61; i++) b[i] = Y >> i & 1;
	vector<int> res(n, 3);
	n += 1;
	for (int i = n - 1; i >= 0; i--) {
		int f1 = 0, f2 = 0;
		for (int bit = 0; bit < 61; bit++) {
			if (b[bit] == -1) continue;
			int yb = b[bit];
			int ab = a[i] >> bit & 1;
			if (yb and !ab) f1 = true;
			if (!yb and ab) f2 = true;
		}
		if (f1 and f2) {
			cout << -1 << "\n";
			return 0;
		}
		if (f1) {
			if(i) res[i - 1] = 2;
			for (int bit = 0; bit < 61; bit++) {
				if (b[bit] == -1) continue;
				int yb = b[bit];
				int ab = a[i] >> bit & 1;
				if (yb and ab) b[bit] = -1;
			}
		}
		else if (f2) {
			if(i) res[i - 1] = 1;
			for (int bit = 0; bit < 61; bit++) {
				if (b[bit] == -1) continue;
				int yb = b[bit];
				int ab = a[i] >> bit & 1;
				if (!yb and !ab) b[bit] = -1;
			}
		}
		else {
			for (int i = 0; i < res.size(); i++) {
				cout << res[i] << " \n"[i + 1 == res.size()];
			}
			return 0;
		}
	}
	cout << -1 << "\n";
}
0