結果

問題 No.73 helloworld
ユーザー simansiman
提出日時 2016-03-26 03:21:11
言語 Ruby
(3.3.0)
結果
AC  
実行時間 87 ms / 5,000 ms
コード長 855 bytes
コンパイル時間 330 ms
コンパイル使用メモリ 11,556 KB
実行使用メモリ 15,372 KB
最終ジャッジ日時 2023-09-11 23:56:10
合計ジャッジ時間 2,738 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 85 ms
15,280 KB
testcase_01 AC 79 ms
15,248 KB
testcase_02 AC 79 ms
15,060 KB
testcase_03 AC 80 ms
15,164 KB
testcase_04 AC 87 ms
15,264 KB
testcase_05 AC 83 ms
15,092 KB
testcase_06 AC 83 ms
15,372 KB
testcase_07 AC 81 ms
15,196 KB
testcase_08 AC 82 ms
15,060 KB
testcase_09 AC 83 ms
15,260 KB
testcase_10 AC 83 ms
15,176 KB
testcase_11 AC 83 ms
15,284 KB
testcase_12 AC 81 ms
15,348 KB
testcase_13 AC 82 ms
15,292 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

class Integer
  def combination(k)
    self.factorial/(k.factorial*(self-k).factorial)
  end

  def permutation(k)
    self.factorial/(self-k).factorial
  end

  def factorial
    return 1 if self == 0
    (1..self).inject(:*)
  end
end

class Yukicoder
  def initialize
    hash = Hash.new(0)

    26.times do |i|
      hash[(97+i).chr] = gets.to_i
    end

    answer = 1

    %w(d e h l o r w).each do |ch|
      if ch == 'l'
        max_val = 0

        1.upto(hash[ch]-2) do |n|
          max_val = [max_val, (hash[ch]-n).combination(2) * n].max
        end

        answer *= max_val
      elsif ch == 'o'
        max_val = 0

        1.upto(hash[ch]-1) do |n|
          max_val = [max_val, (hash[ch]-n) * n].max
        end

        answer *= max_val
      else
        answer *= hash[ch]
      end
    end

    puts answer
  end
end

Yukicoder.new
0