結果

問題 No.1426 Got a Covered OR
ユーザー chocoruskchocorusk
提出日時 2021-03-12 22:07:17
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 52 ms / 2,000 ms
コード長 1,789 bytes
コンパイル時間 3,257 ms
コンパイル使用メモリ 188,272 KB
実行使用メモリ 19,692 KB
最終ジャッジ日時 2023-08-04 15:26:18
合計ジャッジ時間 4,837 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 7 ms
19,152 KB
testcase_01 AC 7 ms
19,020 KB
testcase_02 AC 7 ms
19,000 KB
testcase_03 AC 7 ms
19,052 KB
testcase_04 AC 7 ms
19,228 KB
testcase_05 AC 7 ms
19,044 KB
testcase_06 AC 8 ms
19,020 KB
testcase_07 AC 8 ms
19,172 KB
testcase_08 AC 8 ms
19,020 KB
testcase_09 AC 8 ms
19,112 KB
testcase_10 AC 7 ms
19,004 KB
testcase_11 AC 7 ms
19,024 KB
testcase_12 AC 21 ms
19,476 KB
testcase_13 AC 25 ms
19,292 KB
testcase_14 AC 21 ms
19,204 KB
testcase_15 AC 21 ms
19,228 KB
testcase_16 AC 9 ms
19,284 KB
testcase_17 AC 11 ms
19,140 KB
testcase_18 AC 33 ms
19,296 KB
testcase_19 AC 34 ms
19,272 KB
testcase_20 AC 17 ms
19,132 KB
testcase_21 AC 23 ms
19,140 KB
testcase_22 AC 36 ms
19,408 KB
testcase_23 AC 52 ms
19,692 KB
testcase_24 AC 32 ms
19,380 KB
testcase_25 AC 45 ms
19,420 KB
testcase_26 AC 39 ms
19,548 KB
権限があれば一括ダウンロードができます

ソースコード

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