File tree 3 files changed +100
-1
lines changed 3 files changed +100
-1
lines changed Original file line number Diff line number Diff line change
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" )
Original file line number Diff line number Diff line change
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
+ ```
Original file line number Diff line number Diff line change @@ -4,7 +4,7 @@ name: "계단 오르기"
4
4
src : " https://www.acmicpc.net/problem/2579"
5
5
tags :
6
6
- 다이나믹 프로그래밍
7
- done : false
7
+ done : true
8
8
draft : false
9
9
level : 8
10
10
difficulty : " Silver III"
You can’t perform that action at this time.
0 commit comments