結果
問題 | No.1355 AND OR GAME |
ユーザー |
![]() |
提出日時 | 2021-05-11 22:21:49 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,399 bytes |
コンパイル時間 | 1,285 ms |
コンパイル使用メモリ | 118,388 KB |
最終ジャッジ日時 | 2025-01-21 10:08:00 |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 34 WA * 4 RE * 57 |
ソースコード
#include <iostream> #include <algorithm> #include <iomanip> #include <vector> #include <queue> #include <set> #include <map> #include <tuple> #include <cmath> #include <numeric> #include <functional> #include <cassert> #define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl; #define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl; 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; } using namespace std; typedef long long ll; int n; ll x, y; vector<ll> a; vector<int> as_vec(ll x){ vector<int> v(60); for(int i = 0; i < 60; i++){ if(((ll)1<<i) & x) v[i] = 1; else v[i] = 0; } return v; } bool dfs(int i, vector<int> &p, vector<int> v){ // debug_value(i); if(i < 0) return false; auto u = as_vec(a[i]); bool ok_or = [&](){ for(int i = 0; i < 60; i++) { if(u[i] != 1) continue; if(v[i] == 0) return false; } return true; }(); bool ok_and = [&](){ for(int i = 0; i < 60; i++) { if(u[i] != 0) continue; if(v[i] == 1) return false; } return true; }(); if(ok_or && ok_and){ p[i] = 3; return true; } if(ok_or){ for(int i = 0; i < 60; i++){ if(v[i] == 1) v[i] = 2; } p[i] = 2; return dfs(i-1, p, v); } if(ok_and){ for(int i = 0; i < 60; i++){ if(v[i] == 0) v[i] = 2; } p[i] = 1; return dfs(i-1, p, v); } return false; } ll test(ll x, vector<int> p){ for(int i = 0; i < n; i++){ int t = p[i]; if(t == 1) x &= a[i]; if(t == 2) x |= a[i]; if(t == 3) x = a[i]; } return x; } void get_vec(vector<ll> &a){ int n = a.size(); for(int i = 0; i < n; i++) cin >> a[i]; } int main(){ ios::sync_with_stdio(false); cin.tie(0); cout << setprecision(10) << fixed; cin >> n >> x >> y; a.resize(n); get_vec(a); vector<int> p(n, 1); vector<int> v = as_vec(y); if(dfs(n-1, p, v)) { assert(test(x, p) == y); for(int x : p) cout << x << ' '; cout << endl; }else{ cout << -1 << endl; } }