提出 #14109675


ソースコード 拡げる

# K - Moving Containers
import sys

read = sys.stdin.buffer.read


def main():
    N, Q, *FTX = map(int, read().split())

    desk = list(range(N + 1))  # desk[i] := the top of desk_i
    container = [0] * (N + 1)  # container[i] := the underneath of container_i
    for f, t, x in zip(*[iter(FTX)] * 3):
        desk[f], desk[t], container[x] = container[x], desk[f], desk[t]

    position = [0] * (N + 1)  # position[i] := final position of container_i
    for i, cur in enumerate(desk):
        while cur:
            position[cur] = i
            cur = container[cur]

    print("\n".join(map(str, position[1:])))


if __name__ == "__main__":
    main()

提出情報

提出日時
問題 K - コンテナの移動
ユーザ solzard
言語 Python (3.8.2)
得点 6
コード長 683 Byte
結果 AC
実行時間 284 ms
メモリ 70700 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 6 / 6
結果
AC × 2
AC × 20
セット名 テストケース
Sample sample_01.txt, sample_02.txt
All hand2_01.txt, hand2_02.txt, hand_01.txt, hand_02.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, sample_01.txt, sample_02.txt
ケース名 結果 実行時間 メモリ
hand2_01.txt AC 257 ms 70700 KiB
hand2_02.txt AC 259 ms 70360 KiB
hand_01.txt AC 182 ms 70500 KiB
hand_02.txt AC 183 ms 70368 KiB
random_01.txt AC 81 ms 32388 KiB
random_02.txt AC 63 ms 27188 KiB
random_03.txt AC 87 ms 27856 KiB
random_04.txt AC 40 ms 16908 KiB
random_05.txt AC 43 ms 18876 KiB
random_06.txt AC 39 ms 16300 KiB
random_07.txt AC 83 ms 32836 KiB
random_08.txt AC 98 ms 36308 KiB
random_09.txt AC 86 ms 28076 KiB
random_10.txt AC 71 ms 24524 KiB
random_11.txt AC 284 ms 70388 KiB
random_12.txt AC 278 ms 70384 KiB
random_13.txt AC 155 ms 70112 KiB
random_14.txt AC 155 ms 70112 KiB
sample_01.txt AC 18 ms 9016 KiB
sample_02.txt AC 20 ms 8908 KiB