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 math | |
def solution(distance, rocks, n): | |
rocks.sort() | |
rocks.append(distance) | |
left, right = 0, distance | |
# 바위 사이의 최소거리보다 거리가 작을 경우 돌 삭제. | |
# 거리가 클 경우, 이 값들 중 최솟값을 구해둔다. | |
answer = 0 | |
while left <= right: | |
# 이전 돌 |
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 | |
num = sys.stdin.readline() | |
# 생성자가 존재할 수 있는 숫자인지 확인하기. | |
possible_start = int(num) - (len(num)*9) | |
if possible_start < 0: | |
possible_start = int(num) | |
# 생성자가 존재할 수 있는 숫자인 경우 | |
while possible_start < int(num): | |
# 각 자릿수의 합을 계산한다. |
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 | |
k, n = map(int, sys.stdin.readline().split()) | |
arr = [] | |
for _ in range(k): | |
arr.append(int(sys.stdin.readline())) | |
lower_bound, upper_bound = 1, max(arr) | |
result = 0 | |
while lower_bound <= upper_bound: | |
# 몇 cm의 크기로 잘라낼 것인지. |
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
n = int(input()) | |
def check(brackets): | |
stack = [] | |
for i in brackets: | |
if i == "(": | |
stack.append(i) | |
else: | |
# ")" 를 입력받았는데 이전에 "("를 입력받은 적이 없는 경우. VPS가 아니다. | |
if not stack: | |
print("NO") |
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(n, times): | |
## 최악의 경우: 가장 비효율적인 심사관에게 다 받는 경우의 시간. | |
left, right = 1, max(times) * n | |
answer = 0 | |
while left <= right: | |
# 한 심사관에게 주어진 시간 | |
mid = (left + right) // 2 | |
people = 0 | |
for i in times: | |
# 각 심사관마다, 주어진 시간 동안 몇 명의 사람을 심사할 수 있는지 |
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().replace("\n","")) | |
for _ in range(n): | |
# 글자를 입력받는 stack left, 커서 이동할 때 사용할 stack right. | |
left, right = [], [] | |
string = list(sys.stdin.readline().replace("\n","")) | |
for value in string: | |
# 커서를 뒤로 옮길 경우, left에 값이 있다면 left 마지막 값을 right로 옮긴다. | |
if value == "<": | |
if len(left) != 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
from collections import deque | |
n = int(input()) | |
maps = [] | |
for _ in range(n): | |
tmp = [int(i) for i in input()] | |
maps.append(tmp) | |
def bfs(coord, maps, visited): | |
dirs = [(1, 0), (-1,0), (0,1), (0,-1)] | |
queue = deque() |
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(land): | |
for row in range(1, len(land)): | |
# 밟을 칸(index) 선택 | |
for i in range(4): | |
# 밟은 칸 제외한 나머지 칸 | |
rest = set(range(4)) - {i} | |
# 밟은 칸 제외한 나머지 칸들의 최댓값을 다음 row의 index에 저장. | |
land[row][i] += max([land[row-1][index] for index in rest]) | |
# 마지막 row에서 얻을 수 있는 점수의 최댓값을 확인한다. | |
return max(land[-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
def solution(land): | |
for row in range(1, len(land)): | |
# 밟을 칸(index) 선택 | |
for i in range(4): | |
# 밟은 칸 제외한 나머지 칸 | |
rest = set(range(4)) - {i} | |
# 밟은 칸 제외한 나머지 칸들의 최댓값을 다음 row의 index에 저장. | |
land[row][i] += max([land[row-1][index] for index in rest]) | |
# 마지막 row에서 얻을 수 있는 점수의 최댓값을 확인한다. | |
return max(land[-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
def solution(sticker): | |
# table[i] = i번째 스티커를 떼는 경우 최댓값 | |
# 맨 앞 스티커를 떼는지 아닌지 -> 맨 뒤 스티커에 영향을 준다 | |
if len(sticker) == 1: | |
return sticker[0] | |
# 1. 맨 앞 스티커를 떼는 경우 | |
table1 = [0 for _ in range(len(sticker))] | |
table1[0] = sticker[0] | |
table1[1] = table1[0] | |
for i in range(2, len(sticker)-1): |