結果

問題 No.1355 AND OR GAME
ユーザー 👑 kmjpkmjp
提出日時 2021-01-17 15:39:17
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 86 ms / 2,000 ms
コード長 1,824 bytes
コンパイル時間 2,210 ms
コンパイル使用メモリ 210,560 KB
実行使用メモリ 46,452 KB
最終ジャッジ日時 2023-08-19 21:54:42
合計ジャッジ時間 12,236 ms
ジャッジサーバーID
(参考情報)
judge13 / judge10
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
12,800 KB
testcase_01 AC 4 ms
12,948 KB
testcase_02 AC 4 ms
13,084 KB
testcase_03 AC 4 ms
12,892 KB
testcase_04 AC 4 ms
12,884 KB
testcase_05 AC 3 ms
12,888 KB
testcase_06 AC 4 ms
12,944 KB
testcase_07 AC 4 ms
12,844 KB
testcase_08 AC 4 ms
12,980 KB
testcase_09 AC 3 ms
12,884 KB
testcase_10 AC 4 ms
12,868 KB
testcase_11 AC 4 ms
12,860 KB
testcase_12 AC 4 ms
12,924 KB
testcase_13 AC 4 ms
12,924 KB
testcase_14 AC 4 ms
12,856 KB
testcase_15 AC 3 ms
12,812 KB
testcase_16 AC 4 ms
12,784 KB
testcase_17 AC 4 ms
12,812 KB
testcase_18 AC 3 ms
13,060 KB
testcase_19 AC 4 ms
12,952 KB
testcase_20 AC 4 ms
12,952 KB
testcase_21 AC 4 ms
12,924 KB
testcase_22 AC 3 ms
12,856 KB
testcase_23 AC 4 ms
12,780 KB
testcase_24 AC 4 ms
12,816 KB
testcase_25 AC 3 ms
12,792 KB
testcase_26 AC 4 ms
12,960 KB
testcase_27 AC 4 ms
12,796 KB
testcase_28 AC 4 ms
12,784 KB
testcase_29 AC 4 ms
12,916 KB
testcase_30 AC 3 ms
12,848 KB
testcase_31 AC 4 ms
12,948 KB
testcase_32 AC 4 ms
13,052 KB
testcase_33 AC 4 ms
12,916 KB
testcase_34 AC 8 ms
13,040 KB
testcase_35 AC 54 ms
15,216 KB
testcase_36 AC 50 ms
15,220 KB
testcase_37 AC 4 ms
13,020 KB
testcase_38 AC 54 ms
15,276 KB
testcase_39 AC 19 ms
13,816 KB
testcase_40 AC 29 ms
14,116 KB
testcase_41 AC 54 ms
15,280 KB
testcase_42 AC 55 ms
15,304 KB
testcase_43 AC 30 ms
14,396 KB
testcase_44 AC 11 ms
13,228 KB
testcase_45 AC 55 ms
15,136 KB
testcase_46 AC 23 ms
13,676 KB
testcase_47 AC 54 ms
15,160 KB
testcase_48 AC 41 ms
14,496 KB
testcase_49 AC 54 ms
15,280 KB
testcase_50 AC 5 ms
12,864 KB
testcase_51 AC 29 ms
14,060 KB
testcase_52 AC 49 ms
14,904 KB
testcase_53 AC 36 ms
14,436 KB
testcase_54 AC 55 ms
15,268 KB
testcase_55 AC 43 ms
15,148 KB
testcase_56 AC 42 ms
15,260 KB
testcase_57 AC 39 ms
14,592 KB
testcase_58 AC 14 ms
13,336 KB
testcase_59 AC 4 ms
12,804 KB
testcase_60 AC 38 ms
14,376 KB
testcase_61 AC 4 ms
12,796 KB
testcase_62 AC 22 ms
14,004 KB
testcase_63 AC 54 ms
15,152 KB
testcase_64 AC 43 ms
15,152 KB
testcase_65 AC 5 ms
12,808 KB
testcase_66 AC 17 ms
13,656 KB
testcase_67 AC 20 ms
13,672 KB
testcase_68 AC 20 ms
13,608 KB
testcase_69 AC 4 ms
12,800 KB
testcase_70 AC 23 ms
13,688 KB
testcase_71 AC 54 ms
15,304 KB
testcase_72 AC 55 ms
15,328 KB
testcase_73 AC 55 ms
15,148 KB
testcase_74 AC 55 ms
15,216 KB
testcase_75 AC 55 ms
15,200 KB
testcase_76 AC 54 ms
15,252 KB
testcase_77 AC 55 ms
15,164 KB
testcase_78 AC 5 ms
12,912 KB
testcase_79 AC 4 ms
12,928 KB
testcase_80 AC 54 ms
15,136 KB
testcase_81 AC 55 ms
15,416 KB
testcase_82 AC 55 ms
15,168 KB
testcase_83 AC 43 ms
15,216 KB
testcase_84 AC 26 ms
23,228 KB
testcase_85 AC 70 ms
38,152 KB
testcase_86 AC 45 ms
28,612 KB
testcase_87 AC 40 ms
26,676 KB
testcase_88 AC 7 ms
13,976 KB
testcase_89 AC 6 ms
13,532 KB
testcase_90 AC 86 ms
44,668 KB
testcase_91 AC 12 ms
16,684 KB
testcase_92 AC 8 ms
14,348 KB
testcase_93 AC 60 ms
40,216 KB
testcase_94 AC 38 ms
28,884 KB
testcase_95 AC 27 ms
24,328 KB
testcase_96 AC 23 ms
21,536 KB
testcase_97 AC 7 ms
14,256 KB
testcase_98 AC 74 ms
46,452 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