結果

問題 No.1245 ANDORゲーム(calc)
ユーザー kk
提出日時 2020-10-06 16:43:30
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 204 ms / 2,000 ms
コード長 857 bytes
コンパイル時間 1,996 ms
コンパイル使用メモリ 199,692 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-27 08:00:02
合計ジャッジ時間 10,231 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 5 ms
4,376 KB
testcase_08 AC 3 ms
4,380 KB
testcase_09 AC 5 ms
4,376 KB
testcase_10 AC 7 ms
4,380 KB
testcase_11 AC 204 ms
4,380 KB
testcase_12 AC 200 ms
4,380 KB
testcase_13 AC 201 ms
4,380 KB
testcase_14 AC 201 ms
4,376 KB
testcase_15 AC 204 ms
4,376 KB
testcase_16 AC 203 ms
4,380 KB
testcase_17 AC 195 ms
4,376 KB
testcase_18 AC 195 ms
4,376 KB
testcase_19 AC 190 ms
4,380 KB
testcase_20 AC 197 ms
4,380 KB
testcase_21 AC 196 ms
4,380 KB
testcase_22 AC 192 ms
4,376 KB
testcase_23 AC 203 ms
4,380 KB
testcase_24 AC 202 ms
4,380 KB
testcase_25 AC 165 ms
4,376 KB
testcase_26 AC 170 ms
4,376 KB
testcase_27 AC 179 ms
4,384 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,b,e) for (int i=(int)(b); i<(int)(e); i++)
#define ALL(x) (x).begin(), (x).end()

const double PI = acos(-1);

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int n, q;
  cin >> n >> q;
  vector<int> a(n);
  REP (i, n) cin >> a[i];
  string s;
  cin >> s;

  long long dp[30][2];
  REP (i, 30) {
    REP (j, 2) {
      dp[i][j] = 0;
      int t = (1<<i) * j;
      REP (k, n) {
        int w = (s[k] == '0') ? (t & a[k]) : (t | a[k]);
        w &= 1<<i;
        dp[i][j] += abs(w - t);
        t = w;
      }
    }
  }

  REP (i, q) {
    int t;
    cin >> t;
    long long ret = 0;
    REP (j, 30) {
      if (t & 1<<j)
        ret += dp[j][1];
      else
        ret += dp[j][0];
    }
    cout << ret << endl;
  }
  
  return 0;
}
0