23762023-01-11 23:04:54kristofKarácsonyi égőkpython3Accepted 100/100347ms60080 KiB
N, C = map(int, input().strip().split())
L = list(map(int, input().strip().split()))

minTav = N
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
1Accepted17ms11952 KiB
2Accepted17ms12232 KiB
subtask215/15
3Accepted261ms18752 KiB
4Accepted270ms19004 KiB
5Accepted263ms19136 KiB
6Accepted17ms12472 KiB
7Accepted17ms12976 KiB
subtask310/10
8Accepted17ms12872 KiB
9Accepted17ms12984 KiB
10Accepted17ms13228 KiB
11Accepted17ms13200 KiB
12Accepted17ms13336 KiB
subtask420/20
13Accepted17ms13596 KiB
14Accepted17ms13712 KiB
15Accepted17ms13780 KiB
16Accepted17ms13972 KiB
17Accepted17ms14140 KiB
subtask525/25
18Accepted21ms15380 KiB
19Accepted24ms15220 KiB
20Accepted23ms15100 KiB
21Accepted25ms14904 KiB
22Accepted24ms14400 KiB
subtask630/30
23Accepted246ms58040 KiB
24Accepted223ms52120 KiB
25Accepted224ms57820 KiB
26Accepted243ms60008 KiB
27Accepted231ms60080 KiB
28Accepted216ms57888 KiB
29Accepted347ms53092 KiB
30Accepted214ms21052 KiB