結果

問題 No.1296 OR or NOR
ユーザー miplectmiplect
提出日時 2020-11-21 19:25:21
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 162 ms / 3,000 ms
コード長 891 bytes
コンパイル時間 860 ms
コンパイル使用メモリ 72,284 KB
実行使用メモリ 4,888 KB
最終ジャッジ日時 2023-09-30 22:13:45
合計ジャッジ時間 8,129 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 67 ms
4,672 KB
testcase_03 AC 67 ms
4,852 KB
testcase_04 AC 103 ms
4,628 KB
testcase_05 AC 104 ms
4,888 KB
testcase_06 AC 92 ms
4,584 KB
testcase_07 AC 91 ms
4,696 KB
testcase_08 AC 90 ms
4,888 KB
testcase_09 AC 82 ms
4,848 KB
testcase_10 AC 83 ms
4,692 KB
testcase_11 AC 70 ms
4,584 KB
testcase_12 AC 69 ms
4,612 KB
testcase_13 AC 74 ms
4,572 KB
testcase_14 AC 162 ms
4,576 KB
testcase_15 AC 115 ms
4,636 KB
testcase_16 AC 86 ms
4,576 KB
testcase_17 AC 90 ms
4,608 KB
testcase_18 AC 87 ms
4,692 KB
testcase_19 AC 87 ms
4,584 KB
testcase_20 AC 52 ms
4,380 KB
testcase_21 AC 52 ms
4,380 KB
testcase_22 AC 49 ms
4,380 KB
testcase_23 AC 51 ms
4,380 KB
testcase_24 AC 52 ms
4,380 KB
testcase_25 AC 52 ms
4,380 KB
testcase_26 AC 53 ms
4,380 KB
testcase_27 AC 53 ms
4,504 KB
testcase_28 AC 52 ms
4,380 KB
testcase_29 AC 52 ms
4,380 KB
testcase_30 AC 149 ms
4,568 KB
testcase_31 AC 152 ms
4,848 KB
testcase_32 AC 151 ms
4,856 KB
testcase_33 AC 90 ms
4,696 KB
testcase_34 AC 90 ms
4,624 KB
権限があれば一括ダウンロードができます

ソースコード

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