結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,384 KB
testcase_01 AC 2 ms
4,384 KB
testcase_02 AC 80 ms
4,752 KB
testcase_03 AC 80 ms
4,660 KB
testcase_04 AC 200 ms
4,664 KB
testcase_05 AC 185 ms
4,832 KB
testcase_06 AC 113 ms
4,720 KB
testcase_07 AC 107 ms
4,664 KB
testcase_08 AC 106 ms
4,664 KB
testcase_09 AC 108 ms
4,660 KB
testcase_10 AC 118 ms
4,632 KB
testcase_11 AC 98 ms
4,560 KB
testcase_12 AC 94 ms
4,656 KB
testcase_13 AC 99 ms
4,668 KB
testcase_14 AC 367 ms
4,672 KB
testcase_15 AC 228 ms
4,744 KB
testcase_16 AC 188 ms
4,556 KB
testcase_17 AC 96 ms
4,588 KB
testcase_18 AC 100 ms
4,792 KB
testcase_19 AC 107 ms
4,556 KB
testcase_20 AC 62 ms
4,380 KB
testcase_21 AC 59 ms
4,384 KB
testcase_22 AC 45 ms
4,384 KB
testcase_23 AC 46 ms
4,380 KB
testcase_24 AC 51 ms
4,380 KB
testcase_25 AC 51 ms
4,384 KB
testcase_26 AC 66 ms
4,384 KB
testcase_27 AC 67 ms
4,380 KB
testcase_28 AC 61 ms
4,384 KB
testcase_29 AC 61 ms
4,384 KB
testcase_30 AC 353 ms
4,724 KB
testcase_31 AC 355 ms
4,552 KB
testcase_32 AC 355 ms
4,512 KB
testcase_33 AC 206 ms
4,620 KB
testcase_34 AC 208 ms
4,676 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++){
		if((t|base[i])==t){
			now ^= base[i];
			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<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