답안 #312735

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
312735 2020-10-14T09:13:15 Z DEPRomaniac Non-boring sequences (CERC12_D) Python 3
0 / 1
27 ms 4212 KB
def check_boring(first, last):
	if first>=last:
		return 1
	for i in range(first,int((first+last)/2)+1):
		if prev[i]<first and next[i]>last:
			return (check_boring(first,i-1) and check_boring(i+1, last))
		if prev[last-i]<first and next[last-i]>last:
			return (check_boring(first,last-i-1) and check_boring(last-i+1, last))
	return 0

def assign_prev():
	d.clear()
	for i in range(0,n):
		if arr[i] in d:
			prev[i] = d[arr[i]]
		else:
			prev[i] = -1
		d[arr[i]] = i

def assign_next():
	d.clear()
	for i in range(n-1, -1, -1):
		if arr[i] in d:
			next[i] = d[arr[i]]
		else:
			next[i] = n
		d[arr[i]] = i

d = dict()

t = int(input())
for i in range(t):
	n = int(input())
	next = [n] *n
	prev = [-1] *n
	arr = list(map(int,input().split()))
	assign_prev()
	assign_next()
	if check_boring(0,n-1) == 1:
		print('non-boring')
	else:
		print('boring')
# 결과 실행 시간 메모리 Grader output
1 Runtime error 27 ms 4212 KB Execution failed because the return code was nonzero
2 Halted 0 ms 0 KB -