Notice
Recent Posts
Recent Comments
Link
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 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 |
Tags
- 논리 연산
- C언어 스택 연산
- 입출력 관리자
- LAN의 분류
- 문제해결 단계
- 값/참조/주소에 의한 전달
- 네트워크 결합
- const화
- IPv4 주소체계
- 프로그래머스 푸드 파이트 대회
- 문자형 배열
- auto 키워드
- 프로그래머스 배열만들기4
- 원형 연결 구조 연결된 큐
- 백준 파이썬
- c언어 괄호검사
- getline()함수
- C언어 계산기 프로그램
- l-value참조자
- const l-value참조자
- 알고리즘 조건
- 주기억장치
- 괄호 검사 프로그램
- 범위 기반 for문
- 유형 변환
- 회전 및 자리 이동 연산
- string유형
- C언어 덱
- r-value참조자
- 운영체제 기능
Archives
- Today
- Total
chyam
[백준] 2468번,python - 안전 영역 본문

https://www.acmicpc.net/problem/2468
import sys
from collections import deque
input = sys.stdin.readline
n = int(input())
space = [] # 땅 높이
max_len, res = 0, 0
direct = [[0,1],[0,-1],[1,0],[-1,0]] # 방향 설정
for _ in range(n):
tmp = list(map(int,input().split()))
max_len = max(max(tmp),max_len) # 빗물 최대 높이
space.append(tmp)
def bfs(l, i, j):
queue = deque([(i,j)]) # 시작 지점
visited[i][j] = True
while queue:
x, y = queue.popleft()
for dx, dy in direct: # 상하좌우로 탐색 시작
nx, ny = x + dx, y + dy
if 0 <= nx < n and 0 <= ny < n: # 범위 내에서만
if space[nx][ny] > l and not visited[nx][ny]: # 기준치보다 높을때만 이동 가능 + 방문하지 않은곳 추가
queue.append([nx,ny]) # 갈수있는곳 추가
visited[nx][ny] = True # 방문 처리
for l in range(max_len):
visited = [[False] * n for _ in range(n)]
cnt = 0
for i in range(n):
for j in range(n):
if not visited[i][j] and space[i][j] > l: # 방문하지 않았고 일정 높이 이상이어야함
bfs(l,i,j)
cnt += 1 # 안전 영역 + 1
res = max(res,cnt) # 최대 영역 저장
print(res)'백준' 카테고리의 다른 글
| [백준] 11404번, python - 플로이드 (0) | 2026.01.21 |
|---|---|
| [백준] 12865번,python - 평범한 배낭(배낭 문제) (0) | 2026.01.20 |
| [백준] 1916번,python - 최소비용 구하기 (0) | 2026.01.13 |
| [백준] 3078번, python - 좋은 친구 (0) | 2026.01.07 |
| [백준] 1753번,python - 최단 경로 (0) | 2026.01.06 |