結果

問題 No.1245 ANDORゲーム(calc)
ユーザー umezoumezo
提出日時 2020-10-03 19:29:35
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 234 ms / 2,000 ms
コード長 780 bytes
コンパイル時間 2,864 ms
コンパイル使用メモリ 202,456 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-25 05:40:47
合計ジャッジ時間 8,231 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 6 ms
4,376 KB
testcase_08 AC 4 ms
4,380 KB
testcase_09 AC 6 ms
4,376 KB
testcase_10 AC 8 ms
4,376 KB
testcase_11 AC 231 ms
4,380 KB
testcase_12 AC 234 ms
4,380 KB
testcase_13 AC 229 ms
4,380 KB
testcase_14 AC 230 ms
4,376 KB
testcase_15 AC 227 ms
4,380 KB
testcase_16 AC 229 ms
4,376 KB
testcase_17 AC 229 ms
4,380 KB
testcase_18 AC 222 ms
4,380 KB
testcase_19 AC 225 ms
4,376 KB
testcase_20 AC 223 ms
4,380 KB
testcase_21 AC 224 ms
4,376 KB
testcase_22 AC 225 ms
4,380 KB
testcase_23 AC 224 ms
4,376 KB
testcase_24 AC 232 ms
4,376 KB
testcase_25 AC 205 ms
4,376 KB
testcase_26 AC 201 ms
4,376 KB
testcase_27 AC 224 ms
4,380 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: 関数 ‘int main()’ 内:
main.cpp:24:16: 警告: 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){
    ll ans=0;
    rep(j,31){
      if(D[i]&(1<<j)) ans+=C[j];
      else ans+=B[j];
    }
    cout<<ans<<endl;
  }
  
  return 0;
}
0