結果

問題 No.1296 OR or NOR
ユーザー 沙耶花沙耶花
提出日時 2020-06-24 17:40:28
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,152 bytes
コンパイル時間 2,320 ms
コンパイル使用メモリ 204,168 KB
実行使用メモリ 4,888 KB
最終ジャッジ日時 2023-09-02 14:17:43
合計ジャッジ時間 11,021 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 212 ms
4,616 KB
testcase_05 WA -
testcase_06 AC 110 ms
4,632 KB
testcase_07 AC 105 ms
4,572 KB
testcase_08 AC 105 ms
4,568 KB
testcase_09 AC 109 ms
4,612 KB
testcase_10 AC 116 ms
4,748 KB
testcase_11 AC 96 ms
4,888 KB
testcase_12 AC 93 ms
4,620 KB
testcase_13 AC 99 ms
4,676 KB
testcase_14 AC 400 ms
4,752 KB
testcase_15 AC 251 ms
4,628 KB
testcase_16 AC 209 ms
4,632 KB
testcase_17 AC 101 ms
4,560 KB
testcase_18 AC 104 ms
4,684 KB
testcase_19 AC 116 ms
4,684 KB
testcase_20 AC 61 ms
4,380 KB
testcase_21 AC 59 ms
4,376 KB
testcase_22 AC 49 ms
4,380 KB
testcase_23 AC 49 ms
4,376 KB
testcase_24 AC 54 ms
4,380 KB
testcase_25 AC 52 ms
4,380 KB
testcase_26 AC 65 ms
4,376 KB
testcase_27 AC 64 ms
4,376 KB
testcase_28 AC 61 ms
4,380 KB
testcase_29 AC 60 ms
4,376 KB
testcase_30 AC 383 ms
4,556 KB
testcase_31 AC 392 ms
4,672 KB
testcase_32 AC 386 ms
4,628 KB
testcase_33 AC 236 ms
4,692 KB
testcase_34 AC 236 ms
4,688 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>=0;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