結果

問題 No.1296 OR or NOR
ユーザー 👑 NachiaNachia
提出日時 2020-11-20 22:14:39
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,334 bytes
コンパイル時間 2,864 ms
コンパイル使用メモリ 205,268 KB
実行使用メモリ 4,916 KB
最終ジャッジ日時 2023-09-30 19:24:57
合計ジャッジ時間 22,644 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,356 KB
testcase_01 AC 2 ms
4,356 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 482 ms
4,536 KB
testcase_05 WA -
testcase_06 AC 574 ms
4,916 KB
testcase_07 AC 563 ms
4,868 KB
testcase_08 AC 564 ms
4,548 KB
testcase_09 AC 504 ms
4,888 KB
testcase_10 AC 504 ms
4,612 KB
testcase_11 AC 441 ms
4,608 KB
testcase_12 AC 445 ms
4,656 KB
testcase_13 AC 476 ms
4,868 KB
testcase_14 AC 591 ms
4,716 KB
testcase_15 AC 498 ms
4,736 KB
testcase_16 AC 469 ms
4,604 KB
testcase_17 AC 562 ms
4,592 KB
testcase_18 AC 563 ms
4,604 KB
testcase_19 AC 569 ms
4,576 KB
testcase_20 AC 399 ms
4,356 KB
testcase_21 AC 395 ms
4,360 KB
testcase_22 AC 393 ms
4,356 KB
testcase_23 AC 392 ms
4,356 KB
testcase_24 AC 393 ms
4,356 KB
testcase_25 AC 396 ms
4,356 KB
testcase_26 AC 402 ms
4,352 KB
testcase_27 AC 399 ms
4,352 KB
testcase_28 AC 396 ms
4,352 KB
testcase_29 AC 395 ms
4,356 KB
testcase_30 AC 534 ms
4,596 KB
testcase_31 AC 529 ms
4,724 KB
testcase_32 AC 533 ms
4,596 KB
testcase_33 AC 481 ms
4,584 KB
testcase_34 AC 485 ms
4,656 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using LL=long long;
using ULL=unsigned long long;
#define rep(i,n) for(int i=0;i<(n);i++)

int N,Q;
vector<ULL> A;

int main(){
  cin>>N;
  A.resize(N);
  rep(i,N) cin>>A[i];

  vector<ULL> G;
  ULL no;
  {
    int dcrA[60];
    int rA[60]; rep(i,60) rA[i]=-1;
    rep(i,N) rep(d,60) if((A[i]>>d)&1) rA[d]=i;

    pair<int,int> S[61];
    S[0] = {-1,-1};
    rep(i,60){ S[i+1] = {rA[i],i}; }
    sort(S,S+61);
    int p=-1;
    rep(i,60){
      if(S[i+1].first!=S[i].first) p++;
      dcrA[S[i+1].second]=p;
    }
    G.resize(p+1);
    no=0;
    rep(i,60){
      if(dcrA[i]==-1) no |= 1ull<<i;
      else G[dcrA[i]] |= 1ull<<i;
    }
  }

  cin>>Q;
  while(Q--){
    ULL b; cin>>b;
    bool enable = true;

    int no_flipped=0;
    if((no&b) == 0){ no_flipped=0; }
    else if((no&b) == no){ no_flipped=1; }
    else enable=false;

    for(ULL g:G) if(((g&b) != g) && ((g&b) != 0)) enable=false;
    
    int flipped = 0;
    int ans=0;
    for(int i=G.size()-1; i>=0 && enable; i--){
      ULL g = G[i];
      int flip=1; if(g&b) flip=0;
      if(flipped != flip) ans++;
      flipped = flip;
    }
    
    if(no) if(ans%2 != no_flipped) {
      ans++;
      if(G.size()==N){ enable=false; }
    }

    if(!enable){ cout<<-1<<endl; continue; }
    cout<<ans<<endl;
  }

  return 0;
}

0