結果

問題 No.1296 OR or NOR
ユーザー leaf_1415leaf_1415
提出日時 2020-11-20 22:47:59
言語 C++11
(gcc 8.5.0)
結果
AC  
実行時間 861 ms / 3,000 ms
コード長 1,477 bytes
コンパイル時間 1,426 ms
使用メモリ 6,320 KB
最終ジャッジ日時 2023-02-23 19:14:53
合計ジャッジ時間 14,954 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
testcase_00 AC 2 ms
6,272 KB
testcase_01 AC 1 ms
6,188 KB
testcase_02 AC 92 ms
6,204 KB
testcase_03 AC 95 ms
6,204 KB
testcase_04 AC 382 ms
6,248 KB
testcase_05 AC 373 ms
6,284 KB
testcase_06 AC 165 ms
6,256 KB
testcase_07 AC 148 ms
6,204 KB
testcase_08 AC 143 ms
6,268 KB
testcase_09 AC 133 ms
6,200 KB
testcase_10 AC 146 ms
6,312 KB
testcase_11 AC 126 ms
6,204 KB
testcase_12 AC 119 ms
6,316 KB
testcase_13 AC 124 ms
6,196 KB
testcase_14 AC 822 ms
6,192 KB
testcase_15 AC 827 ms
6,208 KB
testcase_16 AC 785 ms
6,164 KB
testcase_17 AC 119 ms
6,260 KB
testcase_18 AC 133 ms
6,176 KB
testcase_19 AC 174 ms
6,248 KB
testcase_20 AC 120 ms
6,164 KB
testcase_21 AC 106 ms
6,172 KB
testcase_22 AC 64 ms
6,212 KB
testcase_23 AC 68 ms
6,204 KB
testcase_24 AC 90 ms
6,184 KB
testcase_25 AC 94 ms
6,176 KB
testcase_26 AC 128 ms
6,172 KB
testcase_27 AC 127 ms
6,200 KB
testcase_28 AC 119 ms
6,160 KB
testcase_29 AC 117 ms
6,192 KB
testcase_30 AC 857 ms
6,256 KB
testcase_31 AC 861 ms
6,248 KB
testcase_32 AC 858 ms
6,244 KB
testcase_33 AC 819 ms
6,280 KB
testcase_34 AC 800 ms
6,320 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