87702024-01-29 18:11:25NagyLeoKutyavetélkedőpypy3Wrong answer 85/100458ms201724 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
1Accepted48ms76716 KiB
2Accepted45ms77112 KiB
subtask20/15
3Accepted46ms77036 KiB
4Accepted43ms77376 KiB
5Accepted39ms77988 KiB
6Accepted46ms77988 KiB
7Wrong answer122ms143516 KiB
8Accepted123ms144576 KiB
9Accepted109ms144228 KiB
subtask319/19
10Accepted39ms79036 KiB
11Accepted39ms79448 KiB
12Accepted46ms78940 KiB
13Accepted46ms79104 KiB
14Accepted43ms79280 KiB
15Accepted46ms79056 KiB
16Accepted45ms79992 KiB
subtask434/34
17Accepted92ms94036 KiB
18Accepted98ms93916 KiB
19Accepted98ms94040 KiB
20Accepted100ms94720 KiB
21Accepted103ms95224 KiB
22Accepted104ms94892 KiB
subtask532/32
23Accepted223ms123792 KiB
24Accepted232ms131756 KiB
25Accepted232ms137176 KiB
26Accepted240ms141744 KiB
27Accepted245ms149868 KiB
28Accepted312ms148340 KiB
29Accepted451ms201724 KiB
30Accepted458ms200940 KiB
31Accepted291ms169368 KiB
32Accepted197ms137448 KiB
33Accepted344ms187880 KiB
34Accepted338ms189888 KiB