結果

問題 No.1245 ANDORゲーム(calc)
ユーザー umezo
提出日時 2020-10-03 19:28:35
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 781 bytes
コンパイル時間 1,930 ms
コンパイル使用メモリ 197,960 KB
最終ジャッジ日時 2025-01-15 02:13:29
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 5 WA * 20
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:24:16: warning: integer overflow in expression of type ‘int’ results in ‘2147483647’ [-Woverflow]
   24 |   int c=(1<<31)-1;
      |         ~~~~~~~^~

ソースコード

diff #

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(v) v.begin(),v.end()
typedef long long ll;

#include <bits/stdc++.h>
using namespace std;

int main(){
  int n,q;
  cin>>n>>q;
  
  vector<int> A(n);
  rep(i,n) cin>>A[i];
  
  string s;
  cin>>s;
  
  vector<int> D(q);
  rep(i,q) cin>>D[i];
  
  vector<ll> B(31),C(31);
  
  int b=0;
  int c=(1<<31)-1;
  for(int i=0;i<n;i++){
    int btmp=b,ctmp=c;
    if(s[i]=='0'){
      b=b&A[i];
      c=c&A[i];
    }
    else{
      b=b|A[i];
      c=c|A[i];
    }
    for(int j=0;j<31;j++){
      B[j]+=abs((b&(1<<j))-(btmp&(1<<j)));
      C[j]+=abs((c&(1<<j))-(ctmp&(1<<j)));
    }
  }

  rep(i,q){
    int ans=0;
    rep(j,31){
      if(D[i]&(1<<j)) ans+=C[j];
      else ans+=B[j];
    }
    cout<<ans<<endl;
  }
  
  return 0;
}
0