[Baekjoon-Python] 14500 : 테트로미노
https://www.acmicpc.net/problem/14500 접근 모든 좌표에서 dfs 탐색해서 테트로미노를 구한다. 폴리오미노가 2개일 때 3번째 폴리오미노를 더하고 2번째 좌표에서 다시 탐색해서 ㅗ, ㅏ, ㅓ, ㅜ 테트로미노를 구한다. 풀이 from sys import stdin def dfs(depth, total, r, c): global res if res >= total + (4 - depth) * max_num: # (1) return if depth == 4: # (2) res = max(res, total) return for i in range(4): nr, nc = r + direction[i], c + direction[3 - i] if is_out_of_range(nr, n..
2024. 1. 17.
[Baekjoon-Python] 14499 : 주사위 굴리기
https://www.acmicpc.net/problem/14499 접근 주사위의 인덱스를 0:top, 1:north, 2:east, 3:west, 4:south, 5:bottom으로 두고 굴리는 방향에 따라 값을 수정한다. 풀이 from sys import stdin from collections import deque def turn(command): global dice top, north, east, west, south, bottom = dice if command == 1: # (1) dice = [west, north, top, bottom, south, east] elif command == 2: dice = [east, north, bottom, top, south, west] elif ..
2024. 1. 17.
[Baekjoon-Python] 14503 : 로봇 청소기
https://www.acmicpc.net/problem/14503 접근 청소한 칸을 청소하지 않은 칸, 벽과 구분하기 위해 2로 저장한다. 풀이 from sys import stdin n, m = map(int, stdin.readline().split()) r, c, d = map(int, stdin.readline().split()) room = [stdin.readline().split() for _ in range(n)] direction = [(-1, 0), (0, 1), (1, 0), (0, -1)] cleaning_cnt = 1 while True: room[r][c] = '2' for _ in range(4): d = (d + 3) % 4 nr, nc = r + direct..
2024. 1. 17.