1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
import sys
sys.stdin = open("input", "rt")
n = int(input())
ar = [list(map(int, input().split())) for _ in range(n)]
ar.insert(0,[0]*n)
ar.append([0]*n)
for a in ar:
a.insert(0, 0)
a.append(0)
cnt=0
# 위 오른쪽 아래 왼쪽 인덱스
# 보통 상하좌우 구할 때 이런식으로 구한다
dx=[-1, 0, 1, 0]
dy=[0, 1, 0, -1]
for i in range(1, n+1):
for j in range(1, n+1):
if all(ar[i][j] > ar[i+dx[k]][j+dy[k]] for k in range(4)): # 핵심!
cnt+=1
print(cnt)
|
cs |
728x90
'Data Structures & Algorithms' 카테고리의 다른 글
[Algorithms] Basic-격자판 회문수 (0) | 2022.05.15 |
---|---|
[Algorithms] Basic-스도쿠 검사 (0) | 2022.05.14 |
[Algorithms] Basic-곶감(모래시계) (0) | 2022.05.14 |
[Algorithms] Basic-사과나무(다이아몬드) (0) | 2022.05.14 |
[Algorithms] Basic-수들의 합 (0) | 2022.05.14 |