結果

問題 No.117 組み合わせの数
ユーザー gigurururugigurururu
提出日時 2015-01-11 17:25:23
言語 Ruby
(3.3.0)
結果
WA  
実行時間 -
コード長 820 bytes
コンパイル時間 373 ms
コンパイル使用メモリ 11,360 KB
実行使用メモリ 46,792 KB
最終ジャッジ日時 2023-09-03 23:12:40
合計ジャッジ時間 7,562 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

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)
}
0