結果
| 問題 |
No.117 組み合わせの数
|
| ユーザー |
|
| 提出日時 | 2015-01-11 17:25:23 |
| 言語 | Ruby (3.4.1) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 820 bytes |
| コンパイル時間 | 151 ms |
| コンパイル使用メモリ | 7,680 KB |
| 実行使用メモリ | 47,872 KB |
| 最終ジャッジ日時 | 2024-06-13 03:47:29 |
| 合計ジャッジ時間 | 7,555 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | WA * 1 |
コンパイルメッセージ
Syntax OK
ソースコード
def memo
m = []
lambda {|arg1,arg2|
(m.size..arg1).each{|i|m << yield(i,arg2)}
(arg1<0)?yield(arg1,arg2):m[arg1]
}
end
Inv = memo{|m,mod|
case
when m>1 then ((mod-mod/m)*Inv[mod%m,mod])%mod
else 1
end
}
Fact = memo{|m,mod|
case
when m>0 then (m*Fact[m-1,mod])%mod
else 1
end
}
Factr = memo{|m,mod|
case
when m>0 then (Inv[m,mod]*Factr[m-1,mod])%mod
when m==0 then 1
else 0
end
}
def combination_len(n,r,mod);Fact[n,mod]*Factr[r,mod]%mod*Factr[n-r,mod]%mod;end
def repeated_combination_len(n,r,mod);combination_len(n+r-1,r,mod);end
def permutation_len(n,r,mod);Fact[n,mod]*Factr[n-r,mod]%mod;end
MOD = 1000000007
m=Hash[?C,:combination_len,?P,:permutation_len,?H,:repeated_combination_len]
gets.to_i.times{
a,b,c = gets.split(/\(|\)|,/)
p send(m[a],b.to_i,c.to_i,1000000007)
}