結果

問題 No.462 6日知らずのコンピュータ
ユーザー firiexpfiriexp
提出日時 2019-08-21 23:56:49
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 3,313 bytes
コンパイル時間 1,080 ms
コンパイル使用メモリ 103,404 KB
実行使用メモリ 4,508 KB
最終ジャッジ日時 2023-08-09 21:16:10
合計ジャッジ時間 4,524 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,384 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,384 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 2 ms
4,384 KB
testcase_14 AC 2 ms
4,384 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 2 ms
4,384 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 1 ms
4,380 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 1 ms
4,380 KB
testcase_26 AC 1 ms
4,380 KB
testcase_27 AC 2 ms
4,384 KB
testcase_28 AC 0 ms
4,380 KB
testcase_29 AC 2 ms
4,380 KB
testcase_30 AC 2 ms
4,380 KB
testcase_31 AC 2 ms
4,384 KB
testcase_32 AC 2 ms
4,380 KB
testcase_33 AC 2 ms
4,380 KB
testcase_34 AC 1 ms
4,380 KB
testcase_35 AC 1 ms
4,380 KB
testcase_36 AC 2 ms
4,380 KB
testcase_37 AC 2 ms
4,384 KB
testcase_38 AC 2 ms
4,380 KB
testcase_39 AC 2 ms
4,384 KB
testcase_40 AC 2 ms
4,384 KB
testcase_41 AC 2 ms
4,380 KB
testcase_42 AC 1 ms
4,384 KB
testcase_43 AC 2 ms
4,380 KB
testcase_44 AC 1 ms
4,384 KB
testcase_45 AC 2 ms
4,380 KB
testcase_46 AC 1 ms
4,380 KB
testcase_47 AC 1 ms
4,380 KB
testcase_48 AC 1 ms
4,508 KB
testcase_49 AC 2 ms
4,384 KB
testcase_50 AC 1 ms
4,384 KB
testcase_51 AC 1 ms
4,384 KB
testcase_52 AC 2 ms
4,380 KB
testcase_53 AC 2 ms
4,380 KB
testcase_54 AC 1 ms
4,380 KB
testcase_55 AC 2 ms
4,380 KB
testcase_56 AC 2 ms
4,384 KB
testcase_57 AC 1 ms
4,384 KB
testcase_58 AC 2 ms
4,380 KB
testcase_59 AC 1 ms
4,384 KB
testcase_60 AC 1 ms
4,380 KB
testcase_61 AC 2 ms
4,380 KB
testcase_62 AC 1 ms
4,380 KB
testcase_63 AC 2 ms
4,384 KB
testcase_64 AC 1 ms
4,384 KB
testcase_65 AC 1 ms
4,380 KB
testcase_66 AC 2 ms
4,380 KB
testcase_67 AC 2 ms
4,380 KB
testcase_68 AC 1 ms
4,384 KB
testcase_69 AC 1 ms
4,388 KB
testcase_70 AC 2 ms
4,380 KB
testcase_71 AC 2 ms
4,380 KB
testcase_72 AC 2 ms
4,384 KB
testcase_73 AC 1 ms
4,384 KB
testcase_74 AC 1 ms
4,384 KB
testcase_75 AC 2 ms
4,380 KB
testcase_76 AC 2 ms
4,380 KB
testcase_77 AC 2 ms
4,384 KB
testcase_78 AC 2 ms
4,380 KB
testcase_79 AC 1 ms
4,384 KB
testcase_80 AC 2 ms
4,380 KB
testcase_81 AC 1 ms
4,384 KB
testcase_82 AC 1 ms
4,380 KB
testcase_83 AC 1 ms
4,380 KB
testcase_84 AC 2 ms
4,384 KB
testcase_85 AC 2 ms
4,384 KB
testcase_86 AC 1 ms
4,384 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <limits>
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = uint32_t;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;



template <ll M = MOD> struct modint {
    ll val;
    modint(const ll x = 0) : val(x) {
        val = x;
        while(val < 0) val += M;
        while(val > M) val -= M;
    }

    modint operator+(const modint a) const { return modint(*this) += a; }
    modint operator-(const modint a) const { return modint(*this) -= a; }
    modint operator*(const modint a) const { return modint(*this) *= a; }
    modint operator/(const modint a) const { return modint(*this) /= a; }
    modint operator-() const { return modint(M-val); }
    modint inv() const {
        ll u = 1, v = 0, s = 0, t = 1, m = M, x = val;
        while (x) {ll q = m/x; swap(s -= q*u, u); swap(t -= q*v, v); swap(m -= q*x, x); }
        if(s < 0) s += M;
        return modint(s);
    }
    modint pow(ll n) const {
        ll u = 1, xx = val;
        while (n > 0){ if (n&1) u = u * xx % M; xx = xx * xx % M; n >>= 1; }
        return modint(u);
    }
    modint& operator+=(const modint a){ val += a.val; if(val >= M) val -= M; return *this; }
    modint& operator-=(const modint a){ val += a.val; if(val < 0) val += M; return *this; }
    modint& operator*=(const modint a){ val = val * a.val % M; return *this; }
    modint& operator/=(const modint a){ val = val * a.inv().val % M; return *this;}

    modint& operator=(const int& x){
        val = x;
        while(val < 0) val += M;
        while(val > M) val -= M;
        return *this;
    }
};


class Factorial {
    using mint = modint<MOD>;
    vector<mint> facts, factinv;

public:
    explicit Factorial(int n) : facts(static_cast<u32>(n+1)), factinv(static_cast<u32>(n+1)) {
        facts[0] = 1;
        for (int i = 1; i < n+1; ++i) facts[i] = facts[i-1]*mint(i);
        factinv[n] = facts[n].inv();
        for (int i = n-1; i >= 0; --i) factinv[i] = factinv[i+1] * mint(i+1);
    }

    mint fact(int k) const {
        if(k >= 0) return facts[k]; else return factinv[-k];
    }

    mint operator[](const int &k) const {
        if(k >= 0) return facts[k]; else return factinv[-k];
    }

    mint C(int p, int q) const {
        if(q < 0 || p < q) return 0;
        return facts[p] * factinv[q] * factinv[p-q];
    }

    mint P(int p, int q) const {
        if(q < 0 || p < q) return 0;
        return facts[p] * factinv[p-q];
    }

    mint H(int p, int q) const {
        if(p < 0 || q < 0) return 0;
        return q == 0 ? 1 : C(p+q-1, q);
    }
};


using mint = modint<MOD>;

int main() {
    ll n, k;
    cin >> n >> k;
    vector<ll> v(k);
    for (auto &&i : v) scanf("%lld", &i);
    sort(v.begin(),v.end());
    v.emplace_back((1LL << n)-1);

    Factorial f(n);
    mint ans = f[__builtin_popcountll(v[0])];
    for (int i = 0; i < k; ++i) {
        if((v[i] | v[i+1]) != v[i+1]) {
            puts("0");
            return 0;
        }else {
            ans *= f[__builtin_popcountll(v[i+1])-__builtin_popcountll(v[i])];
        }
    }
    cout << ans.val << "\n";
    return 0;
}
0