結果
問題 | No.1296 OR or NOR |
ユーザー | chocorusk |
提出日時 | 2020-11-22 03:38:07 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 2,228 ms / 3,000 ms |
コード長 | 1,946 bytes |
コンパイル時間 | 1,138 ms |
コンパイル使用メモリ | 128,840 KB |
実行使用メモリ | 34,740 KB |
最終ジャッジ日時 | 2023-09-30 22:25:09 |
合計ジャッジ時間 | 14,193 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge12 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
4,376 KB |
testcase_01 | AC | 2 ms
5,616 KB |
testcase_02 | AC | 107 ms
30,948 KB |
testcase_03 | AC | 107 ms
31,092 KB |
testcase_04 | AC | 306 ms
34,464 KB |
testcase_05 | AC | 301 ms
33,944 KB |
testcase_06 | AC | 138 ms
33,600 KB |
testcase_07 | AC | 132 ms
33,164 KB |
testcase_08 | AC | 133 ms
33,176 KB |
testcase_09 | AC | 192 ms
34,424 KB |
testcase_10 | AC | 206 ms
34,236 KB |
testcase_11 | AC | 155 ms
33,820 KB |
testcase_12 | AC | 156 ms
33,900 KB |
testcase_13 | AC | 167 ms
33,636 KB |
testcase_14 | AC | 2,228 ms
33,220 KB |
testcase_15 | AC | 578 ms
33,216 KB |
testcase_16 | AC | 496 ms
33,620 KB |
testcase_17 | AC | 117 ms
33,640 KB |
testcase_18 | AC | 116 ms
33,472 KB |
testcase_19 | AC | 117 ms
34,212 KB |
testcase_20 | AC | 74 ms
7,656 KB |
testcase_21 | AC | 74 ms
7,796 KB |
testcase_22 | AC | 63 ms
4,380 KB |
testcase_23 | AC | 64 ms
4,376 KB |
testcase_24 | AC | 71 ms
5,600 KB |
testcase_25 | AC | 71 ms
4,380 KB |
testcase_26 | AC | 74 ms
7,764 KB |
testcase_27 | AC | 75 ms
7,648 KB |
testcase_28 | AC | 73 ms
11,772 KB |
testcase_29 | AC | 76 ms
9,644 KB |
testcase_30 | AC | 626 ms
34,268 KB |
testcase_31 | AC | 627 ms
33,256 KB |
testcase_32 | AC | 625 ms
32,908 KB |
testcase_33 | AC | 501 ms
34,740 KB |
testcase_34 | AC | 499 ms
32,964 KB |
ソースコード
#include <cstdio> #include <cstring> #include <iostream> #include <string> #include <cmath> #include <bitset> #include <vector> #include <map> #include <set> #include <queue> #include <deque> #include <algorithm> #include <complex> #include <unordered_map> #include <unordered_set> #include <random> #include <cassert> #include <fstream> #include <utility> #include <functional> #include <time.h> #include <stack> #include <array> #define popcount __builtin_popcount using namespace std; typedef long long int ll; typedef pair<int, int> P; int main() { int n; cin>>n; vector<ll> a(n); for(int i=0; i<n; i++){ scanf("%lld", &a[i]); } ll as[20][200020]; for(int i=0; i<n; i++) as[0][i]=a[i]; for(int i=1; (1<<i)<=n; i++){ for(int j=0; j<n; j++){ if(j+1-(1<<i)>=0){ as[i][j]=(as[i-1][j]|as[i-1][j-(1<<(i-1))]); } } } int q; cin>>q; while(q--){ ll b; scanf("%lld", &b); int k=n-1; ll x=(1ll<<60)-1; int ans=0; while(k>=0){ for(int t=17; t>=0; t--){ if(k+1-(1<<t)<0) continue; if((x&as[t][k])==0) k-=(1<<t); } if(k==-1){ if(b==0) break; else if(x==b){ ans++; b=0; break; }else{ ans=-1; break; } } if(((b|a[k])&x)==b){ b^=(x&a[k]); x^=(x&a[k]); k--; }else if(((~b|a[k])&x)==(~b&x)){ ans++; b=(~b&x); b^=(x&a[k]); x^=(x&a[k]); k--; }else{ ans=-1; break; } } if(b!=0) ans=-1; printf("%d\n", ans); } return 0; }