結果

問題 No.1245 ANDORゲーム(calc)
ユーザー siman
提出日時 2023-04-11 23:19:02
言語 C++17(clang)
(17.0.6 + boost 1.87.0)
結果
AC  
実行時間 235 ms / 2,000 ms
コード長 1,086 bytes
コンパイル時間 3,635 ms
コンパイル使用メモリ 141,816 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-10-07 18:41:21
合計ジャッジ時間 9,660 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 25
権限があれば一括ダウンロードができます

ソースコード

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