#문제링크 https://www.acmicpc.net/problem/2665 2665번: 미로만들기 첫 줄에는 한 줄에 들어가는 방의 수 n(1 ≤ n ≤ 50)이 주어지고, 다음 n개의 줄의 각 줄마다 0과 1이 이루어진 길이가 n인 수열이 주어진다. 0은 검은 방, 1은 흰 방을 나타낸다. www.acmicpc.net #나의풀이 import sys from heapq import heappush, heappop delta = [[1, 0], [0, 1], [-1, 0], [0, -1]] if __name__=="__main__": N = int(sys.stdin.readline()) board = [] for _ in range(N): board.append(list(map(int, sys.stdin..
#문제링크 https://www.acmicpc.net/problem/22866 22866번: 탑 보기 3번째 건물에서 볼 수 있는 건물은 2, 4, 8번째 건물로 총 3개를 볼 수 있다. 그 중 3번째 건물과 가장 가까운 건물은 2, 4번째 있는 건물로 이 중 번호가 작은 번호인 2가 답이 된다. www.acmicpc.net #나의풀이 import sys if __name__=="__main__": N = int(sys.stdin.readline()) arr = list(map(int, sys.stdin.readline().split())) near = [[-1, 2147000000] for _ in range(N)] count = [] stack = [] for i in range(N): while l..
#문제링크 https://www.acmicpc.net/problem/16120 16120번: PPAP 첫 번째 줄에 문자열이 주어진다. 문자열은 대문자 알파벳 P와 A로만 이루어져 있으며, 문자열의 길이는 1 이상 1,000,000 이하이다. www.acmicpc.net #나의풀이 import sys from collections import deque if __name__=="__main__": S = sys.stdin.readline().rstrip() stack = [] for i in range(len(S)): if len(stack) == 0: stack.append(S[i]) continue if len(stack) > 2: if "".join(stack[len(stack)-3:len(stac..
#문제링크 https://www.acmicpc.net/problem/5430 5430번: AC 각 테스트 케이스에 대해서, 입력으로 주어진 정수 배열에 함수를 수행한 결과를 출력한다. 만약, 에러가 발생한 경우에는 error를 출력한다. www.acmicpc.net #나의풀이 import sys from collections import deque if __name__=="__main__": N = int(sys.stdin.readline()) for _ in range(N): commands = sys.stdin.readline().strip() len_arr = int(sys.stdin.readline()) s = sys.stdin.readline().rstrip() if s == "[]": arr ..
#문제링크 https://www.acmicpc.net/problem/27211 27211번: 도넛 행성 준겸이는 $N \times M$칸으로 이루어진 도넛 모양의 행성에 살고 있다. 준겸이가 살고 있는 행성에는 위 그림처럼 격자 모양으로 줄이 그어져 있다. 행성의 각 칸은 숲으로 막혀 있거나, 지나갈 수 www.acmicpc.net #나의풀이 import sys sys.stdin = open('../input.txt') delta = [[-1, 0], [0, 1], [1, 0], [0, -1]] def DFS(x, y): board[x][y] = 1 for i in range(4): dx = x + delta[i][0] dy = y + delta[i][1] if dx < 0: dx += N if dx =..
#문제링크 https://www.acmicpc.net/problem/1446 1446번: 지름길 첫째 줄에 지름길의 개수 N과 고속도로의 길이 D가 주어진다. N은 12 이하인 양의 정수이고, D는 10,000보다 작거나 같은 자연수이다. 다음 N개의 줄에 지름길의 시작 위치, 도착 위치, 지름길의 길이 www.acmicpc.net #나의풀이 import sys if __name__=="__main__": N, D = map(int, sys.stdin.readline().split()) arr = [[] for _ in range(10001)] for _ in range(N): start, end, express = map(int, sys.stdin.readline().split()) arr[start]..