結果

問題 No.1426 Got a Covered OR
ユーザー butsurizukibutsurizuki
提出日時 2021-03-12 22:35:39
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 392 ms / 2,000 ms
コード長 1,931 bytes
コンパイル時間 1,621 ms
コンパイル使用メモリ 167,924 KB
実行使用メモリ 11,904 KB
最終ジャッジ日時 2024-04-22 13:46:25
合計ジャッジ時間 3,523 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 11 ms
11,648 KB
testcase_01 AC 12 ms
11,520 KB
testcase_02 AC 12 ms
11,776 KB
testcase_03 AC 11 ms
11,648 KB
testcase_04 AC 12 ms
11,520 KB
testcase_05 AC 11 ms
11,776 KB
testcase_06 AC 12 ms
11,520 KB
testcase_07 AC 11 ms
11,648 KB
testcase_08 AC 11 ms
11,648 KB
testcase_09 AC 11 ms
11,520 KB
testcase_10 AC 12 ms
11,648 KB
testcase_11 AC 12 ms
11,648 KB
testcase_12 AC 24 ms
11,740 KB
testcase_13 AC 39 ms
11,872 KB
testcase_14 AC 29 ms
11,744 KB
testcase_15 AC 21 ms
11,744 KB
testcase_16 AC 13 ms
11,776 KB
testcase_17 AC 14 ms
11,904 KB
testcase_18 AC 31 ms
11,648 KB
testcase_19 AC 29 ms
11,744 KB
testcase_20 AC 19 ms
11,904 KB
testcase_21 AC 22 ms
11,744 KB
testcase_22 AC 392 ms
11,776 KB
testcase_23 AC 41 ms
11,648 KB
testcase_24 AC 20 ms
11,776 KB
testcase_25 AC 37 ms
11,904 KB
testcase_26 AC 23 ms
11,776 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#define mod 1000000007

using namespace std;

int dsumb(int x,int b){int r=0;while(x){r+=(x%b);x/=b;}return r;}

long long power(long long a,long long b){
  long long x=1,y=a;
  while(b>0){
    if(b&1ll){
      x=(x*y)%mod;
    }
    y=(y*y)%mod;
    b>>=1;
  }
  return x%mod;
}

long long modular_inverse(long long n){
  return power(n,mod-2);
}

long long factorial[524288];
long long invfact[524288];

void cfact(){
  long long i;
  factorial[0]=1;
  factorial[1]=1;
  for(i=2;i<524288;i++){
    factorial[i]=factorial[i-1]*i;
    factorial[i]%=mod;
  }
  invfact[524287]=modular_inverse(factorial[524287]);
  for(i=524286;i>=0;i--){
    invfact[i]=invfact[i+1]*(i+1);
    invfact[i]%=mod;
  }
}

long long calcnCr(long long n,long long k){
  if(k<0 || n<k){return 0;}
  return (factorial[n]*((invfact[k]*invfact[n-k])%mod))%mod;
}

long long calc(long long len,long long fr,long long to){
  vector<long long> dp(to+1);
  dp[fr]=1;
  for(int i=0;i<len;i++){
    vector<long long> ndp(to+1);
    for(int j=0;j<=to;j++){
      if(dp[j]==0){continue;}
      ndp[j]+=dp[j]*(power(2,j)-1);
      ndp[j]%=mod;
      for(int k=j+1;k<=to;k++){
        long long ce=calcnCr(to-j,k-j);
        ce*=power(2,j);ce%=mod;
        ndp[k]+=dp[j]*ce;
        ndp[k]%=mod;
      }
    }
    dp.swap(ndp);
  }
  return dp[to];
}

int main(){
  cfact();
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  cin >> n;
  vector<int> a(n);
  for(int i=0;i<n;i++){cin >> a[i];}
  int mem=-1;
  for(int i=0;i<n;i++){
    if(a[i]!=-1){
      if(mem==-1){mem=a[i];}
      else if((mem&a[i])!=mem){
        cout << "0\n";
        return 0;
      }
      mem=a[i];
    }
  }
  int pv=0;
  long long res=1;
  long long len=1;
  for(int i=0;i<n;i++){
    if(a[i]!=-1){
      res*=calc(len,dsumb(pv,2),dsumb(a[i],2));
      res%=mod;
      pv=a[i];
      len=1;
    }
    else{len++;}
  }
  cout << res << '\n';
  return 0;
}
0