結果

問題 No.1426 Got a Covered OR
ユーザー kk
提出日時 2021-04-17 18:14:35
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 17 ms / 2,000 ms
コード長 1,368 bytes
コンパイル時間 2,006 ms
コンパイル使用メモリ 202,504 KB
実行使用メモリ 4,500 KB
最終ジャッジ日時 2023-09-17 03:38:03
合計ジャッジ時間 3,406 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 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 2 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 5 ms
4,376 KB
testcase_13 AC 6 ms
4,376 KB
testcase_14 AC 5 ms
4,380 KB
testcase_15 AC 5 ms
4,380 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 3 ms
4,376 KB
testcase_18 AC 11 ms
4,380 KB
testcase_19 AC 11 ms
4,376 KB
testcase_20 AC 5 ms
4,376 KB
testcase_21 AC 7 ms
4,380 KB
testcase_22 AC 8 ms
4,380 KB
testcase_23 AC 17 ms
4,380 KB
testcase_24 AC 10 ms
4,376 KB
testcase_25 AC 16 ms
4,376 KB
testcase_26 AC 15 ms
4,500 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

const long long MOD = 1e9 + 7;
long long comb[32][32];

void init() {
  for (int i = 0; i < 32; i++) {
    comb[i][0] = comb[i][i] = 1;
    for (int j = 1; j < i; j++)
      comb[i][j] = (comb[i-1][j-1] + comb[i-1][j]) % MOD;
  }
}

long long modpow(long long x, long long p, long long mod) {
  long long ret = 1;
  while (p) {
    if (p & 1)
      ret = ret * x % mod;
    x = x * x % mod;
    p >>= 1;
  }
  return ret;
}

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

  init();
  
  int n;
  cin >> n;

  vector<int> b(n+1);
  for (int i = 1; i <= n; i++)
    cin >> b[i];

  long long ret = 1;
  for (int i = 0, j = 1; i < n; j++) {
    if (b[j] != -1) {
      if (b[i] & ~b[j]) {
        ret = 0;
        break;
      }

      int x = __builtin_popcountll(b[i]);
      int y = __builtin_popcountll(b[i]^b[j]);
      int m = j - i;
      long long tmp = 0;

      for (int k = 0; k <= y; k++) {
        long long z = modpow(2, x + y - k, MOD) - 1;
        if (z < 0)
          z += MOD;
        if (k % 2 == 0)
          tmp += comb[y][k] * modpow(z, m, MOD) % MOD;
        else
          tmp -= comb[y][k] * modpow(z, m, MOD) % MOD;

        tmp %= MOD;
        if (tmp < 0)
          tmp += MOD;
      }

      ret = ret * tmp % MOD;
      i = j;
    }
  }
  
  cout << ret << endl;
  
  return 0;
}
0