結果

問題 No.1035 Color Box
ユーザー nrvftnrvft
提出日時 2020-04-25 05:50:24
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 25 ms / 2,000 ms
コード長 2,328 bytes
コンパイル時間 2,092 ms
コンパイル使用メモリ 196,464 KB
実行使用メモリ 6,016 KB
最終ジャッジ日時 2024-04-23 19:35:20
合計ジャッジ時間 3,976 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 25 ms
5,760 KB
testcase_01 AC 17 ms
6,016 KB
testcase_02 AC 18 ms
5,760 KB
testcase_03 AC 18 ms
6,016 KB
testcase_04 AC 18 ms
5,888 KB
testcase_05 AC 17 ms
5,888 KB
testcase_06 AC 18 ms
6,016 KB
testcase_07 AC 18 ms
5,888 KB
testcase_08 AC 24 ms
5,888 KB
testcase_09 AC 21 ms
6,016 KB
testcase_10 AC 17 ms
5,760 KB
testcase_11 AC 17 ms
6,016 KB
testcase_12 AC 18 ms
5,888 KB
testcase_13 AC 22 ms
6,016 KB
testcase_14 AC 24 ms
5,888 KB
testcase_15 AC 25 ms
6,016 KB
testcase_16 AC 17 ms
6,016 KB
testcase_17 AC 17 ms
6,016 KB
testcase_18 AC 18 ms
6,016 KB
testcase_19 AC 25 ms
6,016 KB
testcase_20 AC 17 ms
6,016 KB
testcase_21 AC 17 ms
6,016 KB
testcase_22 AC 17 ms
6,016 KB
testcase_23 AC 17 ms
5,888 KB
testcase_24 AC 18 ms
6,016 KB
testcase_25 AC 18 ms
6,016 KB
testcase_26 AC 17 ms
5,760 KB
testcase_27 AC 17 ms
6,016 KB
testcase_28 AC 17 ms
5,888 KB
testcase_29 AC 18 ms
6,016 KB
testcase_30 AC 18 ms
6,016 KB
testcase_31 AC 18 ms
5,888 KB
testcase_32 AC 18 ms
5,888 KB
testcase_33 AC 18 ms
6,016 KB
testcase_34 AC 17 ms
5,888 KB
testcase_35 AC 18 ms
5,760 KB
testcase_36 AC 18 ms
6,016 KB
testcase_37 AC 18 ms
5,888 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)
#define repa(i,n) for (auto& i: n)

template<class T> inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}

#ifdef DEBUG
template <class T, class N> void verr(const T& a, const N& n) { rep(i, n) cerr << a[i] << " "; cerr << "\n" << flush; }
ll dbgt = 1; void err() { cerr << "passed " << dbgt++ << "\n" << flush; }
template<class H, class... T> void err(H&& h,T&&... t){ cerr<< h << (sizeof...(t)?" ":"\n") << flush; if(sizeof...(t)>0) err(forward<T>(t)...); }
#endif

const ll INF = 5e18;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
//--------------------------------------------------------------------------------//
ll modpow(ll a, ll n, ll mod_) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod_;
        a = a * a % mod_;
        n >>= 1;
    }
    return res;
}

const ll MAX_SIZE = 100005;
array<ll, MAX_SIZE> fac, inv, finv;
void fac_init() {
    // combination init
    fac[0] = 1;
    for (ll i = 1; i < MAX_SIZE; i++) fac[i] = fac[i - 1] * i % MOD;
    finv[0] = modpow(fac[MAX_SIZE - 1], MOD - 2, MOD);
    repe(i, 1, MAX_SIZE) finv[i] = finv[i - 1] * (MAX_SIZE - i) % MOD;
    reverse(all(finv));

    //inv init
    repe(i, 1, MAX_SIZE) inv[i] = modpow(i, MOD - 2, MOD);
}

ll perm(ll a, ll b) { return fac[a] * finv[a - b] % MOD; }

ll comb(ll a, ll b) { return fac[a] * finv[b] % MOD * finv[a - b] % MOD; }

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

    ll ans = 0;
    rep(i,M+1){
        ans += comb(M, i) * modpow(M - i, N, MOD) % MOD * (i % 2 ? -1 : 1);
    }
    cout << (ans + MOD * MOD) % MOD << endl;
}
0