結果

問題 No.17 2つの地点に泊まりたい
ユーザー 6soukiti296soukiti29
提出日時 2017-07-26 16:13:02
言語 Nim
(2.0.2)
結果
AC  
実行時間 6 ms / 5,000 ms
コード長 1,040 bytes
コンパイル時間 3,029 ms
コンパイル使用メモリ 68,604 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-12 13:36:31
合計ジャッジ時間 4,274 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 4 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 4 ms
4,376 KB
testcase_06 AC 4 ms
4,376 KB
testcase_07 AC 3 ms
4,376 KB
testcase_08 AC 5 ms
4,380 KB
testcase_09 AC 6 ms
4,376 KB
testcase_10 AC 3 ms
4,380 KB
testcase_11 AC 5 ms
4,380 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 4 ms
4,376 KB
testcase_19 AC 4 ms
4,380 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 4 ms
4,380 KB
testcase_23 AC 4 ms
4,380 KB
testcase_24 AC 4 ms
4,376 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 5 ms
4,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
/home/judge/data/code/Main.nim(1, 26) Warning: imported and not used: 'math' [UnusedImport]

ソースコード

diff #

import sequtils,strutils,math
var
    N = stdin.readline.parseInt
    S = newSeq[int](0)
    A,B,C : int
    mcos : int
    ans = high(int)
    table : array[50,array[50,int]]
    
for n in 0..<N:
    S.add(stdin.readline.parseInt)
for i in 0..<N:
    for j in 0..<N:
        table[i][j] = 100000
var M = stdin.readline.parseInt
for m in 0..<M:
    (A,B,C) = stdin.readline.split.map(parseInt)
    table[A][B] = C
    table[B][A] = C
var flag = true
while flag:
    flag = false
    for i in 0..<N:
        for j in 0..<N:
            for k in 0..<N:
                if table[i][j] > table[i][k] + table[k][j]:
                    flag = true
                    table[i][j] = table[i][k] + table[k][j]
for i in 1..N - 2:
    for j in 1..N - 2:
        if i == j:
            continue
        mcos = min(@[table[0][i] + table[i][j] + table[j][N - 1],
            table[0][N - 1] + table[N - 1][i] * 2 + table[N - 1][j] * 2,
            table[0][i] + table[i][N - 1] + table[N - 1][j] * 2])
        ans = min(ans,mcos + S[i] + S[j])
echo ans
0