結果

問題 No.1426 Got a Covered OR
ユーザー kk
提出日時 2021-04-17 17:19:00
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 397 ms / 2,000 ms
コード長 1,778 bytes
コンパイル時間 2,073 ms
コンパイル使用メモリ 205,936 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-17 02:44:46
合計ジャッジ時間 4,365 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 16 ms
4,384 KB
testcase_13 AC 34 ms
4,376 KB
testcase_14 AC 22 ms
4,380 KB
testcase_15 AC 13 ms
4,380 KB
testcase_16 AC 3 ms
4,376 KB
testcase_17 AC 4 ms
4,376 KB
testcase_18 AC 17 ms
4,380 KB
testcase_19 AC 17 ms
4,380 KB
testcase_20 AC 8 ms
4,380 KB
testcase_21 AC 11 ms
4,380 KB
testcase_22 AC 397 ms
4,376 KB
testcase_23 AC 27 ms
4,380 KB
testcase_24 AC 10 ms
4,380 KB
testcase_25 AC 24 ms
4,376 KB
testcase_26 AC 24 ms
4,380 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;
}

long long calc(int x, int y, int n) {

  vector<long long> cur(32);
  cur[x] = 1;
  
  for (int i = 0; i < n; i++) {
    vector<long long> nxt(32);

    // xで立っているbitがall zeroのとき
    for (int j = x; j <= y; j++) {
      for (int k = 1; k <= y-j; k++) {
        nxt[j+k] += cur[j] * comb[y-j][k] % MOD;
        nxt[j+k] %= MOD;
      }
    }

    // xで立っているbitがall zeroではないとき
    for (int j = x; j <= y; j++) {
      long long base = modpow(2, j, MOD) - 1;
      if (base < 0)
        base += MOD;
      base = base * cur[j] % MOD;
      for (int k = 0; k <= y-j; k++) {
        nxt[j+k] += base * comb[y-j][k] % MOD;
        nxt[j+k] %= MOD;
      }
    }
    cur = nxt;
  }

  return cur[y];
}

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

  init();
  
  int n;
  cin >> n;
  vector<int> b(n);
  vector<int> p;

  for (int i = 0; i < n; i++) {
    cin >> b[i];
    if (b[i] != -1)
      p.push_back(i);
  }

  long long ret = 1;
  int j = -1;
  int x = 0;
  for (int i: p) {
    int y = b[i];
    if ((y & x) != x) {
      ret = 0;
      break;
    }

    int bx = __builtin_popcountll(x);
    int by = __builtin_popcountll(y);

    ret *= calc(bx, by, i-j);
    ret %= MOD;

    x = y;
    j = i;
  }

  cout << ret << endl;
  
  return 0;
}
0