結果

問題 No.1426 Got a Covered OR
ユーザー snow39snow39
提出日時 2021-03-18 15:07:21
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 756 ms / 2,000 ms
コード長 2,921 bytes
コンパイル時間 1,363 ms
コンパイル使用メモリ 115,416 KB
実行使用メモリ 54,704 KB
最終ジャッジ日時 2024-04-28 05:29:22
合計ジャッジ時間 5,259 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 59 ms
26,752 KB
testcase_01 AC 56 ms
26,752 KB
testcase_02 AC 51 ms
26,880 KB
testcase_03 AC 47 ms
26,744 KB
testcase_04 AC 60 ms
26,752 KB
testcase_05 AC 60 ms
26,752 KB
testcase_06 AC 50 ms
26,752 KB
testcase_07 AC 51 ms
26,752 KB
testcase_08 AC 47 ms
26,752 KB
testcase_09 AC 46 ms
26,752 KB
testcase_10 AC 50 ms
26,752 KB
testcase_11 AC 59 ms
26,752 KB
testcase_12 AC 71 ms
31,292 KB
testcase_13 AC 104 ms
31,028 KB
testcase_14 AC 86 ms
29,720 KB
testcase_15 AC 68 ms
30,816 KB
testcase_16 AC 51 ms
27,248 KB
testcase_17 AC 53 ms
26,880 KB
testcase_18 AC 67 ms
27,520 KB
testcase_19 AC 81 ms
27,548 KB
testcase_20 AC 62 ms
27,124 KB
testcase_21 AC 58 ms
27,244 KB
testcase_22 AC 756 ms
54,704 KB
testcase_23 AC 103 ms
27,912 KB
testcase_24 AC 79 ms
28,072 KB
testcase_25 AC 84 ms
27,848 KB
testcase_26 AC 95 ms
27,904 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define all(v) v.begin(),v.end()
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;
template<class T> void chmin(T &a,const T &b){if(a>b) a=b;}
template<class T> void chmax(T &a,const T &b){if(a<b) a=b;}

#define MAX_N 1000010
ll inv[MAX_N+10],fac[MAX_N+10],ifac[MAX_N+10];

void setComb(){
  inv[0]=1;inv[1]=1;fac[1]=1;ifac[1]=1;fac[0]=1;ifac[0]=1;
  for(int i=2;i<MAX_N;i++){
    inv[i]=(-MOD/i)*inv[MOD%i]%MOD;
    fac[i]=fac[i-1]*i%MOD;
    ifac[i]=ifac[i-1]*inv[i]%MOD;

    inv[i]=(inv[i]+MOD)%MOD;
    fac[i]=(fac[i]+MOD)%MOD;
    ifac[i]=(ifac[i]+MOD)%MOD;
  }
  return;
}

ll comb(ll n,ll k){
  if(n<k||n<0||k<0) return 0;
  else return ((fac[n]*ifac[k]%MOD*ifac[n-k]%MOD+MOD)%MOD);
}

ll hcomb(ll n,ll r){// this size is really ok??
  if(n==0&&r==0) return 1;
  else if(n<0||r<0) return 0;
  else return comb(n+r-1,r);
}

ll binom(ll n,ll k){
  if(n<k||n<0||k<0) return 0;
  ll res=1;
  for(ll i=0;i<k;i++) res=res*(n-i)%MOD;
  res=res*ifac[k]%MOD;
  return res;
}

ll mod_pow(ll x,ll n){
  x%=MOD;
  ll res=1;
  while(n>0){
    if(n&1) res=res*x%MOD;
    x=x*x%MOD;
    n>>=1;
  }
  return res;
}

ll mod_inverse(ll x){
  return mod_pow(x,MOD-2);
}

void add(ll &a,ll b){
  a=(a+b)%MOD;
}

void mul(ll &a,ll b){
  a%=MOD;b%=MOD;
  a=a*b%MOD;
}

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

  setComb();

  int N;
  cin>>N;
  vector<ll> B(N+1,0);
  rep(i,N) cin>>B[i+1];

  vector<ll> two(31,0);
  two[0]=1;
  rep(i,30) two[i+1]=two[i]*2%MOD;

  vector<int> v;
  rep(i,N+1) if(B[i]!=-1) v.push_back(i);

  ll ans=1;
  for(int p=0;p+1<(int)v.size();p++){
      int now=v[p];
      int nex=v[p+1];
      int len=nex-now;
      
      int plus_bit=0;
      rep(k,30){
          if(B[now]&(1<<k)){
              if((B[nex]&(1<<k))==0){
                  cout<<0<<endl;
                  return 0;
              }
          }else{
              if(B[nex]&(1<<k)) plus_bit++;
          }
      }
      int base_bit=__builtin_popcount(B[now]);
      int all_bit=base_bit+plus_bit;

      vector<vector<ll>> dp(len+1,vector<ll> (all_bit+1,0));
      dp[0][base_bit]=1;
      for(int i=0;i<len;i++){
          for(int j=base_bit;j<=all_bit;j++){
              ll value=dp[i][j];
              if(value==0) continue;
              for(int k=j;k<=all_bit;k++){
                  ll coef=comb(all_bit-j,k-j);
                  if(k==j) mul(coef,two[j]-1);
                  else mul(coef,two[j]);

                  ll res=value;
                  mul(res,coef);
                  
                  add(dp[i+1][k],res);
              }
          }
      }

      mul(ans,dp[len][all_bit]);
  }

  cout<<ans<<endl;

  return 0;
}
0