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
- 완전탐색
- Kubernetes
- 코딩테스트
- GIT
- FastAPI
- FDS
- python
- docker
- 네이버AItech
- NaverAItech
- pytorch
- 백준
- DeepLearning
- Matplotlib
- torchserve
- GitHub Action
- Kaggle
- autoencoder
- 알고리즘
- NLP
- pep8
- 프로그래머스
- GCP
- github
- datascience
- wandb
- leetcode
- rnn
- PytorchLightning
- vscode
Archives
- Today
- Total
Sangmun
백준 17144번 미세먼지 안녕! 본문
https://www.acmicpc.net/problem/17144
파이썬으로 풀면 시간초과가 나는데 pypy로 제출을 하면 통과는 된다...
매번 행렬을 복사하는 것 때문에 그런거 같은데 다른 풀이법을 알아봐야겠다.
import sys
input = sys.stdin.readline
r,c,t = map(int,input().split())
Particulates = []
Particulates_copy = [[0]*c for _ in range(r)]
for _ in range(r):
tmp = list(map(int,input().split()))
Particulates.append(tmp)
direction = [[0,1],[1,0],[0,-1],[-1,0]]
position = []
for i in range(r):
for j in range(c):
if Particulates[i][j] == -1:
position.append((i,j))
for _ in range(t):
for i in range(r):
for j in range(c):
if Particulates[i][j] > 0:
count = 0
for each in direction:
new_i = i + each[0]
new_j = j + each[1]
if 0 <= new_i < r and 0 <= new_j < c and Particulates[new_i][new_j] != -1:
count += 1
Particulates_copy[new_i][new_j] += int(Particulates[i][j] / 5)
Particulates[i][j] -= int(Particulates[i][j] / 5) * count
for i in range(r):
for j in range(c):
if Particulates_copy[i][j] > 0:
Particulates[i][j] += Particulates_copy[i][j]
Particulates_copy[i][j] = 0
up = position[0]
# Upper rotate
for i in range(up[1]-1,-1,-1):
if Particulates[up[0]][i+1] == -1:
continue
else:
Particulates[up[0]][i+1] = Particulates[up[0]][i]
for i in range(up[0]-1,-1,-1):
if Particulates[i+1][0] == -1:
continue
else:
Particulates[i+1][0] = Particulates[i][0]
for i in range(1,c):
Particulates[0][i-1] = Particulates[0][i]
for i in range(1,up[0]+1):
if Particulates[i][c-1] == -1:
Particulates[i-1][c-1] = 0
else:
Particulates[i-1][c-1] = Particulates[i][c-1]
for i in range(c-2, up[1]-1,-1):
if Particulates[up[0]][i] == -1:
Particulates[up[0]][i+1] = 0
else:
Particulates[up[0]][i+1] = Particulates[up[0]][i]
dw = position[1]
# Lower rotate
for i in range(dw[1]-1,-1,-1):
if Particulates[dw[0]][i+1] == -1:
continue
else:
Particulates[dw[0]][i+1] = Particulates[dw[0]][i]
for i in range(dw[0]+1,r):
if Particulates[i-1][0] == -1:
continue
else:
Particulates[i-1][0] = Particulates[i][0]
for i in range(1,c):
Particulates[r-1][i - 1] = Particulates[r-1][i]
for i in range(r-2,dw[0]-1,-1):
if Particulates[i][c-1] == -1:
Particulates[i + 1][c - 1] = 0
else:
Particulates[i+1][c-1] = Particulates[i][c-1]
for i in range(c-2, dw[1]-1,-1):
if Particulates[dw[0]][i] == -1:
Particulates[dw[0]][i+1] = 0
else:
Particulates[dw[0]][i+1] = Particulates[dw[0]][i]
total = 0
for each in Particulates:
total += sum(each)
print(total + 2)
'알고리즘 > 백준' 카테고리의 다른 글
백준 11052번 카드 구매하기 파이썬 (0) | 2022.12.21 |
---|---|
백준 9935번 문자열 폭발 (0) | 2022.12.14 |
백준 12851번 숨바꼭질2 (0) | 2022.12.14 |
백준 2096번 내려가기 (0) | 2022.12.12 |
백준 15686번 치킨 배달 (0) | 2022.12.12 |
Comments