結果

問題 No.1035 Color Box
ユーザー ShibuyapShibuyap
提出日時 2020-04-25 08:50:55
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,443 bytes
コンパイル時間 2,168 ms
コンパイル使用メモリ 195,548 KB
実行使用メモリ 15,616 KB
最終ジャッジ日時 2024-04-24 07:43:28
合計ジャッジ時間 3,414 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
#define yn {puts("Yes");}else{puts("No");}
#define MAX_N 200005

const int MAX = 510000;
const int MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

long long FINV(int n){
    if (n < 0) return 0;
    return finv[n];
}

ll mod_pow(ll x, ll n, ll mod){ // x ^ n % mod
    ll res = 1;
    while(n > 0){
        if (n & 1) res = res * x % mod;
        x = x * x % mod;
        n >>= 1;
    }
    return res;
}

int main() {
    // 前処理
    COMinit();
    int n, m;
    cin >> n >> m;
    ll ans = 0;

    ll flag = 1;
    for(int i = m; i >= 1; i--){
        ll tmp = COM(m, i) * mod_pow(i, n, MOD) % MOD;
        ans += flag * tmp;
        ans %= MOD;
        flag *= -1;
    }

    cout << ans << endl;
    return 0;
}
0