結果

問題 No.1035 Color Box
ユーザー tomatoma
提出日時 2020-04-24 22:31:37
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 3,590 bytes
コンパイル時間 2,271 ms
コンパイル使用メモリ 169,068 KB
実行使用メモリ 6,476 KB
最終ジャッジ日時 2023-08-05 05:25:05
合計ジャッジ時間 3,172 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 14 ms
6,308 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 7 ms
6,144 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 14 ms
6,296 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 7 ms
6,192 KB
testcase_12 WA -
testcase_13 AC 11 ms
6,336 KB
testcase_14 AC 13 ms
6,144 KB
testcase_15 AC 14 ms
6,244 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 14 ms
6,280 KB
testcase_20 WA -
testcase_21 AC 7 ms
6,144 KB
testcase_22 AC 7 ms
6,196 KB
testcase_23 AC 7 ms
6,140 KB
testcase_24 AC 6 ms
6,152 KB
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 7 ms
6,196 KB
testcase_29 AC 7 ms
6,472 KB
testcase_30 WA -
testcase_31 AC 7 ms
6,148 KB
testcase_32 AC 6 ms
6,308 KB
testcase_33 AC 7 ms
6,144 KB
testcase_34 AC 6 ms
6,264 KB
testcase_35 WA -
testcase_36 WA -
testcase_37 AC 7 ms
6,304 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include"bits/stdc++.h"
using namespace std;
#define REP(k,m,n) for(int (k)=(m);(k)<(n);(k)++)
#define rep(i,n) REP((i),0,(n))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using tp3 = tuple<int, int, int>;
using Mat = vector<vector<ll>>;
constexpr int INF = 1 << 28;
constexpr ll INFL = 1ll << 60;
constexpr int dh[4] = { 0,1,0,-1 };
constexpr int dw[4] = { -1,0,1,0 };
bool isin(const int H, const int W, const int h, const int w) {
    return 0 <= h && h < H && 0 <= w && w < W;
}
template<typename T>
T minch(T& l, T r) {
    return l = min(l, r);
}
template<typename T>
T maxch(T& l, T r) {
    return l = max(l, r);
}
template<typename T>
void output(const T& val) {
    cout << val << endl;
}
template<typename T>
void output(const vector<T>& vec, const bool newline = false) {
    for (const T& val : vec)cout << val << (newline ? '\n' : ' '); cout << endl;
}
template<typename T>
void output(const vector<vector<T>>& mat) {
    for (const auto& row : mat)output(row);
}
struct ModInt {
    static const ll MOD = 1000000007;

    // constructors etc
    ModInt() :num(1ll) {}
    ModInt(ll num_) :num(num_%MOD) {}
    ModInt(const ModInt& modint) :num(modint.num%MOD) {}
    ll get()const { return num; }

    // operator etc
    // operator ll() const { return num; }
    // ll operator*() { return num; }
    ModInt& operator+=(const ModInt& r) { (num += r.num) %= MOD; return *this; }
    ModInt& operator-=(const ModInt& r) { (num += -r.num + MOD) %= MOD; return *this; }
    ModInt& operator*=(const ModInt& r) { (num *= r.num) %= MOD; return *this; }
    ModInt& operator/=(const ModInt& r) { (num *= r.inv().num) %= MOD; return *this; }
    ModInt pow(const ModInt& r)const {
        ll res = 1;
        ll x = num;
        ll n = r.num;
        while (n > 0) {
            if (n & 1)res = (res*x) % MOD;
            x = (x*x) % MOD;
            n >>= 1;
        }
        return res;
    }
    ModInt inv()const { return this->pow(MOD - 2); }

    ModInt operator+(const ModInt& r)const { return ModInt(*this) += r; }
    ModInt operator-(const ModInt& r)const { return ModInt(*this) -= r; }
    ModInt operator*(const ModInt& r)const { return ModInt(*this) *= r; }
    ModInt operator/(const ModInt& r)const { return ModInt(*this) /= r; }
    ModInt operator+(const ll& r)const { return *this + ModInt(r); }
    ModInt operator-(const ll& r)const { return *this - ModInt(r); }
    ModInt operator*(const ll& r)const { return *this * ModInt(r); }
    ModInt operator/(const ll& r)const { return *this / ModInt(r); }

private:
    ll num;
};
ostream& operator<<(ostream& stream, const ModInt& val) { stream << val.get(); return stream; }

struct Comb {
    static constexpr ll LIM = 200000;
    static vector<ModInt> fact, inv;

    static void init() {
        fact.resize(LIM, 1);
        inv.resize(LIM, 1);

        REP(i, 1, LIM)fact[i] = fact[i - 1] * i;
        inv[LIM - 1] = fact[LIM - 1].inv();
        for (ll i = LIM - 2; i > 0; i--)inv[i] = inv[i + 1] * (i + 1);
    }

    static ll comb(ll n, ll k) {
        if (n < k)return 0ll;
        return (fact[n] * inv[k] * inv[n - k]).get();
    }
};
vector<ModInt> Comb::fact;
vector<ModInt> Comb::inv;

// ============ template finished ============

int main()
{
    ll N, M;
    cin >> N >> M;

    Comb::init();
    ModInt res(0);
    rep(i, M + 1) {
        bool inv = (M - i) % 2 == 1;
        ModInt tres = Comb::comb(M, i);
        if (i) tres *= ModInt(i).pow(N);
        if (inv)res -= tres;
        else res += tres;
    }
    res = res - 1;
    output(res);
    return 0;
}
0