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 | |
| # F : 건물의 총 높이 | |
| # G : 목적지 | |
| # U : 위로 한 번에 이동할 수 있는 폭 | |
| # D : 아래로 한 번에 이동할 수 있는 폭 | |
| # 현재위치 = S. | |
| F, S, G, U, D = map(int, sys.stdin.readline().split()) | |
| def bfs(start, end, up, down, F): |
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 | |
| # 남 : 스위치번호가 자기 배수이면, 상태 바꾼다. | |
| # 여 : 현 위치 중심으로 좌우대칭이면서 가장 많은 스위치를 포함하는 구간 전부 바꿈. | |
| SPLITS = 20 | |
| # 좌우대칭이면서 가장 긴 거리 찾는 함수 | |
| def find_symmetric(arr, idx): | |
| r, l = idx - 1, idx + 1 | |
| min_r, max_l = idx, idx | |
| while r > 0 and l < 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
| import sys | |
| from copy import deepcopy | |
| dirs = [(-1,0),(-1,-1),(0,-1),(1,-1),(1,0),(1,1),(0,1),(-1,1)] | |
| maps = [[0 for _ in range(4)] for _ in range(4)] | |
| fish_dict = dict() | |
| y, x = 0, 0 | |
| for _ in range(4): | |
| arr = list(map(int, sys.stdin.readline().split())) | |
| for i in range(0, len(arr), 2): |
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 itertools import chain | |
| r, c, t = map(int, sys.stdin.readline().split()) | |
| maps = [list(map(int, sys.stdin.readline().split())) for _ in range(r)] | |
| pos = 0 | |
| # 공기청정기 위치 확인 | |
| for y in range(r): | |
| if maps[y][0] == -1: | |
| pos = y | |
| break |
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 check_shape(start, color, row_num, board): | |
| y, x = start | |
| color = board[y][x] | |
| coord = set() | |
| color_cnt, black_cnt = 0, 0 | |
| if row_num == 2 and y - 2 >= 0: | |
| # [1,#], | |
| # [1,#], | |
| # [1,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, m, h = map(int, sys.stdin.readline().split()) | |
| table = [[0 for _ in range(n+2)] for _ in range(h)] | |
| # table[y][x] = x와 x+1이 y번째 row에서 연결되어 있다. | |
| answer = 4 | |
| for _ in range(m): | |
| a, b = map(int, sys.stdin.readline().split()) | |
| table[a-1][b] = 1 | |
| def check(maps): |
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, l = map(int, sys.stdin.readline().split()) | |
| arr = list(map(int, sys.stdin.readline().split())) | |
| d = [0 for _ in range(n)] | |
| window = deque() | |
| for idx in range(n): | |
| # window의 마지막 값보다 input으로 넣을 값이 작은 경우 | |
| # 최솟값은 어차피 input값이 될 것이므로, window에 굳이 넣을 필요가 없다 | |
| while window and window[-1][1] > arr[idx]: |
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 itertools import combinations | |
| import math | |
| def solution(nums): | |
| candidates = combinations(nums, 3) | |
| answer = 0 | |
| for item in candidates: | |
| sums = sum(item) | |
| is_prime = True | |
| for i in range(2, int(math.sqrt(sums)) + 1): | |
| if sums % i == 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(n): | |
| cnt = 0 | |
| while n > 0: | |
| q, r = divmod(n, 2) | |
| n = q | |
| if r != 0: | |
| cnt += 1 | |
| return cnt |
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
| # deque rotate 양수 = 시계방향, 음수 = 반시계방향 | |
| from collections import deque | |
| import sys | |
| from itertools import chain | |
| def bfs(maps, y, x): | |
| dirs = [(0,1),(0,-1),(1,0),(-1,0)] | |
| queue = deque() | |
| value = maps[y][x] | |
| queue.append((y, x)) |