Created
July 18, 2021 15:14
-
-
Save uchidama/7373ce496569d41bece2b812b2d69825 to your computer and use it in GitHub Desktop.
AtCoder Beginner Contest 210 [ C - Colorful Candies ] https://atcoder.jp/contests/abc210/tasks/abc210_c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
[問題] | |
https://atcoder.jp/contests/abc210/tasks/abc210_c | |
[解法] | |
しゃくとり法で解けた | |
[参考] | |
AtCoder Beginner Contest 032 [ C - 列 ]をPythonで解く。しゃくとり法をやってみる(💧水色diff) | |
https://uchidama.hatenablog.com/entry/2021/07/16/002834 | |
[結果] | |
PyPy3(7.3.0) AC 210ms | |
Python(3.8.2) AC 484ms | |
''' | |
import sys | |
from collections import defaultdict | |
sys.setrecursionlimit(10 ** 6) # 再帰上限の引き上げ | |
input = sys.stdin.readline | |
INF = 2 ** 63 - 1 | |
N, K = map(int, input().split()) | |
C = list(map(int, input().split())) | |
r, ans = 0, 0 | |
color = defaultdict(int) | |
for l in range(N): | |
while (r < N and r < (l + K)): | |
# 色の出現回数をdefaultdictに保存 | |
color[C[r]] += 1 | |
r += 1 | |
ans = max(ans, len(color)) | |
# lが1増えるので、先頭のcolorを削除 | |
color[C[l]] -= 1 | |
if color[C[l]] <= 0: | |
color.pop(C[l]) | |
print(ans) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment