๋ฌธ์
https://www.acmicpc.net/problem/14890
ํ์ด
# ๋ฐฑ์ค 14890๋ฒ ๋ฌธ์ - ๊ฒฝ์ฌ๋ก
n, l = map(int, input().split())
graph = [list(map(int, input().split())) for _ in range(n)]
ans = 0
def check_line(line):
for i in range(1, n):
if abs(line[i] - line[i - 1]) > 1:
return False
if line[i] < line[i - 1]:
for j in range(l):
if i + j >= n or line[i] != line[i + j] or slope[i + j]:
return False
if line[i] == line[i + j]:
slope[i + j] = True
elif line[i] > line[i - 1]:
for j in range(l):
if i - j - 1 < 0 or line[i - 1] != line[i - j - 1] or slope[i - j - 1]:
return False
if line[i - 1] == line[i - j - 1]:
slope[i - j - 1] = True
return True
for i in range(n):
slope = [False] * n
if check_line([graph[i][j] for j in range(n)]):
ans += 1
for j in range(n):
slope = [False] * n
if check_line([graph[i][j] for i in range(n)]):
ans += 1
print(ans)
'๐๏ธ Algorithm > ๐ฉ ๋ฐฑ์ค' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
๐ฉ [๋ฐฑ์ค] [Python] [Gold4] 15685๋ฒ_๋๋๊ณค ์ปค๋ธ (0) | 2023.06.26 |
---|---|
๐ฉ [๋ฐฑ์ค] [Python] [Gold5] 14719๋ฒ_๋น๋ฌผ (0) | 2023.06.21 |
๐ฉ [๋ฐฑ์ค] [Python] [Silver2] 2477๋ฒ_์ฐธ์ธ๋ฐญ (0) | 2023.06.16 |
๐ฉ [๋ฐฑ์ค] [Python] [Silver2] 3085๋ฒ_์ฌํ ๊ฒ์ (0) | 2023.06.14 |
๐ฉ [๋ฐฑ์ค] [Python] [Silver3] 15903๋ฒ_์นด๋ ํฉ์ฒด ๋์ด (0) | 2023.05.29 |