結果

問題 No.140 みんなで旅行
ユーザー cielciel
提出日時 2015-05-27 23:54:53
言語 Ruby
(3.3.0)
結果
AC  
実行時間 324 ms / 5,000 ms
コード長 414 bytes
コンパイル時間 87 ms
コンパイル使用メモリ 11,472 KB
実行使用メモリ 22,748 KB
最終ジャッジ日時 2023-09-20 16:58:18
合計ジャッジ時間 4,566 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 80 ms
15,344 KB
testcase_01 AC 80 ms
15,140 KB
testcase_02 AC 94 ms
15,988 KB
testcase_03 AC 85 ms
15,008 KB
testcase_04 AC 82 ms
15,296 KB
testcase_05 AC 82 ms
15,196 KB
testcase_06 AC 80 ms
15,232 KB
testcase_07 AC 82 ms
15,148 KB
testcase_08 AC 81 ms
15,212 KB
testcase_09 AC 80 ms
15,148 KB
testcase_10 AC 79 ms
15,276 KB
testcase_11 AC 321 ms
22,748 KB
testcase_12 AC 91 ms
15,620 KB
testcase_13 AC 84 ms
15,212 KB
testcase_14 AC 322 ms
22,732 KB
testcase_15 AC 324 ms
22,716 KB
testcase_16 AC 175 ms
18,144 KB
testcase_17 AC 127 ms
17,180 KB
testcase_18 AC 268 ms
20,972 KB
testcase_19 AC 287 ms
21,424 KB
testcase_20 AC 120 ms
16,992 KB
testcase_21 AC 82 ms
15,120 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

#!/usr/bin/ruby
N=gets.to_i
M=10**9+7
C,F,P=3.times.map{(N+2).times.map{[0]*(N+2)}}
(0..N).each{|x|
	C[x][0]=1
	F[x][1]=1
	(1..x).each{|y|
		C[x][y]=(C[x-1][y]+C[x-1][y-1])%M
	}
}
(1..N).each{|x|
	(2..x).each{|y|
		F[x][y]=(F[x-1][y-1]+y*F[x-1][y])%M
	}
}
(0..N).each{|x|
	P[x][0]=1
	(0..N).each{|y|
		P[x][y+1]=P[x][y]*x*~-x%M
	}
}
r=0
(1..N).each{|x|
	(1..N).each{|y|
		r=(r+C[N][x]*F[x][y]*P[y][N-x])%M
	}
}
p r
0