結果

問題 No.1245 ANDORゲーム(calc)
ユーザー SSRSSSRS
提出日時 2020-10-02 21:39:15
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 262 ms / 2,000 ms
コード長 1,181 bytes
コンパイル時間 3,973 ms
コンパイル使用メモリ 201,284 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-23 04:25:14
合計ジャッジ時間 11,157 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 7 ms
4,376 KB
testcase_08 AC 3 ms
4,380 KB
testcase_09 AC 6 ms
4,380 KB
testcase_10 AC 9 ms
4,376 KB
testcase_11 AC 262 ms
4,376 KB
testcase_12 AC 260 ms
4,380 KB
testcase_13 AC 257 ms
4,380 KB
testcase_14 AC 261 ms
4,376 KB
testcase_15 AC 258 ms
4,376 KB
testcase_16 AC 261 ms
4,380 KB
testcase_17 AC 248 ms
4,380 KB
testcase_18 AC 244 ms
4,376 KB
testcase_19 AC 250 ms
4,376 KB
testcase_20 AC 254 ms
4,380 KB
testcase_21 AC 250 ms
4,376 KB
testcase_22 AC 251 ms
4,380 KB
testcase_23 AC 253 ms
4,380 KB
testcase_24 AC 249 ms
4,380 KB
testcase_25 AC 215 ms
4,380 KB
testcase_26 AC 211 ms
4,376 KB
testcase_27 AC 233 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
int main(){
  int N, Q;
  cin >> N >> Q;
  vector<int> A(N);
  for (int i = 0; i < N; i++){
    cin >> A[i];
  }
  string S;
  cin >> S;
  vector<int> start(30, -1);
  vector<int> curr(30, -1);
  vector<int> cnt(30, 0);
  for (int i = 0; i < N; i++){
    if (S[i] == '0'){
      for (int j = 0; j < 30; j++){
        if (!(A[i] >> j & 1)){
          if (curr[j] == -1){
            start[j] = 0;
          } else if (curr[j] == 1){
            cnt[j]++;
          }
          curr[j] = 0;
        }
      }
    }
    if (S[i] == '1'){
      for (int j = 0; j < 30; j++){
        if (A[i] >> j & 1){
          if (curr[j] == -1){
            start[j] = 1;
          } else if (curr[j] == 0){
            cnt[j]++;
          }
          curr[j] = 1;
        }
      }
    }
  }
  for (int i = 0; i < Q; i++){
    int t;
    cin >> t;
    long long ans = 0;
    for (int j = 0; j < 30; j++){
      if (t >> j & 1){
        if (start[j] == 0){
          ans += 1 << j;
        }
      } else {
        if (start[j] == 1){
          ans += 1 << j;
        }
      }
      ans += (long long) cnt[j] << j;
    }
    cout << ans << endl;
  }
}
0