結果

問題 No.90 品物の並び替え
ユーザー DialBirdDialBird
提出日時 2017-02-26 14:17:58
言語 Ruby
(3.3.0)
結果
AC  
実行時間 3,196 ms / 5,000 ms
コード長 705 bytes
コンパイル時間 146 ms
コンパイル使用メモリ 11,460 KB
実行使用メモリ 15,780 KB
最終ジャッジ日時 2023-09-02 09:52:54
合計ジャッジ時間 5,831 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 79 ms
15,276 KB
testcase_01 AC 371 ms
15,500 KB
testcase_02 AC 80 ms
15,280 KB
testcase_03 AC 113 ms
15,356 KB
testcase_04 AC 109 ms
15,608 KB
testcase_05 AC 368 ms
15,780 KB
testcase_06 AC 372 ms
15,500 KB
testcase_07 AC 85 ms
15,528 KB
testcase_08 AC 79 ms
15,032 KB
testcase_09 AC 3,196 ms
15,624 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

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

  def run
    # 最大値
    max = 0    

    # 0〜@n-1で作る列の組み合わせを作成するO(n!)
    (0...@n).to_a.permutation(@n).each do |a|
      # # 9!でarrayを作成するのは厳しい
      # arr_cp = Marshal.load(Marshal.dump(@arr))
      sum = 0
      rest = (0...@n).to_a
      a.each do |i|
        rest.each do |j|
          sum += @arr[i][j]
        end
        rest -= [i]
      end
      max = [sum, max].max
    end
    max
  end
end

puts Yukicoder.new.run
0