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 | 29 | 30 | 31 |
Tags
- C언어 덱
- 범위 기반 for문
- 원형 연결 구조 연결된 큐
- 논리 연산
- C언어 계산기 프로그램
- 회전 및 자리 이동 연산
- LAN의 분류
- 값/참조/주소에 의한 전달
- 운영체제 기능
- string유형
- 문제해결 단계
- 입출력 관리자
- 프로그래머스 배열만들기4
- C언어 스택 연산
- auto 키워드
- const화
- 알고리즘 조건
- 네트워크 결합
- c언어 괄호검사
- l-value참조자
- 프로그래머스 푸드 파이트 대회
- 유형 변환
- r-value참조자
- 괄호 검사 프로그램
- 백준 파이썬
- const l-value참조자
- getline()함수
- 문자형 배열
- 주기억장치
- IPv4 주소체계
Archives
- Today
- Total
chyam
[프로그래머스 Lv2, python] - [PCCP 기출문제] 2번 / 석유 시추 본문
https://school.programmers.co.kr/learn/courses/30/lessons/250136
프로그래머스
SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프
programmers.co.kr
from collections import deque
def solution(land): # 마지막에 res의 max값 구하기
r, c = len(land), len(land[0])
visited = [[False]* c for i in range(r)]
direction = [(0,1), (0,-1), (1,0) ,(-1,0)] # 상하좌우
res = [0] * c
def bfs(i, j):
queue = deque([(i, j)])
visited[i][j] = True
cnt = 1
tmp = []
while queue:
x, y = queue.popleft()
if y not in tmp: # 열 번호를 새로운 리스트에 저장
tmp.append(y)
for dx, dy in direction:
nX, nY = x + dx, y + dy
if 0 <= nX < r and 0 <= nY < c and not visited[nX][nY] and land[nX][nY] == 1:
cnt += 1 # 이웃하는 1의 개수 세기
visited[nX][nY] = True
queue.append([nX, nY])
for i in tmp: # 이후에 이 열들에 1의 개수 더해주기
res[i] += cnt
for i in range(r):
for j in range(c):
if land[i][j] == 1 and not visited[i][j]:
bfs(i, j)
return max(res)
'프로그래머스 > LV2' 카테고리의 다른 글
[프로그래머스 Lv2, python] - 혼자 놀기의 달인 (0) | 2025.05.08 |
---|---|
[프로그래머스 Lv2, python] - 숫자 블록 (0) | 2025.05.07 |
[프로그래머스 Lv2, python] - 혼자서 하는 틱택토 (0) | 2025.05.02 |
[프로그래머스 Lv2, python] - 지게차와 크레인 (0) | 2025.05.01 |
[프로그래머스 Lv2, python] - 후보키 (0) | 2025.04.30 |