結果

問題 No.391 CODING WAR
ユーザー 🍡yurahuna🍡yurahuna
提出日時 2016-07-08 23:27:21
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,255 bytes
コンパイル時間 1,915 ms
コンパイル使用メモリ 163,828 KB
実行使用メモリ 10,752 KB
最終ジャッジ日時 2024-04-21 08:23:51
合計ジャッジ時間 5,562 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
10,752 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 6 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 8 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 TLE -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define int long long   // <-----!!!!!!!!!!!!!!!!!!!

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()

typedef long long ll;
typedef pair<int, int> Pii;
typedef tuple<int, int, int> TUPLE;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;
typedef vector<vector<int>> Graph;
const int inf = 1e9;
const int mod = 1e9 + 7;

ll powmod (ll a, ll p) {
	ll ans = 1ll;
	ll mul = a;
	for (; p > 0ll; p >>= 1ll, mul = (mul * mul) % mod) {
		if ((p & 1ll) == 1ll) ans = (ans * mul) % mod;
	}
	return ans;
}

ll getRev(ll x) {
	return powmod(x, mod - 2ll);
}

int C(int n, int k) {
    int ret = 1ll;
    for (int i = n; i > n - k; i--) {
        (ret *= i) %= mod;
    }
    for (int i = k; i >= 1ll; i--) {
        (ret *= getRev(i)) %= mod;
    }
    return ret;
}

signed main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);

	int N, M;
	cin >> N >> M;
	int ans = 0;
	for (int x = M; x > 0; x--) {
		ans += ((M - x) % 2 ? -1 : 1) * C(M, x) * powmod(x, N);
		ans %= mod;
	}

	cout << (ans + mod) % mod << endl;
}
0