結果

問題 No.1035 Color Box
ユーザー 里旬里旬
提出日時 2020-04-24 21:40:11
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 11 ms / 2,000 ms
コード長 3,040 bytes
コンパイル時間 1,979 ms
コンパイル使用メモリ 198,752 KB
実行使用メモリ 5,156 KB
最終ジャッジ日時 2023-08-05 04:42:00
合計ジャッジ時間 3,492 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 11 ms
4,944 KB
testcase_01 AC 3 ms
4,992 KB
testcase_02 AC 4 ms
4,860 KB
testcase_03 AC 4 ms
4,908 KB
testcase_04 AC 4 ms
4,872 KB
testcase_05 AC 3 ms
5,152 KB
testcase_06 AC 4 ms
5,092 KB
testcase_07 AC 4 ms
5,060 KB
testcase_08 AC 10 ms
5,088 KB
testcase_09 AC 6 ms
4,960 KB
testcase_10 AC 4 ms
4,920 KB
testcase_11 AC 3 ms
4,868 KB
testcase_12 AC 3 ms
5,128 KB
testcase_13 AC 9 ms
4,964 KB
testcase_14 AC 9 ms
4,940 KB
testcase_15 AC 11 ms
5,048 KB
testcase_16 AC 3 ms
4,916 KB
testcase_17 AC 4 ms
5,156 KB
testcase_18 AC 4 ms
5,088 KB
testcase_19 AC 11 ms
5,144 KB
testcase_20 AC 3 ms
4,908 KB
testcase_21 AC 4 ms
4,904 KB
testcase_22 AC 3 ms
4,852 KB
testcase_23 AC 3 ms
4,920 KB
testcase_24 AC 4 ms
4,908 KB
testcase_25 AC 3 ms
4,920 KB
testcase_26 AC 4 ms
5,060 KB
testcase_27 AC 3 ms
4,980 KB
testcase_28 AC 3 ms
5,144 KB
testcase_29 AC 4 ms
4,988 KB
testcase_30 AC 4 ms
4,944 KB
testcase_31 AC 4 ms
5,080 KB
testcase_32 AC 4 ms
4,988 KB
testcase_33 AC 3 ms
4,868 KB
testcase_34 AC 3 ms
4,892 KB
testcase_35 AC 3 ms
4,964 KB
testcase_36 AC 3 ms
4,988 KB
testcase_37 AC 3 ms
4,908 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
constexpr int64_t mod = 1000000007;

template <uint32_t mod>
class modint{
    uint64_t value;
public:
    constexpr modint(const int64_t x=0) noexcept: value(x % mod + (x < 0 ? mod : 0)){ }
    constexpr explicit operator uint64_t() const noexcept{ return value; }
    constexpr modint inverse() const noexcept{ return pow(*this, mod-2); }
    constexpr bool operator==(const modint &rhs) const noexcept{ return value == rhs.value; }
    constexpr bool operator!=(const modint &rhs) const noexcept{ return value != rhs.value; }
    constexpr modint operator+() const noexcept{ return modint(*this); }
    constexpr modint operator-() const noexcept{ return modint(mod - value); }
    constexpr modint operator+(const modint &rhs) const noexcept{ return modint(*this) += rhs; }
    constexpr modint operator-(const modint &rhs) const noexcept{ return modint(*this) -= rhs; }
    constexpr modint operator*(const modint &rhs) const noexcept{ return modint(*this) *= rhs; }
    constexpr modint operator/(const modint &rhs) const noexcept{ return modint(*this) /= rhs; }
    constexpr modint &operator+=(const modint &rhs) noexcept{
        if((value += rhs.value) >= mod) value -= mod;
        return *this;
    }
    constexpr modint &operator-=(const modint &rhs) noexcept{ return *this += mod - rhs.value; }
    constexpr modint &operator*=(const modint &rhs) noexcept{
        if((value *= rhs.value) >= mod) value %= mod;
        return *this;
    }
    constexpr modint &operator/=(const modint &rhs) noexcept{ return *this *= rhs.inverse(); }
    constexpr modint operator++(int) noexcept{
        modint ret(*this);
        if((++value) >= mod) value -= mod;
        return ret;
    }
    constexpr modint operator--(int) noexcept{
        modint ret(*this);
        if((value += mod - 1) >= mod) value -= mod;
        return ret;
    }
    constexpr modint &operator++() noexcept{ return *this += 1; }
    constexpr modint &operator--() noexcept{ return *this -= 1; }
    friend std::ostream &operator<<(std::ostream &os, const modint<mod> &x){ return os << x.value; }
    friend std::istream &operator>>(std::istream &is, modint<mod> &x){
        int64_t i;
        is >> i;
        x = modint<mod>(i);
        return is;
    }
    friend constexpr modint<mod> pow(const modint<mod> &x, uint64_t y){
        modint<mod> ret{1}, m{x};
        while(y > 0){
            if(y & 1) ret *= m;
            m *= m;
            y >>= 1;
        }
        return ret;
    }
};

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    int n, m;
    cin >> n >> m;    
    static modint<mod> fact[100001], finv[100001];
    fact[0] = 1;
    for(int i=1;i<=100000;++i) fact[i] = fact[i-1] * i;
    finv[100000] = fact[100000].inverse();
    for(int i=100000;i>0;--i) finv[i-1] = finv[i] * i;

    modint<mod> ans = 0;
    for(int i=0;i<=m;++i) ans += modint<mod>{(i&1)?-1:1} * pow(modint<mod>(m-i), n) * fact[m] * finv[m-i] * finv[i];
    cout << ans << endl;
    
    return 0;
}
0