結果

問題 No.1296 OR or NOR
ユーザー leaf_1415leaf_1415
提出日時 2020-11-20 22:47:59
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 979 ms / 3,000 ms
コード長 1,477 bytes
コンパイル時間 1,530 ms
コンパイル使用メモリ 83,524 KB
実行使用メモリ 5,212 KB
最終ジャッジ日時 2023-09-30 19:45:29
合計ジャッジ時間 17,347 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 117 ms
4,972 KB
testcase_03 AC 134 ms
5,004 KB
testcase_04 AC 451 ms
5,004 KB
testcase_05 AC 440 ms
5,152 KB
testcase_06 AC 196 ms
4,956 KB
testcase_07 AC 179 ms
5,024 KB
testcase_08 AC 179 ms
5,212 KB
testcase_09 AC 166 ms
4,944 KB
testcase_10 AC 180 ms
4,944 KB
testcase_11 AC 154 ms
4,948 KB
testcase_12 AC 146 ms
5,008 KB
testcase_13 AC 146 ms
4,992 KB
testcase_14 AC 962 ms
4,952 KB
testcase_15 AC 964 ms
4,960 KB
testcase_16 AC 918 ms
5,152 KB
testcase_17 AC 150 ms
5,092 KB
testcase_18 AC 165 ms
4,964 KB
testcase_19 AC 211 ms
4,996 KB
testcase_20 AC 146 ms
4,356 KB
testcase_21 AC 129 ms
4,380 KB
testcase_22 AC 80 ms
4,360 KB
testcase_23 AC 84 ms
4,360 KB
testcase_24 AC 107 ms
4,360 KB
testcase_25 AC 106 ms
4,360 KB
testcase_26 AC 156 ms
4,360 KB
testcase_27 AC 157 ms
4,364 KB
testcase_28 AC 147 ms
4,364 KB
testcase_29 AC 143 ms
4,356 KB
testcase_30 AC 976 ms
5,088 KB
testcase_31 AC 979 ms
5,096 KB
testcase_32 AC 976 ms
5,028 KB
testcase_33 AC 915 ms
5,092 KB
testcase_34 AC 915 ms
4,948 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cassert>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <algorithm>
#include <utility>
#include <complex>
#define rep(x, s, t) for(llint (x) = (s); (x) <= (t); (x)++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))
#define all(x) (x).begin(),(x).end()
#define inf 1e18
#define mod 998244353

using namespace std;

typedef long long llint;
typedef long long ll;
typedef pair<llint, llint> P;

ll n, Q;
ll a[200005];
vector<ll> vec;

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n;
	rep(i, 1, n) cin >> a[i];
	
	ll mask = 0; bool none = false;
	for(int i = n; i >= 1; i--){
		ll x = ~mask & a[i];
		if(x > 0) vec.push_back(x);
		mask |= x;
		if(i == 1 && x > 0) none = true;
	}
	mask = ~mask;
	
	cin >> Q;
	ll b;
	rep(i, 1, Q){
		cin >> b;
		ll ans = 0;
		for(auto x : vec){
			bool flag[2] = {};
			rep(j, 0, 59){
				if(x & (1LL<<j)) flag[((b>>j)+ans)&1] = true;
			}
			if(flag[0] && flag[1]) ans = inf;
			if(flag[0]) ans++;
		}
		
		bool flag[2] = {};
		rep(j, 0, 59){
			if(mask & (1LL<<j)) flag[((b>>j)+ans)&1] = true;
		}
 		if(flag[0] && flag[1]) ans = inf;
		if(flag[1]){
			if(none) ans = inf;
			ans++;
		}
		
		if(ans > inf/2) ans = -1;
		cout << ans << "\n";
		end:;
	}
	flush(cout);
	
	return 0;
}
0