Skip to content

Commit 8e247e1

Browse files
committed
solve: 20437 문자열 게임 2
1 parent a012626 commit 8e247e1

File tree

3 files changed

+100
-1
lines changed

3 files changed

+100
-1
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
2+
"""
3+
문제 이름: 문자열 게임 2
4+
문제 번호: 20437
5+
문제 링크: https://www.acmicpc.net/problem/20437
6+
난이도: Gold V
7+
태그: 슬라이딩 윈도우, 문자열
8+
"""
9+
import sys
10+
from collections import defaultdict
11+
12+
13+
def input(): return sys.stdin.readline().rstrip()
14+
15+
16+
for _ in range(int(input())):
17+
chars = defaultdict(list)
18+
alphabet_count = [-1]*26
19+
20+
text = input()
21+
K = int(input())
22+
23+
# 전처리
24+
for idx, c in enumerate(text):
25+
m = ord(c)-ord('a')
26+
if alphabet_count[m] < 0:
27+
alphabet_count[m] = text.count(c)
28+
count = alphabet_count[m]
29+
30+
if K <= count:
31+
chars[c].append(idx)
32+
# -
33+
_min, _max = 10000, 0
34+
for x in chars.values():
35+
for i in range(len(x)-K+1):
36+
# 0+k-1 2,
37+
current_length = x[i+K-1] - x[i] + 1
38+
_min = min(_min, current_length)
39+
_max = max(_max, current_length)
40+
41+
if len(chars) > 0:
42+
print(_min, _max)
43+
else:
44+
print("-1")
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
---
2+
file: "20437.md"
3+
name: "문자열 게임 2"
4+
src: "https://www.acmicpc.net/problem/20437"
5+
tags:
6+
- 슬라이딩 윈도우
7+
- 문자열
8+
done: true
9+
draft: false
10+
level: 11
11+
difficulty: "Gold V"
12+
date: 2021-11-06
13+
---
14+
15+
# 문자열 게임 2
16+
17+
```python
18+
import sys
19+
from collections import defaultdict
20+
21+
22+
def input(): return sys.stdin.readline().rstrip()
23+
24+
25+
for _ in range(int(input())):
26+
chars = defaultdict(list)
27+
alphabet_count = [-1]*26
28+
29+
text = input()
30+
K = int(input())
31+
32+
# 전처리
33+
for idx, c in enumerate(text):
34+
m = ord(c)-ord('a')
35+
if alphabet_count[m] < 0:
36+
alphabet_count[m] = text.count(c)
37+
count = alphabet_count[m]
38+
39+
if K <= count:
40+
chars[c].append(idx)
41+
# -
42+
_min, _max = 10000, 0
43+
for x in chars.values():
44+
for i in range(len(x)-K+1):
45+
# 0+k-1 2,
46+
current_length = x[i+K-1] - x[i] + 1
47+
_min = min(_min, current_length)
48+
_max = max(_max, current_length)
49+
50+
if len(chars) > 0:
51+
print(_min, _max)
52+
else:
53+
print("-1")
54+
55+
```

baekjoon/problems/[2579]계단 오르기/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ name: "계단 오르기"
44
src: "https://www.acmicpc.net/problem/2579"
55
tags:
66
- 다이나믹 프로그래밍
7-
done: false
7+
done: true
88
draft: false
99
level: 8
1010
difficulty: "Silver III"

0 commit comments

Comments
 (0)