Submission #50596739


Source Code Expand

import os
import sys
import gc
import heapq

sys.setrecursionlimit(210000)
gc.disable()


def debug(func):
    def wrapper(*args, **kwargs):
        if os.getenv('TEST'):
            return func(*args, **kwargs)
    return wrapper


@debug
def eprint(*args, **kwargs):
    print('[EPRINT]', *args, file=sys.stderr, **kwargs)


def main() -> None:
    N, M = map(int, input().split())
    schedules = [[] for _ in range(N)]
    for _ in range(M):
        L, D, K, C, A, B = map(int, input().split())
        schedules[B - 1].append((L, D, K, C, A - 1))

    departs = [-1 for _ in range(N)]
    queue = [(-10**20, N - 1)]
    heapq.heapify(queue)

    while len(queue) > 0:
        time, pos = heapq.heappop(queue)
        time = -time
        for schedule in schedules[pos]:
            l, d, k, c, a = schedule
            index = min((time - c - l) // d, k - 1)
            depart = l + index * d
            if depart < departs[a]:
                continue

            departs[a] = depart
            heapq.heappush(queue, (-depart, a))

    for depart in departs[:-1]:
        print(depart if depart > -1 else 'Unreachable')


if __name__ == '__main__':
    main()

Submission Info

Submission Time
Task E - Last Train
User takedarts
Language Python (PyPy 3.10-v7.3.12)
Score 450
Code Size 1179 Byte
Status AC
Exec Time 701 ms
Memory 145548 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 450 / 450
Status
AC × 3
AC × 33
Set Name Test Cases
Sample 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt
All 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 01_random_14.txt, 01_random_15.txt, 01_random_16.txt, 01_random_17.txt, 01_random_18.txt, 01_random_19.txt, 01_random_20.txt, 01_random_21.txt, 01_random_22.txt, 01_random_23.txt, 01_random_24.txt, 01_random_25.txt, 01_random_26.txt, 01_random_27.txt, 01_random_28.txt, 01_random_29.txt, 01_random_30.txt, 01_random_31.txt, 01_random_32.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 63 ms 76692 KiB
00_sample_01.txt AC 62 ms 76484 KiB
00_sample_02.txt AC 63 ms 76668 KiB
01_random_03.txt AC 680 ms 139932 KiB
01_random_04.txt AC 682 ms 139928 KiB
01_random_05.txt AC 701 ms 139732 KiB
01_random_06.txt AC 697 ms 139448 KiB
01_random_07.txt AC 694 ms 139812 KiB
01_random_08.txt AC 565 ms 136896 KiB
01_random_09.txt AC 576 ms 137188 KiB
01_random_10.txt AC 391 ms 133728 KiB
01_random_11.txt AC 387 ms 116336 KiB
01_random_12.txt AC 604 ms 132280 KiB
01_random_13.txt AC 332 ms 106300 KiB
01_random_14.txt AC 220 ms 95192 KiB
01_random_15.txt AC 202 ms 95404 KiB
01_random_16.txt AC 213 ms 108060 KiB
01_random_17.txt AC 379 ms 133752 KiB
01_random_18.txt AC 388 ms 133880 KiB
01_random_19.txt AC 387 ms 133792 KiB
01_random_20.txt AC 398 ms 133960 KiB
01_random_21.txt AC 391 ms 133664 KiB
01_random_22.txt AC 526 ms 118764 KiB
01_random_23.txt AC 283 ms 115056 KiB
01_random_24.txt AC 255 ms 113136 KiB
01_random_25.txt AC 594 ms 145548 KiB
01_random_26.txt AC 598 ms 145320 KiB
01_random_27.txt AC 587 ms 144636 KiB
01_random_28.txt AC 596 ms 144480 KiB
01_random_29.txt AC 95 ms 94064 KiB
01_random_30.txt AC 102 ms 85256 KiB
01_random_31.txt AC 160 ms 102776 KiB
01_random_32.txt AC 221 ms 120816 KiB