結果

問題 No.1355 AND OR GAME
ユーザー 👑 kmjpkmjp
提出日時 2021-01-17 15:39:17
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 89 ms / 2,000 ms
コード長 1,824 bytes
コンパイル時間 2,522 ms
コンパイル使用メモリ 214,532 KB
実行使用メモリ 46,388 KB
最終ジャッジ日時 2024-05-07 04:59:48
合計ジャッジ時間 11,758 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
12,928 KB
testcase_01 AC 5 ms
13,760 KB
testcase_02 AC 5 ms
13,760 KB
testcase_03 AC 5 ms
13,804 KB
testcase_04 AC 5 ms
12,852 KB
testcase_05 AC 5 ms
13,668 KB
testcase_06 AC 5 ms
12,960 KB
testcase_07 AC 6 ms
13,636 KB
testcase_08 AC 6 ms
13,008 KB
testcase_09 AC 5 ms
13,636 KB
testcase_10 AC 5 ms
12,792 KB
testcase_11 AC 5 ms
13,008 KB
testcase_12 AC 5 ms
14,228 KB
testcase_13 AC 5 ms
13,640 KB
testcase_14 AC 5 ms
13,640 KB
testcase_15 AC 6 ms
12,796 KB
testcase_16 AC 5 ms
13,816 KB
testcase_17 AC 5 ms
13,136 KB
testcase_18 AC 5 ms
13,892 KB
testcase_19 AC 6 ms
12,948 KB
testcase_20 AC 5 ms
13,636 KB
testcase_21 AC 5 ms
13,944 KB
testcase_22 AC 5 ms
13,764 KB
testcase_23 AC 5 ms
13,852 KB
testcase_24 AC 6 ms
13,652 KB
testcase_25 AC 6 ms
13,852 KB
testcase_26 AC 5 ms
13,640 KB
testcase_27 AC 5 ms
13,768 KB
testcase_28 AC 5 ms
13,636 KB
testcase_29 AC 5 ms
13,056 KB
testcase_30 AC 6 ms
13,640 KB
testcase_31 AC 5 ms
12,884 KB
testcase_32 AC 5 ms
13,764 KB
testcase_33 AC 5 ms
12,776 KB
testcase_34 AC 11 ms
13,248 KB
testcase_35 AC 54 ms
15,228 KB
testcase_36 AC 49 ms
15,116 KB
testcase_37 AC 5 ms
13,024 KB
testcase_38 AC 54 ms
15,144 KB
testcase_39 AC 20 ms
13,892 KB
testcase_40 AC 29 ms
14,104 KB
testcase_41 AC 53 ms
15,172 KB
testcase_42 AC 54 ms
15,220 KB
testcase_43 AC 30 ms
14,404 KB
testcase_44 AC 12 ms
13,892 KB
testcase_45 AC 53 ms
15,340 KB
testcase_46 AC 23 ms
13,832 KB
testcase_47 AC 54 ms
15,136 KB
testcase_48 AC 40 ms
14,688 KB
testcase_49 AC 53 ms
15,304 KB
testcase_50 AC 6 ms
12,844 KB
testcase_51 AC 29 ms
14,276 KB
testcase_52 AC 48 ms
15,168 KB
testcase_53 AC 35 ms
14,484 KB
testcase_54 AC 53 ms
15,172 KB
testcase_55 AC 41 ms
15,264 KB
testcase_56 AC 41 ms
15,176 KB
testcase_57 AC 38 ms
14,532 KB
testcase_58 AC 15 ms
13,500 KB
testcase_59 AC 5 ms
13,512 KB
testcase_60 AC 37 ms
14,680 KB
testcase_61 AC 4 ms
13,764 KB
testcase_62 AC 24 ms
14,008 KB
testcase_63 AC 55 ms
15,256 KB
testcase_64 AC 41 ms
15,352 KB
testcase_65 AC 5 ms
13,012 KB
testcase_66 AC 17 ms
14,148 KB
testcase_67 AC 21 ms
13,636 KB
testcase_68 AC 20 ms
13,940 KB
testcase_69 AC 5 ms
13,632 KB
testcase_70 AC 24 ms
13,880 KB
testcase_71 AC 53 ms
15,224 KB
testcase_72 AC 54 ms
15,172 KB
testcase_73 AC 54 ms
15,296 KB
testcase_74 AC 54 ms
15,312 KB
testcase_75 AC 54 ms
15,272 KB
testcase_76 AC 54 ms
15,168 KB
testcase_77 AC 54 ms
15,300 KB
testcase_78 AC 5 ms
13,828 KB
testcase_79 AC 5 ms
12,776 KB
testcase_80 AC 53 ms
15,172 KB
testcase_81 AC 54 ms
15,168 KB
testcase_82 AC 54 ms
15,172 KB
testcase_83 AC 41 ms
15,120 KB
testcase_84 AC 27 ms
23,800 KB
testcase_85 AC 71 ms
38,044 KB
testcase_86 AC 47 ms
29,104 KB
testcase_87 AC 41 ms
26,976 KB
testcase_88 AC 8 ms
14,204 KB
testcase_89 AC 8 ms
14,644 KB
testcase_90 AC 89 ms
44,648 KB
testcase_91 AC 13 ms
17,220 KB
testcase_92 AC 9 ms
15,172 KB
testcase_93 AC 61 ms
40,048 KB
testcase_94 AC 39 ms
29,368 KB
testcase_95 AC 29 ms
24,644 KB
testcase_96 AC 24 ms
22,208 KB
testcase_97 AC 8 ms
15,044 KB
testcase_98 AC 75 ms
46,388 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define FORR2(x,y,arr) for(auto& [x,y]:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
template<class T> bool chmax(T &a, const T &b) { if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a, const T &b) { if(a>b){a=b;return 1;}return 0;}
//-------------------------------------------------------

int N;
ll X,Y;
ll A[202020];
map<pair<ll,ll>,pair<pair<ll,ll>,int>> M[202020];
int ret[202020];

void solve() {
	int i,j,k,l,r,x,y; string s;
	cin>>N>>X>>Y;
	FOR(i,N) cin>>A[i];
	M[N][{0,(1LL<<60)-1}]={{0,0},1};
	FOR(i,N) ret[i]=3;
	for(i=N-1;i>=0;i--) {
		FORR(m,M[i+1]) {
			ll o=m.first.first;
			ll a=m.first.second;
			if((Y&a)!=Y) continue;
			if((Y|o)!=Y) continue;
			if(((A[i]|o)&a)==Y) {
				i=i+1;
				while(i<N) {
					assert(M[i].count({o,a}));
					auto m2=M[i][{o,a}];
					o=m2.first.first;
					a=m2.first.second;
					ret[i]=m2.second;
					i++;
				}
				FOR(i,N) cout<<ret[i]<<" ";
				return;
			}
			//and
			ll am=(A[i]|o)&a;
			M[i][{o,am}]={{o,a},1};
			//or
			ll om=(A[i]&a)|o;
			M[i][{om,a}]={{o,a},2};
		}
	}
	FORR(m,M[0]) {
		ll o=m.first.first;
		ll a=m.first.second;
		if(((X|o)&a)==Y) {
			i=0;
			while(i<N) {
				auto m2=M[i][{o,a}];
				o=m2.first.first;
				a=m2.first.second;
				ret[i]=m2.second;
				i++;
			}
			FOR(i,N) cout<<ret[i]<<" ";
			return;
		}
	}
	cout<<-1<<endl;
	
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}
0