結果

問題 No.845 最長の切符
ユーザー pekempeypekempey
提出日時 2019-06-29 20:04:26
言語 Crystal
(1.11.2)
結果
AC  
実行時間 236 ms / 3,000 ms
コード長 612 bytes
コンパイル時間 17,350 ms
コンパイル使用メモリ 255,468 KB
実行使用メモリ 11,040 KB
最終ジャッジ日時 2023-09-13 10:06:40
合計ジャッジ時間 20,599 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
8,520 KB
testcase_01 AC 5 ms
8,648 KB
testcase_02 AC 6 ms
8,712 KB
testcase_03 AC 5 ms
8,640 KB
testcase_04 AC 5 ms
8,592 KB
testcase_05 AC 5 ms
8,500 KB
testcase_06 AC 5 ms
8,616 KB
testcase_07 AC 5 ms
8,572 KB
testcase_08 AC 6 ms
8,892 KB
testcase_09 AC 5 ms
8,592 KB
testcase_10 AC 10 ms
10,348 KB
testcase_11 AC 5 ms
8,876 KB
testcase_12 AC 8 ms
9,472 KB
testcase_13 AC 6 ms
8,736 KB
testcase_14 AC 5 ms
9,048 KB
testcase_15 AC 51 ms
10,336 KB
testcase_16 AC 236 ms
10,888 KB
testcase_17 AC 51 ms
10,872 KB
testcase_18 AC 107 ms
10,480 KB
testcase_19 AC 26 ms
10,348 KB
testcase_20 AC 235 ms
10,420 KB
testcase_21 AC 229 ms
10,364 KB
testcase_22 AC 52 ms
10,900 KB
testcase_23 AC 16 ms
10,960 KB
testcase_24 AC 234 ms
11,040 KB
testcase_25 AC 5 ms
8,496 KB
testcase_26 AC 8 ms
8,540 KB
testcase_27 AC 5 ms
8,604 KB
testcase_28 AC 14 ms
10,532 KB
testcase_29 AC 5 ms
8,452 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def ints() gets.not_nil!.split.map(&.to_i) end
  
n, m = ints

inf = 10**9
g = [-inf]*(n**2)
m.times do
  a, b, c = ints
  a -= 1
  b -= 1
  g[a*n+b] = [g[a*n+b], c].max
  g[b*n+a] = [g[b*n+a], c].max
end


dp = [-inf] * ((1<<16) * 16)
def index(i, j) i * 16 + j end

n.times do |i|
  dp[index(1 << i, i)] = 0
end

ans = -inf
(1<<n).times do |i|
  n.times do |j|
    next if dp[index(i, j)] == -inf
    ans = [ans, dp[index(i, j)]].max
    n.times do |k|
      if (i >> k & 1) == 0
        t = index(i | 1 << k, k)
        dp[t] = [dp[t], dp[index(i, j)] + g[j*n+k]].max
      end
    end
  end
end

puts ans



0