結果

問題 No.462 6日知らずのコンピュータ
ユーザー pekempey
提出日時 2016-12-13 00:10:47
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 840 bytes
コンパイル時間 1,661 ms
コンパイル使用メモリ 174,544 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-11-29 18:23:12
合計ジャッジ時間 3,678 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 84
権限があれば一括ダウンロードができます

ソースコード

diff #

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

const int mod = 1e9 + 7;

int main() {
    int n, k;
    cin >> n >> k;

    vector<int64_t> a(k);
    for (int i = 0; i < k; i++) {
        cin >> a[i];
    }
    sort(a.begin(), a.end(), [](int64_t a, int64_t b) {
        return __builtin_popcountll(a) < __builtin_popcountll(b);
    });
    a.insert(a.begin(), 0);
    a.push_back((1LL << n) - 1);

    vector<int64_t> fact(100);
    fact[0] = 1;
    for (int i = 1; i < 100; i++) {
        fact[i] = i * fact[i - 1] % mod;
    }

    int64_t ans = 1;
    for (int i = 0; i < a.size() - 1; i++) {
        if ((a[i] & a[i + 1]) != a[i]) {
            cout << 0 << endl;
            return 0;
        }
        int diff = __builtin_popcountll(a[i] ^ a[i + 1]);
        ans *= fact[diff];
        ans %= mod;
    }

    cout << ans << endl;
}
0