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
- cs
- ubuntu
- Python
- 이것이 코딩테스트다 with 파이썬
- 3단계
- CS231n
- ssd
- 2단계
- 백준
- test-helper
- SWEA
- docker
- 모두를 위한 딥러닝 강좌 시즌1
- STL
- 파이썬
- 구현
- 그리디
- 실전알고리즘
- 딥러닝
- MySQL
- C++
- pytorch
- 자료구조 및 실습
- 프로그래머스
- AWS
- 머신러닝
- 코드수행
- 1단계
- Object detection
- 전산기초
Archives
- Today
- Total
곰퓨타의 SW 이야기
[프로그래머스 level2 행렬 테두리 회전하기] 시간 초과 극복하기 본문
해결해야하는 문제는 다음과 같았다.
https://programmers.co.kr/learn/courses/30/lessons/77485
코딩테스트 연습 - 행렬 테두리 회전하기
6 6 [[2,2,5,4],[3,3,6,6],[5,1,6,3]] [8, 10, 25] 3 3 [[1,1,2,2],[1,2,2,3],[2,1,3,2],[2,2,3,3]] [1, 1, 5, 3]
programmers.co.kr
처음에는 copy.deepcopy를 활용하였다가, 시간 초과가 떴다.
이 문제는 다음과 같은 아이디어로 접근하였다.
여기서 나는 a,b,c가 있을 때 a를 b에 담고, b를 c에 담는 경우에 자주 활용하였던 temp를 활용하였다.
def solution(rows, columns, queries):
answer = []
maps = [[0]*columns for i in range(rows)]
for i in range(rows):
for j in range(columns):
maps[i][j] = (i)*columns + j + 1
drow = (0,1,0,-1)
dcol = (1,0,-1,0)
for (x1,y1,x2,y2) in queries :
min_n = rows*columns
nx = x1 - 1
ny = y1 - 1
count = (y2-y1, x2-x1,y2-y1,x2-x1)
first_val = maps[nx][ny]
for i in range(4):
for _ in range(count[i]):
nx += drow[i]
ny += dcol[i]
temp = maps[nx][ny]
maps[nx][ny] = first_val
first_val=temp
min_n = min(min_n, maps[nx][ny])
answer.append(min_n)
return answer
'TIL > 프로그래머스' 카테고리의 다른 글
[프로그래머스 level2 배달] 플로이드 워셜 알고리즘 활용하기, bfs 응용(다익스트라) 버전 추가 (0) | 2021.06.11 |
---|---|
[프로그래머스 level2 메뉴 리뉴얼] itertools, collections 사용하기 (0) | 2021.06.11 |
[프로그래머스 level2 게임 맵 최단거리] 효율적으로 bfs 활용하기 (0) | 2021.06.10 |
[프로그래머스 level1 약수의 개수와 덧셈] 완전제곱수 활용하기 (0) | 2021.06.10 |
[프로그래머스 level1 이름이 있는 동물의 아이디] mysql 기초지식 활용하기 (0) | 2021.06.10 |
Comments