본문 바로가기
728x90

분류 전체보기88

[백준] 14502 - 연구소 Python https://www.acmicpc.net/problem/14502 14502번: 연구소 인체에 치명적인 바이러스를 연구하던 연구소에서 바이러스가 유출되었다. 다행히 바이러스는 아직 퍼지지 않았고, 바이러스의 확산을 막기 위해서 연구소에 벽을 세우려고 한다. 연구소는 크 www.acmicpc.net import sys from collections import deque import copy input = sys.stdin.readline dx = [-1, 1, 0, 0] dy = [0, 0, -1, 1] def bfs(): queue = deque() tmp_graph = copy.deepcopy(graph) for i in range(N): for j in range(M): if tmp_graph[i.. 2023. 10. 10.
[백준] 2156 - 포도주 시식 Python https://www.acmicpc.net/problem/2156 2156번: 포도주 시식 효주는 포도주 시식회에 갔다. 그 곳에 갔더니, 테이블 위에 다양한 포도주가 들어있는 포도주 잔이 일렬로 놓여 있었다. 효주는 포도주 시식을 하려고 하는데, 여기에는 다음과 같은 두 가지 규 www.acmicpc.net import sys input = sys.stdin.readline N = int(input()) wines = list() dp = [0] * N for i in range(N): wine = int(input()) wines.append(wine) dp[0] = wines[0] if N > 1: dp[1] = wines[0] + wines[1] if N > 2: dp[2] = max(wines[.. 2023. 10. 10.
[백준] 1406 - 에디터 Python https://www.acmicpc.net/problem/1406 1406번: 에디터 첫째 줄에는 초기에 편집기에 입력되어 있는 문자열이 주어진다. 이 문자열은 길이가 N이고, 영어 소문자로만 이루어져 있으며, 길이는 100,000을 넘지 않는다. 둘째 줄에는 입력할 명령어의 개수 www.acmicpc.net import sys st1 = list(sys.stdin.readline().rstrip()) st2 = [] for _ in range(int(sys.stdin.readline())): command = list(sys.stdin.readline().split()) if command[0] == 'L': if st1: st2.append(st1.pop()) elif command[0] == 'D'.. 2023. 10. 10.
[백준] 1912 - 연속합 Python https://www.acmicpc.net/problem/1912 1912번: 연속합 첫째 줄에 정수 n(1 ≤ n ≤ 100,000)이 주어지고 둘째 줄에는 n개의 정수로 이루어진 수열이 주어진다. 수는 -1,000보다 크거나 같고, 1,000보다 작거나 같은 정수이다. www.acmicpc.net (1) 첫번째 코드 - 메모리 초과 import sys input = sys.stdin.readline N = int(input()) num = list(map(int, input().split(" "))) M = len(num) dp = [[-1000] * (M) for _ in range(M)] answer = -1000 # print(num) for i in range(M): for j in range.. 2023. 10. 9.
[백준] 7576 - 토마토 Python https://www.acmicpc.net/problem/7576 7576번: 토마토 첫 줄에는 상자의 크기를 나타내는 두 정수 M,N이 주어진다. M은 상자의 가로 칸의 수, N은 상자의 세로 칸의 수를 나타낸다. 단, 2 ≤ M,N ≤ 1,000 이다. 둘째 줄부터는 하나의 상자에 저장된 토마토 www.acmicpc.net import sys from collections import deque input = sys.stdin.readline dx = [-1, 1, 0, 0] dy = [0, 0, 1, -1] def bfs(): while queue: x, y = queue.popleft() # print(x, y) for i in range(4): nx = x + dx[i] ny = y + dy[i.. 2023. 10. 9.
[백준] 10773 - 제로 Python https://www.acmicpc.net/problem/10773 10773번: 제로 첫 번째 줄에 정수 K가 주어진다. (1 ≤ K ≤ 100,000) 이후 K개의 줄에 정수가 1개씩 주어진다. 정수는 0에서 1,000,000 사이의 값을 가지며, 정수가 "0" 일 경우에는 가장 최근에 쓴 수를 지우고, 아닐 경 www.acmicpc.net import sys input = sys.stdin.readline K = int(input()) num = list() for i in range(K): M = int(input()) if M == 0: num.pop() else: num.append(M) print(sum(num)) 2023. 10. 9.
728x90