結果

問題 No.391 CODING WAR
ユーザー FF256grhyFF256grhy
提出日時 2016-07-09 00:16:28
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 33 ms / 2,000 ms
コード長 776 bytes
コンパイル時間 440 ms
コンパイル使用メモリ 26,992 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-03 11:01:16
合計ジャッジ時間 1,487 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,384 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 33 ms
4,380 KB
testcase_10 AC 33 ms
4,380 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 29 ms
4,380 KB
testcase_14 AC 25 ms
4,380 KB
testcase_15 AC 27 ms
4,376 KB
testcase_16 AC 17 ms
4,380 KB
testcase_17 AC 20 ms
4,380 KB
testcase_18 AC 13 ms
4,380 KB
testcase_19 AC 14 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>

#define MOD 1000000007
typedef long long int LL;

LL inv(LL n) {
	LL ans = 1;
	int b = MOD - 2;
	
	while(b) {
		if(b % 2) { ans *= n; ans %= MOD; }
		n *= n; n %= MOD;
		b /= 2;
	}
	
	return ans;
}

LL pow_mod(LL a, LL b) {
	LL ans = 1;
	while(b) {
		if(b % 2) { ans *= a; ans %= MOD; }
		a *= a; a %= MOD;
		b /= 2;
	}
	
	return ans;
}

LL comb = 1;
LL comb_mod(LL a, LL b) {
	LL ans = comb;
	
	comb *= a - (b); comb %= MOD;
	comb *= inv(b + 1); comb %= MOD;
	
	return ans;
}

int main() {
	LL n, m;
	scanf("%lld%lld", &n, &m);
	
	LL ans = 0;
	if(n >= m) {
		for(LL i = 0; i < m; i++) {
			LL s = (i % 2 == 0 ? 1 : -1);
			ans += ( pow_mod(m - i, n) * comb_mod(m, i) % MOD * s + MOD ) % MOD;
			ans %= MOD;
		}
	}
	
	printf("%lld\n", ans);
	
	return 0;
}
0