Skip to content
This repository was archived by the owner on Feb 22, 2022. It is now read-only.

Commit 89b6477

Browse files
authored
Merge pull request #68 from boostcamp-ai-tech-4/penguin
[ํŽญ๊ท„] 2021.06.10
2 parents 97e1ea9 + d41c658 commit 89b6477

File tree

2 files changed

+53
-1
lines changed

2 files changed

+53
-1
lines changed

โ€Žcoodingpenguin/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,4 @@
5252
| 6/08 | <a href="https://www.acmicpc.net/problem/20291" target="_blank">20291</a> | <a href="https://www.acmicpc.net/problem/20291" target="_blank">ํŒŒ์ผ ์ •๋ฆฌ</a> | <img height="25px" width="25px" src="https://static.solved.ac/tier_small/7.svg"/> | โœ… | Counter ๋ฌธ์ œ์ง€๋งŒ defaultdict ์”€. |
5353
| 6/09 | <a href="https://www.acmicpc.net/problem/17413" target="_blank">17413</a> | <a href="https://www.acmicpc.net/problem/17413" target="_blank">๋‹จ์–ด ๋’ค์ง‘๊ธฐ 2</a> | <img height="25px" width="25px" src="https://static.solved.ac/tier_small/8.svg"/> | | |
5454
| 6/09 | <a href="https://www.acmicpc.net/problem/17609" target="_blank">17609</a> | <a href="https://www.acmicpc.net/problem/17609" target="_blank">ํšŒ๋ฌธ</a> | <img height="25px" width="25px" src="https://static.solved.ac/tier_small/10.svg"/> | | |
55-
| 6/10 | <a href="https://www.acmicpc.net/problem/20437" target="_blank">20437</a> | <a href="https://www.acmicpc.net/problem/20437" target="_blank">๋ฌธ์ž์—ด ๊ฒŒ์ž„ 2</a> | <img height="25px" width="25px" src="https://static.solved.ac/tier_small/11.svg"/> | | |
55+
| 6/10 | <a href="https://www.acmicpc.net/problem/20437" target="_blank">20437</a> | <a href="https://www.acmicpc.net/problem/20437" target="_blank">๋ฌธ์ž์—ด ๊ฒŒ์ž„ 2</a> | <img height="25px" width="25px" src="https://static.solved.ac/tier_small/11.svg"/> | โœ… | ์—ฐ์† ๋ฌธ์ž์—ด์˜ ๊ธธ์ด๋ฅผ ๊ตฌํ•˜๋Š” ๊ฒƒ์ด ๋ฌด์—‡์ธ์ง€๋ฅผ ํŒŒ์•…ํ•˜๋Š” ๋ฌธ์ œ |
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# ๋ฌธ์ œ: [BOJ 20437] ๋ฌธ์ž์—ด ๊ฒŒ์ž„2
2+
# ์œ ํ˜•: ๋”•์…”๋„ˆ๋ฆฌ
3+
# ๋ฉ”๋ชจ๋ฆฌ/์‹œ๊ฐ„: 32156kb / 240ms
4+
5+
import sys
6+
from collections import defaultdict
7+
8+
input = sys.stdin.readline
9+
10+
11+
def do_game():
12+
loc = defaultdict(list) # ๋ฌธ์ž์˜ ์œ„์น˜ ์ €์žฅ
13+
count = defaultdict(int) # ๋ฌธ์ž์˜ ๊ฐœ์ˆ˜ ์ €์žฅ
14+
15+
for idx, letter in enumerate(W):
16+
loc[letter].append(idx)
17+
count[letter] += 1
18+
19+
for k, v in count.items():
20+
# ์ •์ˆ˜ K๋ณด๋‹ค ์ž‘์œผ๋ฉด ์ œ์™ธ
21+
if v < K:
22+
del loc[k]
23+
24+
# ๋‚จ์€ ๋ฌธ์ž๊ฐ€ ์—†๋‹ค๋ฉด
25+
if not loc:
26+
return -1, -1
27+
28+
diff = [] # ์œ„์น˜ ๊ฐ„ ๊ฑฐ๋ฆฌ ๊ณ„์‚ฐ
29+
for k, l in loc.items():
30+
for i in range(len(l) - K + 1):
31+
diff.append(l[i + K - 1] - l[i] + 1)
32+
33+
# ์ตœ์†Œ ๊ธธ์ด์™€ ์ตœ๋Œ€ ๊ธธ์ด ๋ฐ˜ํ™˜
34+
return min(diff), max(diff)
35+
36+
37+
T = int(input()) # ํ…Œ์ŠคํŠธ ์ผ€์ด์Šค ๊ฐœ์ˆ˜
38+
for _ in range(T):
39+
W, K = input().rstrip(), int(input()) # ๋ฌธ์ž์—ด, ์ •์ˆ˜
40+
# ์ •์ˆ˜๊ฐ€ 1์ด๋ผ๋ฉด
41+
if K == 1:
42+
# ์—ฐ์† ๋ฌธ์ž์—ด ๊ธธ์ด ๋ชจ๋‘ 1
43+
print(1, 1)
44+
# ์ •์ˆ˜๊ฐ€ 1์ด ์•„๋‹ˆ๋ผ๋ฉด
45+
else:
46+
l1, l2 = do_game()
47+
# ์—ฐ์† ๋ฌธ์ž์—ด์ด ์—†๋Š” ๊ฒฝ์šฐ
48+
if l1 == -1:
49+
print(-1)
50+
# ์—ฐ์† ๋ฌธ์ž์—ด์ด ์žˆ๋Š” ๊ฒฝ์šฐ
51+
else:
52+
print(l1, l2)

0 commit comments

Comments
ย (0)