結果

問題 No.391 CODING WAR
ユーザー mayoko_mayoko_
提出日時 2016-07-08 23:07:05
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 61 ms / 2,000 ms
コード長 1,623 bytes
コンパイル時間 950 ms
コンパイル使用メモリ 97,964 KB
実行使用メモリ 6,684 KB
最終ジャッジ日時 2023-08-03 09:07:34
合計ジャッジ時間 2,964 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
6,620 KB
testcase_01 AC 38 ms
6,500 KB
testcase_02 AC 38 ms
6,484 KB
testcase_03 AC 39 ms
6,568 KB
testcase_04 AC 38 ms
6,480 KB
testcase_05 AC 38 ms
6,548 KB
testcase_06 AC 38 ms
6,620 KB
testcase_07 AC 38 ms
6,672 KB
testcase_08 AC 38 ms
6,556 KB
testcase_09 AC 61 ms
6,476 KB
testcase_10 AC 59 ms
6,496 KB
testcase_11 AC 39 ms
6,500 KB
testcase_12 AC 38 ms
6,640 KB
testcase_13 AC 57 ms
6,492 KB
testcase_14 AC 54 ms
6,684 KB
testcase_15 AC 56 ms
6,500 KB
testcase_16 AC 49 ms
6,484 KB
testcase_17 AC 51 ms
6,560 KB
testcase_18 AC 47 ms
6,628 KB
testcase_19 AC 48 ms
6,636 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
//#include<cctype>
#include<climits>
#include<iostream>
#include<string>
#include<vector>
#include<map>
//#include<list>
#include<queue>
#include<deque>
#include<algorithm>
//#include<numeric>
#include<utility>
//#include<memory>
#include<functional>
#include<cassert>
#include<set>
#include<stack>
#include<random>

const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, -1, 0, 1};
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;

const int MOD = 1e9+7;

ll mod_pow(ll x, ll p, ll MOD) {
    ll a = 1;
    while (p) {
        if (p%2) a = a*x%MOD;
        x = x*x%MOD;
        p/=2;
    }
    return a;
}

// mod_inverse
ll mod_inverse(ll a, ll m) {
    return mod_pow(a, m-2, m);
}
const int MAXM = 100100;

int H[MAXM];
ll fact[2*MAXM], rfact[2*MAXM];

ll nCr(int n, int r) {
    ll ret = fact[n];
    (ret *= rfact[r]) %= MOD;
    (ret *= rfact[n-r]) %= MOD;
    return ret;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    fact[0] = rfact[0] = 1;
    for (int i = 1; i < 2*MAXM; i++) {
        fact[i] = (fact[i-1]*i)%MOD;
        rfact[i] = mod_inverse(fact[i], MOD);
    }

    ll N;
    int M;
    cin >> N >> M;
    if (N < M) {
        cout << 0 << endl;
        return 0;
    }
    ll ans = 0;
    for (int i = 1; i <= M; i++) {
        ll tmp = nCr(M, i) * mod_pow(i, N, MOD)%MOD; 
        if ((M-i)%2 == 0) ans += tmp;
        else ans -= tmp;
        ans = (ans+MOD)%MOD;
    }
    cout << ans << endl;
    return 0;
}
0