結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 1 ms
4,376 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 98 ms
4,576 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 95 ms
4,636 KB
testcase_18 AC 96 ms
4,620 KB
testcase_19 AC 104 ms
4,584 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 44 ms
4,376 KB
testcase_23 AC 45 ms
4,376 KB
testcase_24 AC 48 ms
4,380 KB
testcase_25 AC 48 ms
4,380 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 AC 54 ms
4,380 KB
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 AC 152 ms
4,632 KB
testcase_34 AC 154 ms
4,616 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 = check(base,b^t,'1');
		if(ans==100)printf("-1\n");
		else printf("%d\n",ans);
	}
	
	return 0;
}
0