結果

問題 No.845 最長の切符
ユーザー pekempeypekempey
提出日時 2019-06-29 19:57:42
言語 Ruby
(3.3.0)
結果
AC  
実行時間 2,179 ms / 3,000 ms
コード長 605 bytes
コンパイル時間 178 ms
コンパイル使用メモリ 11,416 KB
実行使用メモリ 23,676 KB
最終ジャッジ日時 2023-09-14 23:21:24
合計ジャッジ時間 15,170 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 78 ms
15,136 KB
testcase_01 AC 79 ms
15,144 KB
testcase_02 AC 86 ms
15,168 KB
testcase_03 AC 78 ms
15,056 KB
testcase_04 AC 77 ms
15,220 KB
testcase_05 AC 78 ms
15,356 KB
testcase_06 AC 79 ms
15,132 KB
testcase_07 AC 78 ms
15,308 KB
testcase_08 AC 85 ms
15,252 KB
testcase_09 AC 80 ms
15,140 KB
testcase_10 AC 113 ms
15,364 KB
testcase_11 AC 84 ms
15,292 KB
testcase_12 AC 92 ms
15,100 KB
testcase_13 AC 82 ms
15,032 KB
testcase_14 AC 90 ms
15,264 KB
testcase_15 AC 493 ms
17,180 KB
testcase_16 AC 2,166 ms
23,592 KB
testcase_17 AC 491 ms
17,192 KB
testcase_18 AC 1,000 ms
19,260 KB
testcase_19 AC 257 ms
16,032 KB
testcase_20 AC 2,167 ms
23,544 KB
testcase_21 AC 2,144 ms
23,504 KB
testcase_22 AC 483 ms
17,036 KB
testcase_23 AC 160 ms
15,764 KB
testcase_24 AC 2,179 ms
23,472 KB
testcase_25 AC 81 ms
15,268 KB
testcase_26 AC 249 ms
23,536 KB
testcase_27 AC 78 ms
15,240 KB
testcase_28 AC 290 ms
23,676 KB
testcase_29 AC 77 ms
15,076 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

def ints() gets.split.map(&:to_i) end
  
n, m = ints
$n = n

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<<n) * n)
def index(i, j) i * $n + j end
for i in 0...n
  dp[index(1 << i, i)] = 0
end

ans = -inf
for i in 0...1<<n
  for j in 0...n
    next if dp[index(i, j)] == -inf
    ans = [ans, dp[index(i, j)]].max
    for k in 0...n
      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