結果
| 問題 |
No.1426 Got a Covered OR
|
| コンテスト | |
| ユーザー |
ocvret_
|
| 提出日時 | 2021-03-12 23:44:30 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 1,320 ms / 2,000 ms |
| コード長 | 1,983 bytes |
| コンパイル時間 | 1,845 ms |
| コンパイル使用メモリ | 173,932 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-10-14 14:11:41 |
| 合計ジャッジ時間 | 4,572 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 24 |
ソースコード
#include<bits/stdc++.h>
// #include<atcoder/all>
// #include<boost/multiprecision/cpp_int.hpp>
using namespace std;
// using namespace atcoder;
// using bint = boost::multiprecision::cpp_int;
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;
#define rep(i,n) for(ll i = 0;i < (ll)n;i++)
#define ALL(x) (x).begin(),(x).end()
#define MOD 1000000007
// 2020/12/06 rechecked
class Comb{
public:
const int n;
const int mod = 1000000007;
// const int mod = 998244353;
vector<long long> fac,refac;
Comb(int N) : n(N),fac(N+1,1),refac(N+1,1) {
for(int i = 0;i < n;i++)fac[i+1] = fac[i]*(i+1)%mod;
refac[n] = modpow(fac[n],mod-2);
for(int i = n;i > 0;i--)refac[i-1] = refac[i]*i%mod;
}
long long comb(long long n,long long r){
if(n < r)return 0;
long long res = fac[n]*refac[r]%mod;
res = res*refac[n-r]%mod;
return res;
}
long long modpow(long long n,long long r){
long long res = 1;
while(r){
if(r & 1)res = res*n%mod;
n = n*n%mod;
r >>= 1;
}
return res;
}
};
int main(){
int n;
cin >> n;
vector<int> b(n);
rep(i,n)cin >> b[i];
{
int pre = 0;
rep(i,n){
if(b[i] == -1)continue;
if((b[i] & pre) != pre){
cout << 0 << "\n";
return 0;
}else pre = b[i] | pre;
}
}
int x = 0;
int cnt = 0;
ll res = 1;
Comb cb(100);
vector<ll> two(100,1);
rep(i,99)two[i+1] = two[i]*2%MOD;
rep(i,n){
if(b[i] == -1)cnt++;
else {
int nx = __builtin_popcount(b[i]);
cnt++;
vector<ll> dp(nx-x+1);
dp[0] = 1;
rep(j,cnt){
vector<ll> DP(nx-x+1);
rep(k,nx-x+1)rep(l,k+1){
if(k != l)DP[k] = (DP[k] + (dp[l]*two[x+l]%MOD)*cb.comb(nx-x-l,k-l)%MOD)%MOD;
else DP[k] = (DP[k] + (dp[l]*(two[x+l]-1+MOD)%MOD))%MOD;
}
swap(dp,DP);
}
(res *= dp[nx-x])%= MOD;
cnt = 0;
x = nx;
}
}
cout << res << "\n";
return 0;
}
ocvret_