16472번: 고냥이
고양이는 너무 귀엽다. 사람들은 고양이를 너무 귀여워했고, 결국 고양이와 더욱 가까워지고 싶어 고양이와의 소통을 위한 고양이 말 번역기를 발명하기로 했다. 이 번역기는 사람의 언어를 고
www.acmicpc.net
코드
n = int(input())
cat = input()
alphabets = set()
partial = ""
ans = -1
for c in cat:
if len(alphabets) < n:
alphabets.add(c)
partial += c
else:
if c in alphabets:
partial += c
else:
idx = -1
partial_set = set()
for i in range(len(partial)-1, -1, -1):
if len(partial_set) < n-1:
partial_set.add(partial[i])
elif len(partial_set) == n-1 and partial[i] not in partial_set:
idx = i+1
break
alphabets = partial_set
partial = partial[idx:]+c
alphabets.add(c)
ans = max(ans, len(partial))
print(ans)
'문제풀이 > 구현' 카테고리의 다른 글
[Python/파이썬] 백준 1652번 누울 자리를 찾아라 (0) | 2024.03.12 |
---|---|
[Python/파이썬] 백준 6986번 절사평균 (0) | 2024.03.02 |
[Python/파이썬] 백준 2490번 윷놀이 (0) | 2024.02.22 |
[Python/파이썬] 백준 3005번 크로스워드 퍼즐 쳐다보기 (0) | 2024.02.05 |
[Python/파이썬] 백준 5766번 할아버지는 유명해! (0) | 2024.01.20 |