結果

問題 No.391 CODING WAR
ユーザー bond_cmprogbond_cmprog
提出日時 2020-01-17 20:27:08
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 53 ms / 2,000 ms
コード長 2,527 bytes
コンパイル時間 1,629 ms
コンパイル使用メモリ 169,736 KB
実行使用メモリ 29,588 KB
最終ジャッジ日時 2023-09-07 22:27:23
合計ジャッジ時間 3,643 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 50 ms
29,364 KB
testcase_01 AC 50 ms
29,376 KB
testcase_02 AC 48 ms
29,376 KB
testcase_03 AC 47 ms
29,428 KB
testcase_04 AC 41 ms
29,460 KB
testcase_05 AC 37 ms
29,412 KB
testcase_06 AC 35 ms
29,432 KB
testcase_07 AC 35 ms
29,500 KB
testcase_08 AC 36 ms
29,444 KB
testcase_09 AC 53 ms
29,420 KB
testcase_10 AC 51 ms
29,364 KB
testcase_11 AC 43 ms
29,364 KB
testcase_12 AC 36 ms
29,364 KB
testcase_13 AC 50 ms
29,448 KB
testcase_14 AC 48 ms
29,588 KB
testcase_15 AC 51 ms
29,360 KB
testcase_16 AC 46 ms
29,380 KB
testcase_17 AC 44 ms
29,364 KB
testcase_18 AC 44 ms
29,424 KB
testcase_19 AC 44 ms
29,416 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())
#define ll long long
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;
//typedef vector<unsigned int>vec;
//typedef vector<ll>vec;
//typedef vector<vec> mat;
typedef vector<vector<int>> Graph;

const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const ll LINF = 1000000000000000000;//1e18
const ll  MOD = 1000000007;
const double PI = acos(-1.0);
const double EPS = 1e-10;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};

vector<pair<long long, long long> > prime_factorize(long long n) {
    vector<pair<long long, long long> > res;
    for (long long p = 2; p * p <= n; ++p) {
        if (n % p != 0) continue;
        int num = 0;
        while (n % p == 0) { ++num; n /= p; }
        res.push_back(make_pair(p, num));//p^num
    }
    if (n != 1) res.push_back(make_pair(n, 1));
    return res;
}

const int MAX = 1110000;
long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void comb_init() {
    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 comb(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;
}

ll mod_pow(ll x, ll n, ll mod){
    ll res = 1;
    while(n > 0){
        if(n & 1) res = res * x % mod;//最下位ビットが立っているときにx^(2^i)をかける
        x = x * x % mod; //xを順次二乗していく
        n >>= 1;
    }
    return res;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, m;
    cin >> n >> m;
    comb_init();
    ll ans = 0;
    for(int k=0;k<=m;k++){
        ll tmp = comb(m, k) * mod_pow(m - k, n, MOD);
        tmp %= MOD;
        if(k % 2 == 0) ans += tmp;
        else{
            ans -= tmp;
            ans += MOD;
        }
        ans %= MOD;
    }
    cout << ans << endl;
}
0