結果

問題 No.1296 OR or NOR
ユーザー miplect
提出日時 2020-11-21 19:25:21
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 159 ms / 3,000 ms
コード長 891 bytes
コンパイル時間 786 ms
コンパイル使用メモリ 71,748 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-07-23 16:01:27
合計ジャッジ時間 8,734 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 33
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
using namespace std;

typedef long long LL;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	const LL mask = (1LL << 60) - 1;
	int n;
	cin >> n;
	vector<LL> as(n);
	for(LL &a : as){ cin >> a; }
	LL rem = mask;
	vector<LL> v;
	bool free = false;
	for(int i = n - 1; i >= 0; --i){
		LL b = rem & as[i];
		if(b != 0){
			v.push_back(b);
			rem ^= b;
			free = false;
		}
		else{
			free = true;
		}
	}

	int q;
	cin >> q;
	for(int z = 0; z < q; ++z){
		LL b;
		cin >> b;
		int ans = 0;
		for(LL x : v){
			LL y = b & x;
			if(y != 0 && y != x){
				ans = -1;
				break;
			}
			if((y == x) != (ans % 2 == 0)){
				++ans;
			}
		}
		if(ans != -1 && rem != 0){
			LL y = b & rem;
			if(y != 0 && y != rem){
				ans = -1;
			}
			else if((y == 0) != (ans % 2 == 0)){
				if(free){ ++ans; }
				else{ ans = -1; }
			}
		}
		cout << ans << '\n';
	}
}
0