Submission #24311709


Source Code Expand

n, k = map(int, input().split())
c = list(map(int, input().split()))

color = dict()
for i in range(k):
    if c[i] in color.keys():
        color[c[i]] += 1
    else:
        color[c[i]] = 1
res = len(color)
num = res

for j in range(k, n):
    if c[j] in color.keys() and color[c[j]] > 0:
        color[c[j]] += 1
    else:
        color[c[j]] = 1
        num += 1
    color[c[j - k]] -= 1
    if color[c[j - k]] == 0:
        num -=1
    res = max(res, num)

print(res)

Submission Info

Submission Time
Task C - Colorful Candies
User cubesat
Language PyPy3 (7.3.0)
Score 300
Code Size 495 Byte
Status AC
Exec Time 186 ms
Memory 148460 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 300 / 300
Status
AC × 3
AC × 24
Set Name Test Cases
Sample example0.txt, example1.txt, example2.txt
All 000.txt, 001.txt, 002.txt, 003.txt, 004.txt, 005.txt, 006.txt, 007.txt, 008.txt, 009.txt, 010.txt, 011.txt, 012.txt, 013.txt, 014.txt, 015.txt, 016.txt, 017.txt, 018.txt, 019.txt, 020.txt, example0.txt, example1.txt, example2.txt
Case Name Status Exec Time Memory
000.txt AC 61 ms 61788 KiB
001.txt AC 181 ms 148460 KiB
002.txt AC 184 ms 130956 KiB
003.txt AC 146 ms 117128 KiB
004.txt AC 142 ms 117384 KiB
005.txt AC 171 ms 148384 KiB
006.txt AC 167 ms 130912 KiB
007.txt AC 135 ms 117260 KiB
008.txt AC 185 ms 120328 KiB
009.txt AC 180 ms 117980 KiB
010.txt AC 186 ms 122872 KiB
011.txt AC 186 ms 117792 KiB
012.txt AC 149 ms 117244 KiB
013.txt AC 150 ms 117260 KiB
014.txt AC 143 ms 117388 KiB
015.txt AC 146 ms 117384 KiB
016.txt AC 115 ms 101344 KiB
017.txt AC 115 ms 99624 KiB
018.txt AC 115 ms 94648 KiB
019.txt AC 130 ms 101668 KiB
020.txt AC 152 ms 120396 KiB
example0.txt AC 52 ms 61692 KiB
example1.txt AC 53 ms 61772 KiB
example2.txt AC 49 ms 61776 KiB