結果
問題 | No.1355 AND OR GAME |
ユーザー |
|
提出日時 | 2021-01-17 19:29:00 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 79 ms / 2,000 ms |
コード長 | 2,255 bytes |
コンパイル時間 | 1,219 ms |
コンパイル使用メモリ | 130,244 KB |
最終ジャッジ日時 | 2025-01-18 01:55:24 |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 95 |
ソースコード
#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";}