結果

問題 No.90 品物の並び替え
ユーザー Naoki_M_Naoki_M_
提出日時 2016-09-06 15:20:09
言語 Ruby
(3.3.0)
結果
AC  
実行時間 949 ms / 5,000 ms
コード長 499 bytes
コンパイル時間 62 ms
コンパイル使用メモリ 7,424 KB
実行使用メモリ 12,416 KB
最終ジャッジ日時 2024-04-27 16:45:37
合計ジャッジ時間 2,677 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 80 ms
12,416 KB
testcase_01 AC 163 ms
12,288 KB
testcase_02 AC 77 ms
12,288 KB
testcase_03 AC 89 ms
12,416 KB
testcase_04 AC 91 ms
12,288 KB
testcase_05 AC 167 ms
12,288 KB
testcase_06 AC 165 ms
12,416 KB
testcase_07 AC 81 ms
12,032 KB
testcase_08 AC 79 ms
12,032 KB
testcase_09 AC 949 ms
12,288 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

n, m = gets.chomp.split.map(&:to_i)
ss = Array.new(n){Array.new(n, 0)}
ans = 0
m.times do
  i1, i2, s = gets.chomp.split.map(&:to_i)
  ss[i1][i2] = s
end

(0...n - 1).to_a.permutation do |ps|
  ps << n - 1
  tmp = 0
  for i in 0...n - 1
    for j in i + 1...n
      tmp += ss[ps[i]][ps[j]]
    end
  end
  ans = [ans, tmp].max
  for i in 0...n - 1
    for j in 1...n
      tmp -= ss[ps[i]][ps[(i + j) % n]]
      tmp += ss[ps[(i + j) % n]][ps[i]]
    end
    ans = [ans, tmp].max
  end
end

puts ans
0