結果

問題 No.1296 OR or NOR
ユーザー 沙耶花沙耶花
提出日時 2020-06-26 15:25:19
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 931 ms / 3,000 ms
コード長 1,190 bytes
コンパイル時間 4,257 ms
コンパイル使用メモリ 203,756 KB
実行使用メモリ 4,844 KB
最終ジャッジ日時 2023-09-02 14:19:07
合計ジャッジ時間 16,323 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 82 ms
4,680 KB
testcase_03 AC 84 ms
4,556 KB
testcase_04 AC 345 ms
4,608 KB
testcase_05 AC 336 ms
4,540 KB
testcase_06 AC 142 ms
4,540 KB
testcase_07 AC 125 ms
4,668 KB
testcase_08 AC 116 ms
4,620 KB
testcase_09 AC 141 ms
4,560 KB
testcase_10 AC 150 ms
4,564 KB
testcase_11 AC 123 ms
4,540 KB
testcase_12 AC 128 ms
4,744 KB
testcase_13 AC 108 ms
4,560 KB
testcase_14 AC 931 ms
4,620 KB
testcase_15 AC 737 ms
4,612 KB
testcase_16 AC 728 ms
4,544 KB
testcase_17 AC 108 ms
4,844 KB
testcase_18 AC 118 ms
4,720 KB
testcase_19 AC 150 ms
4,536 KB
testcase_20 AC 80 ms
4,376 KB
testcase_21 AC 69 ms
4,380 KB
testcase_22 AC 46 ms
4,376 KB
testcase_23 AC 47 ms
4,376 KB
testcase_24 AC 53 ms
4,380 KB
testcase_25 AC 53 ms
4,376 KB
testcase_26 AC 98 ms
4,376 KB
testcase_27 AC 96 ms
4,384 KB
testcase_28 AC 94 ms
4,376 KB
testcase_29 AC 73 ms
4,376 KB
testcase_30 AC 912 ms
4,688 KB
testcase_31 AC 912 ms
4,564 KB
testcase_32 AC 913 ms
4,572 KB
testcase_33 AC 745 ms
4,688 KB
testcase_34 AC 749 ms
4,580 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 1000000000

int check(vector<long long> &base,long long t,char last){
	long long now = 0LL;
	string S = "1";
	for(int i=0;i<base.size();i++){
		for(int j=0;j<60;j++){
			if((base[i]>>j)&1){
				if((t>>j)&1){
					now ^= base[i];
					S += '1';
				}
				else{
					S += '0';
				}
				break;
			}
		}
	}
	
	if(now!=t)return 100;
	
	int ret = 0;
	S += last;
	for(int i=1;i<S.size();i++){
		if(S[i]!=S[i-1])ret++;
	}
	
	return ret;
}

int main(){
	
	long long X = (1LL<<60)-1;
	
	int N;
	cin>>N;
	
	vector<long long> a(N);
	for(int i=0;i<N;i++)scanf("%lld",&a[i]);
	
	long long now = X;
	vector<long long> base;
	
	for(int i=N-1;i>=1;i--){
		long long t = now&a[i];
		for(int j=59;j>=0;j--){
			if((t>>j)&1){
				base.push_back(t);
				break;
			}
		}
		
		now &= a[i]^X;
	}
	
	reverse(base.begin(),base.end());
	
	long long t = now&a[0];
	
	int Q;
	cin>>Q;
	
	for(int i=0;i<Q;i++){
		long long b;
		scanf("%lld",&b);
		int ans = min(check(base,b^t,'1'),check(base,b^X^t,'0'));
		if(ans==100)printf("-1\n");
		else printf("%d\n",ans);
	}
	
	return 0;
}
0