Baekjoon #15961

Baekjoon #15961

1개의 풀이 · Python

문제 원문 보기 ↗

SOLUTION INFO

Python · main.py

main.py
import sys

def input():
    return sys.stdin.readline().rstrip()

def answer(line, max_seq, coupon):

    count = 0
    for i in range(max_seq):
        food_number = line[i]
        if not eat[food_number]:
            count += 1
        eat[food_number] += 1

    max_count = count
    for i in range(1, n):
        if max_count <= count:
            if not eat[coupon]:
                max_count = count + 1
            else:
                max_count = count

        out = i - 1
        eat[line[out]] -= 1
        if not eat[line[out]]:
            count -= 1
            
        in_ = (i + max_seq - 1) % n
        if not eat[line[in_]]:
            count += 1
        eat[line[in_]] += 1

    return max_count

n, f_kind, max_seq, coupon = map(int, input().split())
line = [int(input()) for _ in range(n)]
eat = [0 for _ in range(3000001)]
print(answer(line, max_seq, coupon))

SOLUTION DESCRIPTION

풀이 설명

등록된 풀이 설명이 없습니다.