1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | score = 0 slope_map = list() map_size, L = map(int, input().split()) for _ in range(map_size): slope_map.append(list(map(int, input().split()))) def check_slope_possible(slope, L): is_slope = [0 for i in range(map_size)] for i in range(map_size-1): N = slope[i] - slope[i+1] if(abs(N) > 1): return False elif(N == 1): # 3 2 와 같은 경우 for j in range(i+1, i+1+L): # i+1 ~ i+L 까지의 index는 1로 채워진다. (인덱스 범위 초과시 False 반환 : 자리가 없기 때문) try: if (is_slope[j] == 1): return False else: is_slope[j] = 1 except IndexError: return False elif(N == -1): # 2 3 과 같은 경우 if (i-L+1 < 0): return False for j in range(i-L+1, i+1): try: if (is_slope[j] == 1): return False else: is_slope[j] = 1 except IndexError: return False return True for i in range(map_size): slope = slope_map[i] if check_slope_possible(slope, L) is True: score += 1 for i in range(map_size): slope = [slope_map[j][i] for j in range(map_size)] if check_slope_possible(slope, L) is True: score += 1 print(score) | cs |
'프로그래밍 > 백준' 카테고리의 다른 글
1051 숫자 정사각형 (0) | 2020.07.14 |
---|---|
1015 수열정렬 (0) | 2020.07.13 |