結果

問題 No.1426 Got a Covered OR
ユーザー ocvret_ocvret_
提出日時 2021-03-12 23:44:30
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 1,227 ms / 2,000 ms
コード長 1,983 bytes
コンパイル時間 1,642 ms
コンパイル使用メモリ 170,132 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-08-04 17:00:31
合計ジャッジ時間 4,234 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,504 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 1 ms
4,384 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 22 ms
4,376 KB
testcase_13 AC 69 ms
4,380 KB
testcase_14 AC 43 ms
4,380 KB
testcase_15 AC 17 ms
4,380 KB
testcase_16 AC 4 ms
4,376 KB
testcase_17 AC 5 ms
4,380 KB
testcase_18 AC 26 ms
4,384 KB
testcase_19 AC 26 ms
4,380 KB
testcase_20 AC 11 ms
4,380 KB
testcase_21 AC 17 ms
4,380 KB
testcase_22 AC 1,227 ms
4,380 KB
testcase_23 AC 45 ms
4,380 KB
testcase_24 AC 26 ms
4,376 KB
testcase_25 AC 37 ms
4,384 KB
testcase_26 AC 31 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0