結果

問題 No.90 品物の並び替え
ユーザー DialBirdDialBird
提出日時 2017-02-28 20:38:17
言語 Ruby
(3.3.0)
結果
AC  
実行時間 86 ms / 5,000 ms
コード長 505 bytes
コンパイル時間 587 ms
コンパイル使用メモリ 11,584 KB
実行使用メモリ 15,372 KB
最終ジャッジ日時 2023-09-02 18:04:22
合計ジャッジ時間 2,079 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
15,156 KB
testcase_01 AC 77 ms
15,144 KB
testcase_02 AC 75 ms
15,068 KB
testcase_03 AC 77 ms
15,196 KB
testcase_04 AC 77 ms
15,372 KB
testcase_05 AC 77 ms
15,148 KB
testcase_06 AC 76 ms
15,268 KB
testcase_07 AC 73 ms
15,300 KB
testcase_08 AC 72 ms
15,196 KB
testcase_09 AC 86 ms
15,204 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

class Yukicoder
  def initialize
    @n, m = gets.chomp.split.map(&:to_i)
    @points = {}
    m.times do
      a, b, c = gets.chomp.split.map(&:to_i)
      @points[[a, b]] = c
    end
    @dp = {}
  end

  def run
    return solve([], [*0...@n])
  end

  private

  def solve(done, rest)
    @dp[rest.sort!] ||= rest.map do |i|
      sum = 0
      done.each do |j|
        sum += @points[[i, j]] || 0
      end
      sum += solve(done + [i], rest - [i])
    end.max || 0
  end
end

puts Yukicoder.new.run
0