87712024-01-29 18:13:20NagyLeoKutyavetélkedőpython3Wrong answer 85/100694ms155168 KiB
def max_points(K, N, M, pairs):
    tricks = set(range(1, K + 1))
    can_do = {i: set() for i in range(1, 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
1Accepted17ms11444 KiB
2Accepted18ms11800 KiB
subtask20/15
3Accepted18ms11952 KiB
4Accepted17ms11616 KiB
5Accepted17ms12236 KiB
6Accepted17ms12176 KiB
7Wrong answer172ms26896 KiB
8Accepted171ms26976 KiB
9Accepted174ms27148 KiB
subtask319/19
10Accepted17ms12832 KiB
11Accepted17ms13248 KiB
12Accepted17ms13148 KiB
13Accepted17ms13228 KiB
14Accepted17ms13188 KiB
15Accepted17ms13340 KiB
16Accepted17ms13520 KiB
subtask434/34
17Accepted23ms14136 KiB
18Accepted28ms14732 KiB
19Accepted35ms16476 KiB
20Accepted37ms16644 KiB
21Accepted43ms17844 KiB
22Accepted43ms18484 KiB
subtask532/32
23Accepted261ms57224 KiB
24Accepted286ms66052 KiB
25Accepted317ms71136 KiB
26Accepted321ms76472 KiB
27Accepted330ms84120 KiB
28Accepted526ms88196 KiB
29Accepted694ms155168 KiB
30Accepted675ms155160 KiB
31Accepted458ms97580 KiB
32Accepted314ms54496 KiB
33Accepted561ms137648 KiB
34Accepted560ms137568 KiB