結果

問題 No.1035 Color Box
ユーザー t98slidert98slider
提出日時 2023-05-21 19:04:31
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 3,676 bytes
コンパイル時間 1,719 ms
コンパイル使用メモリ 170,684 KB
実行使用メモリ 4,584 KB
最終ジャッジ日時 2023-08-23 15:14:08
合計ジャッジ時間 4,294 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 12 ms
4,584 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 4 ms
4,380 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 10 ms
4,544 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 1 ms
4,380 KB
testcase_12 WA -
testcase_13 AC 9 ms
4,376 KB
testcase_14 AC 10 ms
4,380 KB
testcase_15 AC 11 ms
4,508 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 11 ms
4,544 KB
testcase_20 WA -
testcase_21 AC 1 ms
4,376 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 1 ms
4,376 KB
testcase_24 AC 1 ms
4,380 KB
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 2 ms
4,376 KB
testcase_29 AC 2 ms
4,376 KB
testcase_30 WA -
testcase_31 AC 1 ms
4,376 KB
testcase_32 AC 2 ms
4,376 KB
testcase_33 AC 2 ms
4,376 KB
testcase_34 AC 2 ms
4,380 KB
testcase_35 WA -
testcase_36 WA -
testcase_37 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

template<const unsigned int MOD> struct prime_modint {
    using mint = prime_modint;
    unsigned int v;
    prime_modint() : v(0) {}
    prime_modint(unsigned int a) { a %= MOD; v = a; }
    prime_modint(unsigned long long a) { a %= MOD; v = a; }
    prime_modint(int a) { a %= (int)(MOD); if(a < 0)a += MOD; v = a; }
    prime_modint(long long a) { a %= (int)(MOD); if(a < 0)a += MOD; v = a; }
    static constexpr int mod() { return MOD; }
    mint& operator++() {v++; if(v == MOD)v = 0; return *this;}
    mint& operator--() {if(v == 0)v = MOD; v--; return *this;}
    mint operator++(int) { mint result = *this; ++*this; return result; }
    mint operator--(int) { mint result = *this; --*this; return result; }
    mint& operator+=(const mint& rhs) { v += rhs.v; if(v >= MOD) v -= MOD; return *this; }
    mint& operator-=(const mint& rhs) { if(v < rhs.v) v += MOD; v -= rhs.v; return *this; }
    mint& operator*=(const mint& rhs) {
        v = (unsigned int)((unsigned long long)(v) * rhs.v % MOD);
        return *this;
    }
    mint& operator/=(const mint& rhs) { return *this = *this * rhs.inv(); }
    mint operator+() const { return *this; }
    mint operator-() const { return mint() - *this; }
    mint pow(long long n) const {
        assert(0 <= n);
        mint r = 1, x = *this;
        while (n) {
            if (n & 1) r *= x;
            x *= x;
            n >>= 1;
        }
        return r;
    }
    mint inv() const { assert(v); return pow(MOD - 2); }
    friend mint operator+(const mint& lhs, const mint& rhs) { return mint(lhs) += rhs; }
    friend mint operator-(const mint& lhs, const mint& rhs) { return mint(lhs) -= rhs; }
    friend mint operator*(const mint& lhs, const mint& rhs) { return mint(lhs) *= rhs; }
    friend mint operator/(const mint& lhs, const mint& rhs) { return mint(lhs) /= rhs; }
    friend bool operator==(const mint& lhs, const mint& rhs) { return (lhs.v == rhs.v); }
    friend bool operator!=(const mint& lhs, const mint& rhs) { return (lhs.v != rhs.v); }
    friend std::ostream& operator << (std::ostream &os, const mint& rhs) noexcept { return os << rhs.v; }
};
using mint = prime_modint<1000000007>;
//using mint = prime_modint<998244353>;

//enumeration<mint> enu(200000);のように宣言する
template<class T> struct enumeration{
    int N;
    vector<T> fact, inv;
    enumeration() : N(0), fact(1, 1), inv(1, 1) {}
    enumeration(int _n) : N(_n), fact(_n + 1), inv(_n + 1) {
        fact[0] = 1;
        for(int i = 1; i <= N; i++) fact[i] = fact[i - 1] * i;
        inv[N] = T(1) / fact[N];
        for(int i = N; i >= 1; i--) inv[i - 1] = inv[i] * i;
    }
    void expand(int lim){
        fact.resize(lim + 1);
        inv.resize(lim + 1);
        for(int i = N + 1; i <= lim; i++) fact[i] = i * fact[i - 1];
        inv[lim] = T(1) / fact[lim];
        for(int i = lim; i >= N + 2; i--) inv[i - 1] = i * inv[i];
        N = lim;
    }
    T Per(int n, int k){
        if(k > n) return 0;
        if(n > N) expand(n);
        return fact[n] * inv[n - k];
    }
    T C(int n, int k){
        if(n < 0 || k < 0 || k > n) return 0;
        if(n > N) expand(n);
        return fact[n] * inv[n - k] * inv[k];
    }
    T H(int n, int k){
        if(n ==0 && k == 0) return 1;
        if(n <= 0 || k < 0) return 0;
        return C(n + k - 1, k);
    }
};

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    enumeration<mint> enu(n + m + 1);
    mint ans;
    for(int i = 1; i <= m; i++){
        ans += (i & 1 ? -1 : 1) * enu.C(m, i) * mint(i).pow(n);
    }
    cout << ans << '\n';
}
0