This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
from collections import deque | |
from copy import deepcopy | |
width, height, depth = map(int, sys.stdin.readline().split()) | |
maps = [] | |
starts = [] | |
no_zero = True | |
def bfs(starts, maps, depth, height, width): | |
# 가로, 세로, 높이로 각각 이동 | |
dirs = [(1,0,0),(-1,0,0),(0,1,0),(0,-1,0),(0,0,1),(0,0,-1)] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
N, K = map(int, sys.stdin.readline().split()) | |
result = [[0 for _ in range(K+1)] for _ in range(N)] | |
for i in range(N): | |
weight, value = map(int, sys.stdin.readline().split()) | |
for idx in range(1, K+1): | |
if idx >= weight: | |
result[i][idx] = max(result[i-1][idx], result[i-1][idx - weight] + value) | |
else: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from collections import defaultdict, deque | |
def can_reach(start, des, table): | |
visited = set() | |
queue = deque() | |
queue.append(start) | |
while queue: | |
nxt = queue.popleft() | |
visited.add(nxt) | |
for i in table[nxt]: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
N = int(sys.stdin.readline()) | |
arr = list(map(int, sys.stdin.readline().split())) | |
result = [1] * N | |
for i in range(1, N): | |
for j in range(i): | |
if arr[j] < arr[i]: | |
result[i] = max(result[i], result[j]+1) | |
print(max(result)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
from copy import deepcopy | |
N, S, M = map(int, sys.stdin.readline().split()) | |
V = list(map(int, sys.stdin.readline().split())) | |
result = [S] | |
def get_result(result, V): | |
cnt = 0 | |
while cnt != len(V): | |
# 해당 곡에서 허용 가능한 range 범위 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
# deepcopy 함수를 쓰면 '시간초과' 가 뜬다. | |
# from copy import deepcopy | |
N, S, M = map(int, sys.stdin.readline().split()) | |
V = list(map(int, sys.stdin.readline().split())) | |
# 모든 볼륨에 관해 연주 가능 여부를 계산하기. | |
result = [[0 for _ in range(M+1)] for _ in range(N+1)] | |
result[0][S] = 1 | |
prevs = [S] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
N, S, M = map(int, sys.stdin.readline().split()) | |
V = list(map(int, sys.stdin.readline().split())) | |
# 모든 볼륨에 관해 연주 가능 여부를 계산하기. | |
result = [[0 for _ in range(M+1)] for _ in range(N+1)] | |
result[0][S] = 1 | |
# 정확히 이렇게 풀어아먄 메모리 초과도, 시간 초과도 안 난다. | |
for i in range(1, N+1): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
N = int(sys.stdin.readline()) | |
arr = [(0,0,0,0)] | |
for i in range(1, N+1): | |
area, height, weight = map(int, sys.stdin.readline().split()) | |
arr.append((i, area, height, weight)) | |
arr.sort(key = lambda x: x[3]) | |
# table[i] = i번 벽돌을 가장 아래에 두었을 때 최대 높이. (무게 순으로 정렬된 상태에서) | |
# table[i] = max(table[i], table[j] + height[i]) if area[i] > area[j] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
N = int(sys.stdin.readline()) | |
arr = [] | |
for _ in range(N): | |
arr.append(list(map(int, sys.stdin.readline().split()))) | |
# i 위에 j를 올릴 수 있는지 여부 | |
def is_possible(top, bottom): | |
if top[0] < bottom[0] or top[2] < bottom[2] or bottom == top: | |
return 0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 구명보트를 최대한 적게 쓰려면, | |
# 가장 무게 무거운 사람과 가장 무게 가벼운 사람을 | |
# 같이 보트에 태워 보낼 수 있는지 확인해야 한다. | |
def solution(people, limit): | |
people.sort() | |
min_idx, max_idx = 0, len(people)-1 | |
double = 0 | |
while min_idx < max_idx: | |
# 가장 가벼운 사람 무게 + 가장 무거운 사람 무게 <= 보트 제한 | |
# = 보트 한 번에 두 명을 태워보낸다. |