87732024-01-29 18:23:30NagyLeoKutyavetélkedőpython3Wrong answer 85/100610ms124184 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
        if T[i + 1] in can_do[T[i]]:
            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
1Accepted17ms11472 KiB
2Accepted18ms11684 KiB
subtask20/15
3Accepted17ms11776 KiB
4Accepted17ms12000 KiB
5Accepted17ms12116 KiB
6Accepted17ms12208 KiB
7Wrong answer175ms27092 KiB
8Accepted175ms27236 KiB
9Accepted168ms27184 KiB
subtask319/19
10Accepted18ms12684 KiB
11Accepted19ms13152 KiB
12Accepted18ms13260 KiB
13Accepted18ms13356 KiB
14Accepted17ms13344 KiB
15Accepted17ms13148 KiB
16Accepted17ms13308 KiB
subtask434/34
17Accepted21ms14400 KiB
18Accepted28ms15132 KiB
19Accepted35ms16636 KiB
20Accepted35ms16736 KiB
21Accepted41ms17920 KiB
22Accepted41ms18292 KiB
subtask532/32
23Accepted250ms53912 KiB
24Accepted268ms57868 KiB
25Accepted291ms62600 KiB
26Accepted296ms64784 KiB
27Accepted296ms68848 KiB
28Accepted490ms86716 KiB
29Accepted610ms123864 KiB
30Accepted606ms124184 KiB
31Accepted456ms81428 KiB
32Accepted298ms51744 KiB
33Accepted507ms107344 KiB
34Accepted507ms106908 KiB