This repository was archived by the owner on Feb 22, 2022. It is now read-only.
File tree 2 files changed +53
-1
lines changed
2 files changed +53
-1
lines changed Original file line number Diff line number Diff line change 52
52
| 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 ์. |
53
53
| 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 " /> | | |
54
54
| 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 " /> | โ
| ์ฐ์ ๋ฌธ์์ด์ ๊ธธ์ด๋ฅผ ๊ตฌํ๋ ๊ฒ์ด ๋ฌด์์ธ์ง๋ฅผ ํ์
ํ๋ ๋ฌธ์ |
Original file line number Diff line number Diff line change
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 )
You canโt perform that action at this time.
0 commit comments