22942023-01-09 20:05:43neszbalKarácsonyi égőkpython3Wrong answer 70/100331ms59592 KiB
N, C = map(int, input().strip().split())
L = list(map(int, input().strip().split()))

minTav = 2e5
nyilvantartoLista = [0 for i in range(C+1)]
mostTav = 0
mostTavRovidites = 0
benneVanSzam = 0

for i in range(N):
    while mostTav < N and benneVanSzam < C:
        
        if nyilvantartoLista[L[mostTav]] == 0:
            benneVanSzam += 1

        nyilvantartoLista[L[mostTav]] += 1
        mostTav += 1

    if benneVanSzam == C:
        minTav = min(minTav, mostTav - mostTavRovidites)

    while mostTavRovidites < mostTav and benneVanSzam == C:
        nyilvantartoLista[L[mostTavRovidites]] -= 1
        if nyilvantartoLista[L[mostTavRovidites]] == 0:
            benneVanSzam -= 1
        mostTavRovidites += 1
        if benneVanSzam == C:
            minTav = min(minTav, mostTav - mostTavRovidites)

print(minTav)


SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted18ms11136 KiB
2Accepted17ms11428 KiB
subtask215/15
3Accepted266ms17792 KiB
4Accepted273ms18024 KiB
5Accepted266ms18340 KiB
6Accepted18ms12136 KiB
7Accepted17ms12436 KiB
subtask310/10
8Accepted17ms12632 KiB
9Accepted17ms12492 KiB
10Accepted17ms12600 KiB
11Accepted17ms12828 KiB
12Accepted17ms12744 KiB
subtask420/20
13Accepted17ms12820 KiB
14Accepted17ms12956 KiB
15Accepted17ms13064 KiB
16Accepted17ms13296 KiB
17Accepted17ms13296 KiB
subtask525/25
18Accepted21ms14364 KiB
19Accepted24ms14280 KiB
20Accepted21ms14280 KiB
21Accepted24ms13800 KiB
22Accepted23ms13324 KiB
subtask60/30
23Wrong answer246ms57092 KiB
24Accepted216ms51648 KiB
25Accepted219ms57260 KiB
26Accepted238ms59516 KiB
27Accepted231ms59592 KiB
28Accepted226ms57084 KiB
29Accepted331ms52196 KiB
30Accepted214ms19892 KiB