結果

問題 No.90 品物の並び替え
ユーザー Naoki_M_
提出日時 2016-09-06 15:20:09
言語 Ruby
(3.4.1)
結果
AC  
実行時間 1,022 ms / 5,000 ms
コード長 499 bytes
コンパイル時間 463 ms
コンパイル使用メモリ 7,168 KB
実行使用メモリ 12,416 KB
最終ジャッジ日時 2024-11-15 20:34:27
合計ジャッジ時間 3,097 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 9
権限があれば一括ダウンロードができます
コンパイルメッセージ
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