結果

問題 No.1426 Got a Covered OR
ユーザー SSRSSSRS
提出日時 2021-03-12 22:09:12
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 390 ms / 2,000 ms
コード長 2,221 bytes
コンパイル時間 2,119 ms
コンパイル使用メモリ 174,464 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-22 13:09:38
合計ジャッジ時間 3,888 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 29 ms
5,376 KB
testcase_13 AC 52 ms
5,376 KB
testcase_14 AC 34 ms
5,376 KB
testcase_15 AC 25 ms
5,376 KB
testcase_16 AC 5 ms
5,376 KB
testcase_17 AC 7 ms
5,376 KB
testcase_18 AC 32 ms
5,376 KB
testcase_19 AC 33 ms
5,376 KB
testcase_20 AC 15 ms
5,376 KB
testcase_21 AC 20 ms
5,376 KB
testcase_22 AC 390 ms
5,376 KB
testcase_23 AC 57 ms
5,376 KB
testcase_24 AC 32 ms
5,376 KB
testcase_25 AC 46 ms
5,376 KB
testcase_26 AC 39 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
long long modpow(long long a, long long b){
	long long ans = 1;
	while (b > 0){
		if (b % 2 == 1){
			ans *= a;
			ans %= MOD;
		}
		a *= a;
		a %= MOD;
		b /= 2;
	}
	return ans;
}
long long modinv(long long a){
	return modpow(a, MOD - 2);
}
vector<long long> mf = {1};
vector<long long> mfi = {1};
long long modfact(int n){
	if (mf.size() > n){
		return mf[n];
	} else {
		for (int i = mf.size(); i <= n; i++){
			long long next = mf.back() * i % MOD;
			mf.push_back(next);
			mfi.push_back(modinv(next));
		}
		return mf[n];
	}
}
long long modfactinv(int n){
	if (mfi.size() > n){
		return mfi[n];
	} else {
		return modinv(modfact(n));
	}
}
long long modbinom(int n, int k){
	if (n < 0 || k < 0 || k > n){
		return 0;
	} else {
		return modfact(n) * modfactinv(k) % MOD * modfactinv(n - k) % MOD;
	}
}
int main(){
  int N;
  cin >> N;
  vector<int> B(N + 1);
  B[0] = 0;
  for (int i = 1; i <= N; i++){
    cin >> B[i];
  }
  vector<pair<int, int>> P;
  for (int i = 0; i <= N; i++){
    if (B[i] != -1){
      P.push_back(make_pair(B[i], i));
    }
  }
  int M = P.size();
  bool ok = true;
  for (int i = 0; i < M - 1; i++){
    if ((P[i].first | P[i + 1].first) != P[i + 1].first){
      ok = false;
    }
  }
  if (!ok){
    cout << 0 << endl;
  } else {
    long long ans = 1;
    for (int i = 0; i < M - 1; i++){
      int a = __builtin_popcount(P[i].first);
      int b = __builtin_popcount(P[i + 1].first ^ P[i].first);
      int d = P[i + 1].second - P[i].second;
      long long tmp = 0;
      for (int j = d; j >= 0; j--){
        long long tmp2 = 0;
        for (int k = b; k >= 0; k--){
          long long tmp3 = modpow(2, k * j) * modbinom(b, k) % MOD;
          if ((b - k) % 2 == 0){
            tmp2 += tmp3;
          } else {
            tmp2 += MOD - tmp3;
          }
        }
        tmp2 %= MOD;
        tmp2 *= modpow(2, a * j);
        tmp2 %= MOD;
        tmp2 *= modbinom(d, j);
        tmp2 %= MOD;
        if ((d - j) % 2 == 0){
          tmp += tmp2;
        } else {
          tmp += MOD - tmp2;
        }
      }
      tmp %= MOD;
      ans *= tmp;
      ans %= MOD;
    }
    cout << ans << endl;
  }
}
0