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(begin, end): | |
result = [] | |
for i in range(begin, end+1): | |
# 1은 문제 조건상 0이므로, 0을 넣어준다. | |
if i < 2: | |
result.append(0) | |
continue | |
# 소수 판별하기. | |
for j in range(2, int(math.sqrt(i))+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
from collections import deque | |
import sys | |
from copy import deepcopy | |
n, l, r = map(int, sys.stdin.readline().split()) | |
maps = [] | |
for _ in range(n): | |
maps.append(list(map(int, sys.stdin.readline().split()))) | |
dirs = [(0,1),(0,-1),(1,0),(-1,0)] | |
def bfs(maps, start, visited): |
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, s): | |
# 자연수 n개의 합으로 n보다 작은 s를 만들 수는 없으므로 [-1]을 리턴한다 | |
if n > s: return [-1] | |
result = [] | |
# s를 n으로 나눈 몫이 n개이도록 초기값을 정한다. | |
initial = s // n | |
for _ in range(n): | |
result.append(initial) | |
idx = len(result) - 1 | |
# s를 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 math | |
import sys | |
from itertools import permutations | |
_ = int(sys.stdin.readline()) | |
numbers = sys.stdin.readline().split() | |
operator_list = list(map(int, sys.stdin.readline().split())) | |
operators = {0:"+", 1:'-',2:'*',3:"/"} | |
operator_candidate = [] |
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
# 2. 문자열 w를 균형잡힌 괄호 문자열로 구분하는 함수. | |
# 균형잡힌 괄호 문자열이 만들어지는 index를 반환한다. | |
def balanced(p): | |
num = 0 | |
temp = [] | |
for idx, value in enumerate(p): | |
if value == ")": | |
num -=1 | |
if value == "(": | |
num +=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 | |
height, width, start_y, start_x, _ = map(int, sys.stdin.readline().split()) | |
maps = [] | |
for _ in range(height): | |
maps.append(list(map(int, sys.stdin.readline().split()))) | |
order = list(map(int, sys.stdin.readline().split())) | |
class Dice: | |
def __init__(self): | |
self.t = 0 | |
self.b = 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(m, n, puddles): | |
# 문제에서는 1부터 시작하므로, | |
# 문제의 값과 일치할 수 있게 가로 m+1, 세로 n+1로 maps을 만들어준다. | |
maps = [[0] * (m + 1) for _ in range(n+1)] | |
# 시작점 | |
maps[1][1] = 1 | |
for i in range(1, n + 1): | |
for j in range(1, m + 1): | |
if i == 1 and j == 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 | |
#sys.stdin = open('input.txt','r') | |
N, L = map(int, sys.stdin.readline().split()) | |
maps = [] | |
for _ in range(N): | |
maps.append(list(map(int, sys.stdin.readline().split()))) | |
def check(arr): | |
start = arr[0] | |
idx = 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(cookie): | |
max_value = 0 | |
for i in range(len(cookie)-1): | |
# 분기점을 만들 수 있는 모든 경우의 수를 확인한다. | |
# 맨 뒤에서부터, 앞부분의 합을 front / 뒷부분의 합을 end로 정의한다. | |
front_value, front_idx = cookie[i], i | |
end_value, end_idx = cookie[i+1], i+1 | |
while True: | |
# 앞부분의 합 == 뒷부분의 합, 이전의 max 값보다 클 경우 max_value 업데이트 | |
if front_value == end_value and front_value > max_value: |
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 | |
N = int(sys.stdin.readline()) | |
K = int(sys.stdin.readline()) | |
maps = [[0 for _ in range(N)] for _ in range(N)] | |
for _ in range(K): | |
y, x = map(int, sys.stdin.readline().split()) | |
# 사과 위치 표시하기. | |
maps[y-1][x-1] = 2 |