結果

問題 No.19 ステージの選択
ユーザー szkhtsszkhts
提出日時 2021-04-08 12:50:37
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 382 ms / 5,000 ms
コード長 843 bytes
コンパイル時間 212 ms
コンパイル使用メモリ 10,928 KB
実行使用メモリ 8,312 KB
最終ジャッジ日時 2023-09-05 21:16:48
合計ジャッジ時間 3,629 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
7,804 KB
testcase_01 AC 16 ms
7,936 KB
testcase_02 AC 16 ms
7,828 KB
testcase_03 AC 17 ms
7,784 KB
testcase_04 AC 370 ms
8,312 KB
testcase_05 AC 115 ms
7,852 KB
testcase_06 AC 142 ms
7,856 KB
testcase_07 AC 222 ms
7,784 KB
testcase_08 AC 277 ms
7,804 KB
testcase_09 AC 382 ms
8,220 KB
testcase_10 AC 18 ms
7,896 KB
testcase_11 AC 16 ms
7,852 KB
testcase_12 AC 16 ms
7,836 KB
testcase_13 AC 15 ms
7,788 KB
testcase_14 AC 22 ms
7,904 KB
testcase_15 AC 31 ms
7,840 KB
testcase_16 AC 101 ms
7,856 KB
testcase_17 AC 26 ms
7,904 KB
testcase_18 AC 261 ms
7,896 KB
testcase_19 AC 42 ms
7,904 KB
testcase_20 AC 18 ms
7,908 KB
testcase_21 AC 82 ms
7,860 KB
testcase_22 AC 37 ms
7,844 KB
testcase_23 AC 72 ms
7,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N = int(input())
dist = [[False] * N for _ in range(N)]

level = [0] * N
stage = [0] * N
reg = 0
for i in range(N):
    l, s = map(int, input().split())
    level[i] = l
    stage[i] = s - 1
    dist[i][stage[i]] = True
    dist[i][i] = True

    reg += level[i]

for k in range(N):
    for i in range(N):
        for j in range(N):
            dist[i][j] = dist[i][j] | (dist[i][k] & dist[k][j])

for i in range(N):
    flag = True
    for j in range(i):
        if dist[i][j] and dist[j][i]:
            flag = False
    if not flag:
        continue

    for j in range(N):
        if dist[i][j] and not dist[j][i]:
            flag = False
    if not flag:
        continue

    mincost = 999
    for j in range(i, N):
        if dist[i][j] and dist[j][i]:
            mincost = min(mincost, level[j])

    reg += mincost

print(reg / 2)

0