結果

問題 No.90 品物の並び替え
ユーザー DialBirdDialBird
提出日時 2017-02-26 11:49:33
言語 Ruby
(3.3.0)
結果
TLE  
実行時間 -
コード長 618 bytes
コンパイル時間 422 ms
コンパイル使用メモリ 11,264 KB
実行使用メモリ 21,268 KB
最終ジャッジ日時 2023-09-02 09:49:42
合計ジャッジ時間 10,386 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 81 ms
15,260 KB
testcase_01 AC 954 ms
15,852 KB
testcase_02 AC 81 ms
15,160 KB
testcase_03 AC 172 ms
16,112 KB
testcase_04 AC 172 ms
16,052 KB
testcase_05 AC 950 ms
15,904 KB
testcase_06 AC 941 ms
16,016 KB
testcase_07 AC 94 ms
15,368 KB
testcase_08 AC 83 ms
15,192 KB
testcase_09 TLE -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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|
      arr_cp = Marshal.load(Marshal.dump(@arr))
      sum = 0
      a.each do |i|
        sum += arr_cp[i].inject(:+)
        @n.times { |j| arr_cp[j][i] = 0 }
      end
      max = [sum, max].max
    end
    max
  end
end

puts Yukicoder.new.run
0