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 | |
import heapq | |
def solution(gems): | |
start, end = 0, 1 | |
gem_loc = defaultdict(int) | |
gem_target = len(set(gems)) | |
# 가장 길이가 짧은 좌표 저장을 위해 heap 자료구조 사용. | |
answer = [] | |
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
class Solution: | |
def trap(self, height: List[int]) -> int: | |
if not height: | |
return 0 | |
result = 0 | |
# 왼쪽 / 오른쪽의 idx 지정 | |
left, right = 0, len(height)-1 | |
# 왼쪽 / 오른쪽의 최고높이 결정 | |
left_height, right_height = height[left], height[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 | |
import math | |
#sys.stdin = open('input.txt') | |
t = int(sys.stdin.readline()) | |
for _ in range(t): | |
n = int(sys.stdin.readline()) | |
arr = list(map(int, sys.stdin.readline().split())) | |
# i번째 페이지까지의 연속합 | |
cumsum = {-1:0} | |
for i in range(len(arr)): |
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(s: str): | |
def expand(left: int, right: int) -> str: | |
# 현재 left idx, right idx가 같은 문자열일 경우 | |
# 윈도우 크기를 좌우로 1씩 넓힌다. | |
while left >= 0 and right <= len(s) and s[left] == s[right-1]: | |
left -= 1 | |
right += 1 | |
return s[left+1:right-1] | |
# 연산 필요없는 경우 | |
if len(s) < 2 or s == s[::-1]: |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 | |
r, c = map(int, sys.stdin.readline().split()) | |
maps = [] | |
for y in range(r): | |
arr = list(sys.stdin.readline().replace("\n","")) | |
maps.append(arr) | |
# 많은 파이프를 심으려면, 최대한 우상향으로 접근해야 함. | |
dirs = [(-1,1),(0,1),(1,1)] | |
end_line = len(maps[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 | |
from collections import defaultdict | |
# taller[i] = i보다 키 큰 사람의 집합 | |
# shorter[i] = i보다 키 작은 사람의 집합 | |
taller, shorter = defaultdict(set), defaultdict(set) | |
n, m = map(int, sys.stdin.readline().split()) | |
for _ in range(m): | |
# a는 b보다 키가 작다 | |
a, b = map(int, sys.stdin.readline().split()) |
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()) | |
memo = {1:1,2:1,3:1,4:2,5:2} | |
def find_result(number : int) -> int: | |
if number in memo: | |
return memo[number] | |
memo[number] = find_result(number-1) + find_result(number-5) | |
return memo[number] | |
for _ in range(n): |
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 | |
maps = [] | |
birds = [] | |
r, c = map(int, sys.stdin.readline().split()) | |
for y in range(r): | |
arr = list(sys.stdin.readline().replace("\n","")) | |
maps.append(arr) | |
for x in range(len(arr)): | |
if arr[x] == "L": |
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 | |
r, c, n = map(int, sys.stdin.readline().split()) | |
bombs = [] | |
maps = [] | |
for y in range(r): | |
maps.append(list(sys.stdin.readline().replace("\n",""))) | |
for x in range(len(maps[0])): | |
if maps[y][x] == 'O': | |
maps[y][x] = (0+3, maps[y][x]) |