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