結果

問題 No.391 CODING WAR
ユーザー FF256grhyFF256grhy
提出日時 2016-07-09 00:03:10
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 789 bytes
コンパイル時間 266 ms
コンパイル使用メモリ 23,680 KB
実行使用メモリ 10,624 KB
最終ジャッジ日時 2024-04-21 08:49:47
合計ジャッジ時間 3,777 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 0 ms
10,624 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 0 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 7 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 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:43:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   43 |         scanf("%lld%lld", &n, &m);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~

ソースコード

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_mod(LL a, LL b) {
	LL ans = 1;
	
	for(int i = 0; i < b; i++) {
		ans *= a - i; ans %= MOD;
		ans *= inv(b - i); ans %= 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