結果

問題 No.168 ものさし
ユーザー 6soukiti296soukiti29
提出日時 2017-10-19 22:37:44
言語 Nim
(2.0.2)
結果
WA  
実行時間 -
コード長 2,539 bytes
コンパイル時間 3,412 ms
コンパイル使用メモリ 68,144 KB
実行使用メモリ 13,660 KB
最終ジャッジ日時 2023-09-12 15:19:07
合計ジャッジ時間 4,834 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 21 ms
9,348 KB
testcase_01 WA -
testcase_02 AC 2 ms
5,480 KB
testcase_03 AC 2 ms
5,480 KB
testcase_04 AC 3 ms
5,448 KB
testcase_05 WA -
testcase_06 AC 3 ms
5,404 KB
testcase_07 AC 2 ms
5,388 KB
testcase_08 WA -
testcase_09 AC 4 ms
5,956 KB
testcase_10 AC 6 ms
6,236 KB
testcase_11 AC 19 ms
9,464 KB
testcase_12 AC 49 ms
13,472 KB
testcase_13 AC 67 ms
13,488 KB
testcase_14 AC 61 ms
11,596 KB
testcase_15 AC 2 ms
5,552 KB
testcase_16 AC 3 ms
5,832 KB
testcase_17 AC 4 ms
6,064 KB
testcase_18 AC 6 ms
6,664 KB
testcase_19 AC 60 ms
13,540 KB
testcase_20 AC 62 ms
13,464 KB
testcase_21 AC 66 ms
13,660 KB
testcase_22 AC 63 ms
13,492 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
/home/judge/data/code/Main.nim(24, 25) Warning: Number of spaces around '<=' is not consistent [Spacing]

ソースコード

diff #

import sequtils,strutils,math
type
    priorityQue[I:static[int];T:tuple] = array[I + 1,T]
    item = tuple[cost: int,ID : int]

proc push[T](A:var priorityQue; b: T;)=
    const key = 0
    A[0][0] += 1
    A[A[0][0]] = b # A[0][0]はsize、最大のIndex
    var index = A[0][0]
    while index > 1 and A[index][key] > A[index div 2][key]:
        (A[index],A[index div 2]) = (A[index div 2],A[index])
        index = index div 2

proc pop(A: var priorityQue):item =
    const key = 0
    result = A[1]
    A[1] = A[A[0][0]]
    var a : item
    A[A[0][0]] = a
    A[0][0] -= 1
    var index = 1
    while index * 2 <= A[0][0]:
        if index * 2 + 1<= A[0][0]:
            if A[index][key] < A[index * 2][key] and A[index * 2 + 1][key] <= A[index * 2][key]:
                (A[index],A[index * 2]) = (A[index * 2],A[index])
                index = index * 2
            elif A[index][key] < A[index * 2 + 1][key]:
                (A[index],A[index * 2 + 1]) = (A[index * 2 + 1],A[index])
                index = index * 2 + 1
            else:
                break
        elif index * 2 <= A[0][0]:
            if A[index][key] < A[index * 2][key]:
                (A[index],A[index * 2]) = (A[index * 2],A[index])
            break
        else:
            break

proc size(A : priorityQue):int=
    return A[0][0]

var
    pq : priorityQue[1_000_001, item]
    t : item
    N = stdin.readline.parseInt
    x, y : int
    nodes = newSeq[array[2, int]](0)
    mincos : array[1000, int]
    hyou : array[1000, array[1000, int]]
    flag : array[1000, bool]
    
for n in 0..<N:
    (x, y) = stdin.readline.split.map(parseInt)
    for i in 0..<n:
        var
            r : float64
            a = abs(nodes[i][0] - x).float64
            b = abs(nodes[i][1] - y).float64
            l : int
        if a < b:
            (a, b) = (b, a)
        if a == 0:
            r = 0
        else:
            r = a * sqrt(1 + (b / a) * (b / a))
        if r * r < b * b + a * a:
            r += 0.0000001
        r = r / 10
        r = round(r + 1e-12, 10).ceil
        l = r.int * 10
        hyou[n][i] = l
        hyou[i][n] = l
    nodes.add([x, y])
    mincos[n] = int.high

pq.push((0, 0))
mincos[0] = 0
while pq.size > 0:
    t = pq.pop
    flag[t.ID] = true
    if t.ID == N - 1:
        break
    for i,c in hyou[t.ID]:
        if flag[i]:
            continue
        if mincos[i] > max(hyou[i][t.ID], mincos[t.ID]):
            mincos[i] = max(hyou[i][t.ID], mincos[t.ID])
            pq.push(( -mincos[i], i))
echo mincos[N - 1]
0