結果

問題 No.1426 Got a Covered OR
ユーザー chocorusk
提出日時 2021-03-12 22:07:17
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 55 ms / 2,000 ms
コード長 1,789 bytes
コンパイル時間 2,956 ms
コンパイル使用メモリ 182,012 KB
最終ジャッジ日時 2025-01-19 14:50:13
ジャッジサーバーID
(参考情報)
judge2 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 24
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#include <list>
#include <atcoder/all>
#define popcount __builtin_popcount
using namespace std;
using namespace atcoder;
typedef long long ll;
typedef pair<int, int> P;
using mint=modint1000000007;
mint f[2000010], invf[2000010];
void fac(int n){
    f[0]=1;
    for(ll i=1; i<=n; i++) f[i]=f[i-1]*i;
    invf[n]=f[n].inv();
    for(ll i=n-1; i>=0; i--) invf[i]=invf[i+1]*(i+1);
}
mint comb(int x, int y){
    if(!(0<=y && y<=x)) return 0;
    return f[x]*invf[y]*invf[x-y];
}
int main()
{
    int n; cin>>n;
    int b[100010];
    for(int i=0; i<n; i++) cin>>b[i];
    int bs=0;
    for(int i=0; i<n; i++){
        if(b[i]==-1) continue;
        if((bs|b[i])!=b[i]){
            cout<<0<<endl;
            return 0;
        }
        bs|=b[i];
    }
    fac(n);
    auto calc=[&](int m, int c, int cpr){
        mint res=0;
        for(int i=0; i<=m; i++){
            mint q=mint(2).pow(m-i);
            mint z=comb(m, i)*(q-1).pow(c-cpr)*q.pow(cpr);
            if(i&1) res-=z;
            else res+=z;
        }
        return res;
    };
    int cpr=0;
    int pr=-1;
    mint ans=1;
    for(int i=0; i<n; i++){
        if(b[i]==-1) continue;
        int c=popcount(b[i]);
        //cout<<calc(i-pr, c, cpr).val()<<" "<<i-pr<<" "<<c<<" "<<cpr<<endl;
        ans*=calc(i-pr, c, cpr);
        pr=i, cpr=c;
    }
    cout<<ans.val()<<endl;
    return 0;
}
0