結果

問題 No.1245 ANDORゲーム(calc)
ユーザー iqueue02iqueue02
提出日時 2020-10-03 00:33:10
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 269 ms / 2,000 ms
コード長 952 bytes
コンパイル時間 2,291 ms
コンパイル使用メモリ 205,700 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-25 01:07:18
合計ジャッジ時間 9,124 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 6 ms
4,376 KB
testcase_08 AC 3 ms
4,376 KB
testcase_09 AC 6 ms
4,380 KB
testcase_10 AC 8 ms
4,376 KB
testcase_11 AC 264 ms
4,380 KB
testcase_12 AC 269 ms
4,376 KB
testcase_13 AC 263 ms
4,376 KB
testcase_14 AC 265 ms
4,380 KB
testcase_15 AC 265 ms
4,380 KB
testcase_16 AC 262 ms
4,376 KB
testcase_17 AC 255 ms
4,384 KB
testcase_18 AC 253 ms
4,384 KB
testcase_19 AC 248 ms
4,380 KB
testcase_20 AC 262 ms
4,376 KB
testcase_21 AC 253 ms
4,376 KB
testcase_22 AC 250 ms
4,380 KB
testcase_23 AC 267 ms
4,380 KB
testcase_24 AC 264 ms
4,380 KB
testcase_25 AC 216 ms
4,380 KB
testcase_26 AC 215 ms
4,380 KB
testcase_27 AC 231 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
//#include <atcoder/all>
using namespace std;
//using namespace atcoder;
#define rep(i,n) for(int i = 0; i < (n);i++)
#define sz(x) int(x.size())
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;

int main() {
  int n, q;
  cin >> n >> q;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  string s;
  cin >> s;
 
  vector<vector<ll>> dp(2, vector<ll>(31, 0));

  for (int i = 0; i < 2; i++) {
    for (int j = 0; j < 31; j++) {
      int cur = i;
      for (int k = 0; k < n; k++) {
        int next = cur;
        if (s[k] == '1') next |= ((a[k] & (1 << j)) >> j);
        else next &= ((a[k] & (1 << j)) >> j);
        dp[i][j] += abs(cur - next) * (1 << j);
        cur = next;
      } 
    }
  }

  while (q--) {
    int a;
    cin >> a;
    ll res = 0;
    for (int i = 0; i < 31; i++) {
      if (a & (1 << i)) res += dp[1][i];
      else res += dp[0][i];
    }
    cout << res << endl;
  }
  return 0;
}
0