結果

問題 No.845 最長の切符
ユーザー 6soukiti296soukiti29
提出日時 2019-06-29 00:07:58
言語 Nim
(2.0.2)
結果
AC  
実行時間 78 ms / 3,000 ms
コード長 1,043 bytes
コンパイル時間 3,512 ms
コンパイル使用メモリ 67,996 KB
実行使用メモリ 11,308 KB
最終ジャッジ日時 2023-09-14 22:49:15
合計ジャッジ時間 5,305 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,088 KB
testcase_01 AC 2 ms
5,020 KB
testcase_02 AC 3 ms
7,228 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
5,164 KB
testcase_05 AC 2 ms
5,064 KB
testcase_06 AC 2 ms
4,996 KB
testcase_07 AC 2 ms
5,160 KB
testcase_08 AC 4 ms
7,248 KB
testcase_09 AC 3 ms
5,104 KB
testcase_10 AC 4 ms
7,332 KB
testcase_11 AC 2 ms
5,004 KB
testcase_12 AC 3 ms
7,176 KB
testcase_13 AC 3 ms
5,044 KB
testcase_14 AC 3 ms
7,152 KB
testcase_15 AC 18 ms
9,664 KB
testcase_16 AC 70 ms
11,188 KB
testcase_17 AC 18 ms
9,836 KB
testcase_18 AC 34 ms
10,212 KB
testcase_19 AC 9 ms
9,456 KB
testcase_20 AC 74 ms
11,236 KB
testcase_21 AC 78 ms
11,308 KB
testcase_22 AC 17 ms
9,668 KB
testcase_23 AC 6 ms
7,400 KB
testcase_24 AC 70 ms
11,240 KB
testcase_25 AC 1 ms
4,380 KB
testcase_26 AC 45 ms
9,736 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 56 ms
11,216 KB
testcase_29 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
/home/judge/data/code/Main.nim(1, 26) Warning: imported and not used: 'algorithm' [UnusedImport]

ソースコード

diff #

import sequtils,strutils,algorithm
var
    N, M, a, b, c: int
    hyou : array[16, array[16, int]]
    s : int
    ans : int
    dp : array[16, array[(1 shl 16), int]]
(N, M) = stdin.readline.split.map(parseInt)

for i in 0..<N:
    for j in 0..<N:
        hyou[i][j] = -100000000
for i in 0..<M:
    (a, b, c) = stdin.readline.split.map(parseInt)
    a -= 1
    b -= 1
    hyou[a][b] = max(hyou[a][b], c)
    hyou[b][a] = max(hyou[b][a], c)
    
for B in 0..<(1 shl N):
    for s in 0..<N:
        if B == 0:
            for k in 0..<N:
                var nb = ((1 shl s) or (1 shl k))
                dp[s][nb] = hyou[s][k]
                dp[k][nb] = hyou[k][s]
                ans = max(ans, hyou[s][k])
        if (B and (1 shl s)) > 0:
            for k in 0..<N:
                if (B and (1 shl k)) > 0:
                    continue
                var nb = ((1 shl k) or B)
                if hyou[s][k] > 0:
                    dp[k][nb] = max(dp[k][nb], dp[s][B] + hyou[s][k])
                    ans = max(dp[k][nb], ans)
echo ans
0