結果

問題 No.468 役に立つ競技プログラミング実践編
ユーザー maspymaspy
提出日時 2020-03-19 23:08:20
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 1,644 ms / 2,000 ms
コード長 1,020 bytes
コンパイル時間 79 ms
コンパイル使用メモリ 10,932 KB
実行使用メモリ 136,824 KB
最終ジャッジ日時 2023-08-20 21:14:03
合計ジャッジ時間 18,549 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 18 ms
8,136 KB
testcase_01 AC 17 ms
8,148 KB
testcase_02 AC 18 ms
8,252 KB
testcase_03 AC 17 ms
8,456 KB
testcase_04 AC 16 ms
8,252 KB
testcase_05 AC 17 ms
8,412 KB
testcase_06 AC 16 ms
8,376 KB
testcase_07 AC 16 ms
8,432 KB
testcase_08 AC 17 ms
8,248 KB
testcase_09 AC 17 ms
8,220 KB
testcase_10 AC 17 ms
8,292 KB
testcase_11 AC 16 ms
8,240 KB
testcase_12 AC 18 ms
8,452 KB
testcase_13 AC 17 ms
8,212 KB
testcase_14 AC 25 ms
9,484 KB
testcase_15 AC 25 ms
9,592 KB
testcase_16 AC 26 ms
9,472 KB
testcase_17 AC 26 ms
9,392 KB
testcase_18 AC 26 ms
9,460 KB
testcase_19 AC 26 ms
9,460 KB
testcase_20 AC 26 ms
9,476 KB
testcase_21 AC 25 ms
9,440 KB
testcase_22 AC 26 ms
9,380 KB
testcase_23 AC 25 ms
9,464 KB
testcase_24 AC 1,449 ms
136,408 KB
testcase_25 AC 1,491 ms
136,584 KB
testcase_26 AC 1,486 ms
136,688 KB
testcase_27 AC 1,447 ms
136,824 KB
testcase_28 AC 1,443 ms
136,296 KB
testcase_29 AC 1,443 ms
136,732 KB
testcase_30 AC 1,422 ms
136,772 KB
testcase_31 AC 1,419 ms
136,360 KB
testcase_32 AC 1,644 ms
136,364 KB
testcase_33 AC 1,465 ms
136,308 KB
testcase_34 AC 455 ms
64,220 KB
testcase_35 AC 20 ms
8,488 KB
testcase_36 AC 17 ms
8,408 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/ python3.8
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N, M = map(int, readline().split())
m = map(int, read().split())
ABC = zip(m, m, m)

graph = [[] for _ in range(N)]
graph_rev = [[] for _ in range(N)]
in_deg = [0] * N
for a, b, c in ABC:
    graph[a].append((b, c))
    graph_rev[b].append((a, c))
    in_deg[b] += 1

deg_0 = [i for i, x in enumerate(in_deg) if not x]
order = []
while deg_0:
    v = deg_0.pop()
    order.append(v)
    for w, _ in graph[v]:
        in_deg[w] -= 1
        if in_deg[w] == 0:
            deg_0.append(w)

dp1 = [0] * N
for v in order:
    dv = dp1[v]
    for w, c in graph[v]:
        dw = dv + c
        if dp1[w] < dw:
            dp1[w] = dw
dp2 = [0] * N
for v in order[::-1]:
    dv = dp2[v]
    for w, c in graph_rev[v]:
        dw = dv + c
        if dp2[w] < dw:
            dp2[w] = dw

T = dp1[-1]
dp2 = [T - x for x in dp2]
P = sum(x < y for x, y in zip(dp1, dp2))
print(f'{T} {P}/{N}')
0