結果

問題 No.391 CODING WAR
ユーザー TawaraTawara
提出日時 2015-12-29 23:05:45
言語 Ruby
(3.3.0)
結果
AC  
実行時間 633 ms / 2,000 ms
コード長 397 bytes
コンパイル時間 178 ms
コンパイル使用メモリ 11,420 KB
実行使用メモリ 18,688 KB
最終ジャッジ日時 2023-08-27 06:09:31
合計ジャッジ時間 7,114 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 83 ms
14,976 KB
testcase_01 AC 83 ms
15,100 KB
testcase_02 AC 85 ms
15,156 KB
testcase_03 AC 83 ms
15,164 KB
testcase_04 AC 82 ms
15,112 KB
testcase_05 AC 84 ms
15,116 KB
testcase_06 AC 83 ms
15,112 KB
testcase_07 AC 88 ms
15,160 KB
testcase_08 AC 86 ms
15,228 KB
testcase_09 AC 633 ms
18,580 KB
testcase_10 AC 567 ms
18,656 KB
testcase_11 AC 418 ms
18,660 KB
testcase_12 AC 85 ms
15,088 KB
testcase_13 AC 576 ms
18,688 KB
testcase_14 AC 488 ms
17,920 KB
testcase_15 AC 541 ms
18,392 KB
testcase_16 AC 360 ms
16,564 KB
testcase_17 AC 415 ms
17,668 KB
testcase_18 AC 309 ms
16,468 KB
testcase_19 AC 314 ms
16,408 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

P = 10**9+7
def pow(b,e)
	ret = 1
	while e > 0
		if (e&1) == 1 then
			ret = ret * b % P
		end
		b = b * b % P
		e>>=1
	end
	return ret
end
N,M = gets.split().map{|s| s.to_i}
f = [0]*(M+1)
fi = [0]*(M+1)
f[0] = 1
(1..M).each{|i| f[i] = i*f[i-1]%P}
fi[M] = pow(f[M],P-2)
(1..M).reverse_each{|i| fi[i-1] = i*fi[i]%P}
p (0..M-1).map{|k| f[M]*fi[k]*fi[M-k]*pow(M-k,N)*((-1)**(k%2)) % P}.inject(:+) % P
0