結果

問題 No.1296 OR or NOR
ユーザー 沙耶花沙耶花
提出日時 2020-06-24 17:37:03
言語 C++17
(gcc 11.2.0 + boost 1.78.0)
結果
AC  
実行時間 361 ms / 3,000 ms
コード長 1,152 bytes
コンパイル時間 2,962 ms
使用メモリ 4,736 KB
最終ジャッジ日時 2023-01-18 20:41:55
合計ジャッジ時間 16,403 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
testcase_00 AC 1 ms
3,528 KB
testcase_01 AC 1 ms
3,528 KB
testcase_02 AC 80 ms
4,600 KB
testcase_03 AC 80 ms
4,652 KB
testcase_04 AC 195 ms
4,648 KB
testcase_05 AC 179 ms
4,648 KB
testcase_06 AC 112 ms
4,652 KB
testcase_07 AC 108 ms
4,652 KB
testcase_08 AC 108 ms
4,620 KB
testcase_09 AC 108 ms
4,632 KB
testcase_10 AC 113 ms
4,648 KB
testcase_11 AC 96 ms
4,644 KB
testcase_12 AC 94 ms
4,720 KB
testcase_13 AC 99 ms
4,644 KB
testcase_14 AC 361 ms
4,608 KB
testcase_15 AC 226 ms
4,720 KB
testcase_16 AC 188 ms
4,668 KB
testcase_17 AC 102 ms
4,632 KB
testcase_18 AC 104 ms
4,692 KB
testcase_19 AC 116 ms
4,676 KB
testcase_20 AC 62 ms
3,556 KB
testcase_21 AC 58 ms
3,604 KB
testcase_22 AC 45 ms
3,416 KB
testcase_23 AC 47 ms
3,568 KB
testcase_24 AC 50 ms
3,488 KB
testcase_25 AC 50 ms
3,532 KB
testcase_26 AC 65 ms
3,564 KB
testcase_27 AC 65 ms
3,536 KB
testcase_28 AC 60 ms
3,540 KB
testcase_29 AC 60 ms
3,532 KB
testcase_30 AC 349 ms
4,668 KB
testcase_31 AC 348 ms
4,612 KB
testcase_32 AC 351 ms
4,668 KB
testcase_33 AC 206 ms
4,736 KB
testcase_34 AC 202 ms
4,620 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<pair<long long,int>> &base,long long t,char last){
	long long now = 0LL;
	string S = "1";
	for(int i=0;i<base.size();i++){
		if((t>>base[i].second)&1){
			now ^= base[i].first;
			S += '1';
		}
		else{
			S += '0';
		}
	}
	
	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<pair<long long,int>> 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.emplace_back(t,j);
				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