얼렁뚱땅 백준 문제풀이

[백준 문제풀이] 얼렁뚱땅 20437번 문자열 게임 2 풀이

MOSTAR 2022. 8. 30. 19:26

https://www.acmicpc.net/problem/20437

t = int(input())
for _ in range(t) :
	w = input().strip()
	k = int(input())
	dict_ = {}
	check_min = len(w)
	check_max = -1

	if k == 1 :
		print(1, 1)
		continue

	for i in range(len(w)) :
		if w[i] not in dict_ :
			dict_[w[i]] = [i]
		else :
			if len(dict_[w[i]]) >= k-1:
				check_index = len(dict_[w[i]])- k + 1
				temp = i - dict_[w[i]][check_index]
				check_min = min(check_min, temp)
				check_max = max(check_max, temp)
				dict_[w[i]].append(i)

			else :
				dict_[w[i]].append(i)
	if check_min == len(w) and check_max == -1 :
		print(-1)
	else :
		print(check_min+1, check_max+1)