Problem p02868 (python)

Fixed submission:
from heapq import heappush, heappop
import sys
input = sys.stdin.readline


def dijkstra(graph: list, node: int, start: int) -> list:
    # graph[node] = [(cost, to)]
    INF = float('inf')
    dist = [INF] * node

    dist[start] = 0
    heap = [(0, start)]
    while heap:
        cost, thisNode = heappop(heap)
        for NextCost, NextNode in graph[thisNode]:
            dist_cand = dist[thisNode] + NextCost
            if dist_cand < dist[NextNode]:
                dist[NextNode] = dist_cand
                heappush(heap, (dist[NextNode], NextNode))
    return dist
    # dist = [costs to nodes]


n, m = map(int, input().split())
edge = [[] for _ in range(n)]
for _ in range(m):
    l, r, c = map(int, input().split())
    l -= 1
    r -= 1
    edge[l].append((c, r))
for i in range(1, n):
    edge[i].append((0, i - 1))

dist = dijkstra(edge, n, 0)
ans = dist[-1] if dist[-1] != float("inf") else -1

print(ans)

Buggy submission (verdict: Runtime Error):
from collections import defaultdict
MOD = 998244353

n = int(input())
d = list(map(int, input().split()))

cnt = defaultdict(int)
m = 0
for i in range(n):
    cnt[d[i]] += 1
    m = max(d[i], m)

if d[0] != 0 or cnt[0] != 1:
    ans = 0
else:
    ans = 1
    for i in range(1, m + 1):
        ans *= cnt[i - 1]**cnt[i]
        ans %= MOD

print(ans)

Buggy submission (verdict: Runtime Error):
from collections import defaultdict
MOD = 998244353

n = int(input())
d = list(map(int, input().split()))

cnt = defaultdict(int)
m = 0
for i in range(n):
    cnt[d[i]] += 1
    m = max(d[i], m)

if d[0] != 0 or dd[0] != 1:
    ans = 0
else:
    ans = 1
    for i in range(1, m + 1):
        ans *= cnt[i - 1]**cnt[i]
        ans %= MOD

print(ans)

Buggy submission (verdict: Runtime Error):
from heapq import heappush, heappop

n, m = map(int, input().split())
edge = [list(map(int, input().split())) for _ in range(m)]
edge.sort(key=lambda x: (x[1], x[0]))

q = [(1, 0)]
for l, r, c in edge:
    # print((l, r, c), q)

    if r < q[0][0]:
        continue

    cand = float("inf")
    while q:
        y, z = heappop(q)
        if y >= l:
            heappush(q, (y, z))
            break

    for y, z in q:
        if y < r:
            cand = min(cand, z)
        else:
            heappush(q, (y, z))
            break

    if cand != float("inf"):
        heappush(q, (r, cand + c))

# print(q)

ans = -1
for y, z in q:
    if y == n:
        if ans == -1:
            ans = z
        else:
            ans = min(ans, z)

print(ans)

Buggy submission (verdict: Runtime Error):
from heapq import heappush, heappop

n, m = map(int, input().split())
edge = [list(map(int, input().split())) for _ in range(m)]
edge.sort(key=lambda x: (x[1], x[0]))

q = [(1, 0)]
for l, r, c in edge:
    # print((l, r, c), q)

    if r < q[0][0]:
        continue

    cand = float("inf")
    while q:
        y, z = heappop(q)
        if y >= l:
            heappush(q, (y, z))
            break

    for y, z in q:
        if y < r:
            cand = min(cand, z)
        else:
            heappush(q, (y, z))
            break

    if cand != float("inf"):
        heappush(q, (r, cand + c))

# print(q)

ans = -1
for y, z in q:
    if y == n:
        if ans == -1:
            ans = z
        else:
            ans = min(ans, z)

print(ans)