結果

問題 No.1245 ANDORゲーム(calc)
ユーザー simansiman
提出日時 2023-04-11 23:19:02
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
AC  
実行時間 230 ms / 2,000 ms
コード長 1,086 bytes
コンパイル時間 2,906 ms
コンパイル使用メモリ 141,428 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-16 18:42:02
合計ジャッジ時間 7,822 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 6 ms
5,376 KB
testcase_08 AC 3 ms
5,376 KB
testcase_09 AC 6 ms
5,376 KB
testcase_10 AC 8 ms
5,376 KB
testcase_11 AC 229 ms
5,376 KB
testcase_12 AC 230 ms
5,376 KB
testcase_13 AC 226 ms
5,376 KB
testcase_14 AC 228 ms
5,376 KB
testcase_15 AC 228 ms
5,376 KB
testcase_16 AC 226 ms
5,376 KB
testcase_17 AC 225 ms
5,376 KB
testcase_18 AC 222 ms
5,376 KB
testcase_19 AC 226 ms
5,376 KB
testcase_20 AC 225 ms
5,376 KB
testcase_21 AC 225 ms
5,376 KB
testcase_22 AC 224 ms
5,376 KB
testcase_23 AC 227 ms
5,376 KB
testcase_24 AC 227 ms
5,376 KB
testcase_25 AC 201 ms
5,376 KB
testcase_26 AC 204 ms
5,376 KB
testcase_27 AC 217 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cassert>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <climits>
#include <map>
#include <queue>
#include <set>
#include <cstring>
#include <vector>

using namespace std;
typedef long long ll;

int main() {
  int N, Q;
  cin >> N >> Q;
  ll A[N];
  for (int i = 0; i < N; ++i) {
    cin >> A[i];
  }
  string S;
  cin >> S;
  ll T[Q];
  for (int i = 0; i < Q; ++i) {
    cin >> T[i];
  }

  ll memo[35][2];
  memset(memo, 0, sizeof(memo));

  for (int i = 0; i < 35; ++i) {
    ll val = pow(2, i);

    for (int d = 0; d < 2; ++d) {
      ll cur = d;

      for (int idx = 0; idx < N; ++idx) {
        ll a = A[idx];
        ll b_cur = cur;
        
        if (S[idx] == '0') {
          cur &= (a >> i) & 1;
        } else {
          cur |= (a >> i) & 1;
        }

        memo[i][d] += (cur ^ b_cur) * val;
      }
    }
  }

  for (int i = 0; i < Q; ++i) {
    ll t = T[i];
    ll ans = 0;

    for (int i = 0; i < 35; ++i) {
      int d = (t >> i) & 1;
      ans += memo[i][d];
    }

    cout << ans << endl;
  }

  return 0;
}
0