結果

問題 No.462 6日知らずのコンピュータ
ユーザー imulan
提出日時 2016-12-13 02:19:18
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,184 bytes
コンパイル時間 1,757 ms
コンパイル使用メモリ 174,064 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2024-11-30 00:24:47
合計ジャッジ時間 3,655 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 58 WA * 26
権限があれば一括ダウンロードができます

ソースコード

diff #

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

typedef long long ll;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); ++itr)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second

const ll mod=1e9+7;

inline ll fact(int n)
{
    ll ret=1;
    for(int i=2; i<=n; ++i) (ret*=i)%=mod;
    return ret;
}

inline bool canmove(ll from, ll to)
{
    rep(i,61)
    {
        if(from>>i&1 && !(to>>i&1)) return false;
    }
    return true;
}

ll solve()
{
    int n,k;
    scanf(" %d %d", &n, &k);

    int ct[61]={};
    vector<ll> a(k);
    rep(i,k)
    {
        scanf(" %lld", &a[i]);
        ++ct[__builtin_popcount(a[i])];
    }

    if(k==0) return fact(n);
    rep(i,61) if(ct[i]>1) return 0;

    sort(all(a));

    ll ret=1;

    (ret*=fact(__builtin_popcount(a[0])))%=mod;
    for(int i=1; i<k; ++i)
    {
        if(!canmove(a[i-1],a[i])) return 0;
        (ret*=fact(__builtin_popcount(a[i])-__builtin_popcount(a[i-1])))%=mod;
    }
    (ret*=fact(n - __builtin_popcount(a[k-1])))%=mod;

    return ret;
}

int main()
{
    cout << solve() << endl;
    return 0;
}
0