結果
問題 | No.1355 AND OR GAME |
ユーザー |
👑 ![]() |
提出日時 | 2021-01-17 15:51:05 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
TLE
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 3,646 bytes |
コンパイル時間 | 2,378 ms |
コンパイル使用メモリ | 210,308 KB |
最終ジャッジ日時 | 2025-01-18 01:21:52 |
ジャッジサーバーID (参考情報) |
judge3 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 93 TLE * 2 |
ソースコード
#define _USE_MATH_DEFINES#include <bits/stdc++.h>using namespace std;#define FOR(i,m,n) for(int i=(m);i<(n);++i)#define REP(i,n) FOR(i,0,n)#define ALL(v) (v).begin(),(v).end()using ll = long long;constexpr int INF = 0x3f3f3f3f;constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;constexpr double EPS = 1e-8;constexpr int MOD = 1000000007;// constexpr int MOD = 998244353;constexpr int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};constexpr int dy8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dx8[] = {0, -1, -1, -1, 0, 1, 1, 1};template <typename T, typename U> inline bool chmax(T &a, U b) { return a < b ? (a = b, true) : false; }template <typename T, typename U> inline bool chmin(T &a, U b) { return a > b ? (a = b, true) : false; }struct IOSetup {IOSetup() {std::cin.tie(nullptr);std::ios_base::sync_with_stdio(false);std::cout << fixed << setprecision(20);}} iosetup;int n;void out(string &ans) {while (ans.size() < n) ans += '3';reverse(ALL(ans));REP(i, n) cout << ans[i] << " \n"[i + 1 == n];exit(0);}int main() {constexpr int B = 60;ll x, y; cin >> n >> x >> y;vector<ll> a(n); REP(i, n) cin >> a[i];vector<int> d(B);REP(i, B) d[i] = y >> i & 1;vector<pair<vector<int>, string>> que;{vector<int> bit(B);iota(ALL(bit), 0);que.emplace_back(bit, "");}for (int i = n - 1; i >= 0; --i) {assert(que.size() <= 2);if (que.empty()) {cout << "-1\n";return 0;}vector<pair<vector<int>, string>> nx;for (auto it = que.begin(); it != que.end(); ++it) {vector<int> &bit = it->first;string &ans = it->second;bool sw = true;for (int b : bit) {if (d[b] != (a[i] >> b & 1)) {sw = false;break;}}if (sw) out(ans);bool an = false, o = false;for (int b : bit) {if ((a[i] >> b & 1) && d[b] == 0) an = true;if (!(a[i] >> b & 1) && d[b] == 1) o = true;}if (an && o) continue;if (an) {ans += '1';vector<int> nx_bit;for (int b : bit) {if (!(!(a[i] >> b & 1) && d[b] == 0)) nx_bit.emplace_back(b);}if (nx_bit.empty()) out(ans);nx.emplace_back(nx_bit, ans);} else if (o) {ans += '2';vector<int> nx_bit;for (int b : bit) {if (!((a[i] >> b & 1) && d[b] == 1)) nx_bit.emplace_back(b);}if (nx_bit.empty()) out(ans);nx.emplace_back(nx_bit, ans);} else {int cnt[2] = {};for (int b : bit) ++cnt[d[b]];if (cnt[0] == bit.size()) {ans += '1';out(ans);} else if (cnt[1] == bit.size()) {ans += '2';out(ans);} else {{vector<int> nx_bit;for (int b : bit) {if (!(!(a[i] >> b & 1) && d[b] == 0)) nx_bit.emplace_back(b);}assert(!nx_bit.empty());nx.emplace_back(nx_bit, ans + '1');}{vector<int> nx_bit;for (int b : bit) {if (!((a[i] >> b & 1) && d[b] == 1)) nx_bit.emplace_back(b);}assert(!nx_bit.empty());nx.emplace_back(nx_bit, ans + '2');}}}}que.swap(nx);}for (auto it = que.begin(); it != que.end(); ++it) {vector<int> &bit = it->first;string &ans = it->second;bool sw = true;for (int b : bit) {if (d[b] != (x >> b & 1)) {sw = false;break;}}if (sw) out(ans);}cout << "-1\n";return 0;}