87742024-01-29 18:30:07NagyLeoKutyavetélkedőpypy3Wrong answer 85/100411ms190828 KiB
def max_points(K, N, M, pairs):
    can_do = [set() for i in range(K + 1)]
    for a, b in pairs:
        can_do[a].add(b)

    current_points = [0] * (N + 2)
    if T[N - 1] <= K:
        current_points[N - 1] = 1
    if T[N - 2] <= K:
        current_points[N - 2] = 1
        if T[N - 1] in can_do[T[N - 2]]:
            current_points[N - 2] = 2
    for i in range(N - 3, -1, -1):
        if T[i] > K:
            continue
        current_points[i] = 1
        if T[i + 1] in can_do[T[i]]:
            current_points[i] = max(current_points[i], 1 + current_points[i + 1])
        if T[i + 2] in can_do[T[i]]:
            current_points[i] = max(current_points[i], 1 + current_points[i + 2])

    return max(current_points[0], current_points[1])


N, K = map(int, input().split())
T = list(map(int, input().split()))
M = int(input())
pairs = [tuple(map(int, input().split())) for _ in range(M)]

print(max_points(K, N, M, pairs))
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted41ms77052 KiB
2Wrong answer39ms76868 KiB
subtask20/15
3Accepted41ms77196 KiB
4Accepted39ms77452 KiB
5Accepted46ms77540 KiB
6Accepted43ms78164 KiB
7Wrong answer104ms143864 KiB
8Accepted103ms144032 KiB
9Accepted119ms144416 KiB
subtask319/19
10Accepted43ms78636 KiB
11Accepted46ms78844 KiB
12Accepted43ms79156 KiB
13Accepted39ms79556 KiB
14Accepted39ms79580 KiB
15Accepted50ms79440 KiB
16Accepted48ms80480 KiB
subtask434/34
17Accepted103ms94300 KiB
18Accepted108ms94304 KiB
19Accepted120ms94740 KiB
20Accepted112ms95360 KiB
21Accepted112ms95980 KiB
22Accepted114ms95960 KiB
subtask532/32
23Accepted224ms122512 KiB
24Accepted211ms127816 KiB
25Accepted240ms134412 KiB
26Accepted252ms137912 KiB
27Accepted250ms138184 KiB
28Accepted303ms150616 KiB
29Accepted404ms190692 KiB
30Accepted411ms190828 KiB
31Accepted268ms159224 KiB
32Accepted210ms138136 KiB
33Accepted351ms176312 KiB
34Accepted351ms176052 KiB