結果

問題 No.462 6日知らずのコンピュータ
ユーザー okchan08
提出日時 2018-04-06 18:58:32
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 1,062 bytes
コンパイル時間 772 ms
コンパイル使用メモリ 66,188 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-06-26 10:49:04
合計ジャッジ時間 2,485 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 51 WA * 33
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

const int MOD = 1e9+7;

int f[100];

int fract(int n){
    if(n == 0 || n==1) return f[n] = 1;
    if(f[n] != 0) return f[n]%MOD;
    return f[n] = n*fract(n-1)%MOD;
}

int bit_count(long long N){
    int cnt = 0;
    while(N){
        cnt++;
        N &= N-1;
    }
    return cnt;
}

bool comp(long long a, long long b){
    return bit_count(a) < bit_count(b);
}

int main(){
    int N,k; cin >> N >> k;
    fract(N);
    if(k==0){
        cout << fract(N)%MOD << endl;
        return 0;
    }

    vector<long long> A(k+2);
    for(int i=1;i<=k;i++){
        cin >> A[i];
    }
    A[0] = 0; A[k+1] = (long long) (1<<N)-1;
    sort(A.begin(), A.end(), comp);
    long long ans = 1ll;
    for(int i=0;i<A.size()-1;i++){
        if(bit_count(A[i+1]) < bit_count(A[i+1] | A[i])){
            cout << 0 << endl;
            return 0;
        }
        long long diff = bit_count(A[i] ^ A[i+1]);
        (ans *= fract(diff) ) %= MOD;
    }

    cout << ans << endl;
    return 0;

}
0