結果

問題 No.462 6日知らずのコンピュータ
ユーザー aaaaaaiu
提出日時 2019-08-27 20:53:23
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 62 ms / 2,000 ms
コード長 666 bytes
コンパイル時間 2,143 ms
コンパイル使用メモリ 197,272 KB
最終ジャッジ日時 2025-01-07 15:23:25
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 84
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int popcnt(ll n) {
    int cnt=0;
    while (n) {
        cnt++;
        n&=n-1;
    }
    return cnt;
}

int main() {
    int mod=1e9+7;
    int n,k;
    cin>>n>>k;
    ll fact[n+1];
    fact[0]=1;
    for (int i=1;i<=n;i++)
        fact[i]=i*fact[i-1]%mod;
    ll a[k+2];
    for (int i=0;i<k;i++)
        cin>>a[i];
    a[k]=0;
    a[k+1]=(1LL<<n)-1;
    sort(a,a+k+2);
    ll ans=1;
    for (int i=0;i<k+1;i++) {
        if (a[i]&~a[i+1]) {
            puts("0");
            return 0;
        }
        ans=ans*fact[popcnt(a[i+1])-popcnt(a[i])]%mod;
    }
    cout<<ans<<endl;
    return 0;
}
0