結果

問題 No.90 品物の並び替え
ユーザー shi-moshi-mo
提出日時 2016-03-30 12:26:11
言語 Ruby
(3.3.0)
結果
AC  
実行時間 1,859 ms / 5,000 ms
コード長 425 bytes
コンパイル時間 535 ms
コンパイル使用メモリ 7,424 KB
実行使用メモリ 13,312 KB
最終ジャッジ日時 2024-04-10 01:58:42
合計ジャッジ時間 3,846 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 83 ms
12,160 KB
testcase_01 AC 239 ms
12,288 KB
testcase_02 AC 79 ms
12,288 KB
testcase_03 AC 95 ms
12,288 KB
testcase_04 AC 94 ms
12,544 KB
testcase_05 AC 244 ms
12,416 KB
testcase_06 AC 238 ms
12,416 KB
testcase_07 AC 78 ms
12,416 KB
testcase_08 AC 78 ms
12,288 KB
testcase_09 AC 1,859 ms
13,312 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

n, m = gets.split.map(&:to_i)
score_table = Array.new(n){ Array.new(n, 0) }
m.times do
  i, j, s = gets.split.map(&:to_i)
  score_table[i][j] = s
end

def score(perm, score_table)
  s = 0
  perm.size.times do |j|
    j.times do |i|
      s += score_table[perm[i]][perm[j]]
    end
  end
  s
end

max_score = 0
(0..(n-1)).to_a.permutation do |perm|
  max_score = [ max_score, score(perm, score_table) ].max
end
puts max_score
0