STUDY/Algorithm 402

[백준] 1987 알파벳 python(pypy), c

https://www.acmicpc.net/problem/1987 1987번: 알파벳 세로 R칸, 가로 C칸으로 된 표 모양의 보드가 있다. 보드의 각 칸에는 대문자 알파벳이 하나씩 적혀 있고, 좌측 상단 칸 (1행 1열) 에는 말이 놓여 있다. 말은 상하좌우로 인접한 네 칸 중의 한 칸으 www.acmicpc.net import sys; input = sys.stdin.readline def backtrack(r, c): global answer # 1 길이 갱신 answer = max(answer, len(alphabet)) # 2 탐색 for i in range(4): nr = r + dr[i] nc = c + dc[i] if 0

STUDY/Algorithm 2021.10.26

[백준] 14499 주사위 굴리기 python

https://www.acmicpc.net/problem/14499 14499번: 주사위 굴리기 첫째 줄에 지도의 세로 크기 N, 가로 크기 M (1 ≤ N, M ≤ 20), 주사위를 놓은 곳의 좌표 x y(0 ≤ x ≤ N-1, 0 ≤ y ≤ M-1), 그리고 명령의 개수 K (1 ≤ K ≤ 1,000)가 주어진다. 둘째 줄부터 N개의 줄에 지도 www.acmicpc.net # https://www.acmicpc.net/problem/14499 import sys; input = sys.stdin.readline def rollingDice(d, dice): # d: rolling direction 1 east, 2 west, 3 north, 4 south # dice: 1 top, 6 bottom #..

STUDY/Algorithm 2021.10.17

[백준] 9205 맥주 마시면서 걸어가기

https://www.acmicpc.net/problem/9205 9205번: 맥주 마시면서 걸어가기 송도에 사는 상근이와 친구들은 송도에서 열리는 펜타포트 락 페스티벌에 가려고 한다. 올해는 맥주를 마시면서 걸어가기로 했다. 출발은 상근이네 집에서 하고, 맥주 한 박스를 들고 출발한다. www.acmicpc.net import sys; input = sys.stdin.readline from collections import deque def bfs(graph): q = deque() q.append(0) end = len(graph) - 1 visit = [-1 for _ in range(len(graph))] visit[0] = 0 while q: cur = q.popleft() if cur == ..

STUDY/Algorithm 2021.10.14

[백준] 3190 뱀 python

https://www.acmicpc.net/problem/3190 3190번: 뱀 'Dummy' 라는 도스게임이 있다. 이 게임에는 뱀이 나와서 기어다니는데, 사과를 먹으면 뱀 길이가 늘어난다. 뱀이 이리저리 기어다니다가 벽 또는 자기자신의 몸과 부딪히면 게임이 끝난다. 게임 www.acmicpc.net # import sys; input = sys.stdin.readline from collections import deque N = int(input()) K = int(input()) apples = set([tuple(map(int, input().split())) for _ in range(K)]) L = int(input()) change = [input().split() for _ in ran..

STUDY/Algorithm 2021.10.14

[백준] 12865 평범한 배낭 python

https://www.acmicpc.net/problem/12865 12865번: 평범한 배낭 첫 줄에 물품의 수 N(1 ≤ N ≤ 100)과 준서가 버틸 수 있는 무게 K(1 ≤ K ≤ 100,000)가 주어진다. 두 번째 줄부터 N개의 줄에 거쳐 각 물건의 무게 W(1 ≤ W ≤ 100,000)와 해당 물건의 가치 V(0 ≤ V ≤ 1,000) www.acmicpc.net import sys; input = sys.stdin.readline N, K = map(int, input().split()) stuff_list = [tuple(map(int, input().split())) for _ in range(N)] memo = [[0 for _ in range(K + 1)] for _ in range..

STUDY/Algorithm 2021.10.12

[백준] 2565 전깃줄 python

https://www.acmicpc.net/problem/2565 2565번: 전깃줄 첫째 줄에는 두 전봇대 사이의 전깃줄의 개수가 주어진다. 전깃줄의 개수는 100 이하의 자연수이다. 둘째 줄부터 한 줄에 하나씩 전깃줄이 A전봇대와 연결되는 위치의 번호와 B전봇대와 연결되는 www.acmicpc.net import sys; input = sys.stdin.readline def checkCross(cables, ignore_idx_set): cross = [0 for _ in range(len(cables))] for i in range(len(cables)): if i in ignore_idx_set: continue s1, e1 = cables[i] for j in range(i + 1, len(c..

STUDY/Algorithm 2021.10.11

[백준] 2021 최소 환승 경로 python

https://www.acmicpc.net/problem/2021 2021번: 최소 환승 경로 첫째 줄에 역의 개수 N(1≤N≤100,000), 노선의 개수 L(1≤L≤100,000)이 주어진다. 다음 L개의 줄에는 각 노선이 지나는 역이 순서대로 주어지며 각 줄의 마지막에는 -1이 주어진다. 마지막 줄에는 출발 www.acmicpc.net import sys; input = sys.stdin.readline from collections import deque N, L = map(int, input().split()) station = [list() for _ in range(N+1)] line = [list() for _ in range(L)] for i in range(L): tmp = list(m..

STUDY/Algorithm 2021.08.15

[백준] 1238 파티, python

https://www.acmicpc.net/problem/1238 1238번: 파티 첫째 줄에 N(1 ≤ N ≤ 1,000), M(1 ≤ M ≤ 10,000), X가 공백으로 구분되어 입력된다. 두 번째 줄부터 M+1번째 줄까지 i번째 도로의 시작점, 끝점, 그리고 이 도로를 지나는데 필요한 소요시간 Ti가 들어 www.acmicpc.net from sys import stdin;input = stdin.readline from heapq import heappop, heappush def dijkstra(start): q = [(0, start)] while q: cur_w, cur = heappop(q) if distance_matrix[i][cur] > cur_w: distance_matrix[i]..

STUDY/Algorithm 2021.08.12

[백준] 3055 탈출 python

https://www.acmicpc.net/problem/3055 3055번: 탈출 사악한 암흑의 군주 이민혁은 드디어 마법 구슬을 손에 넣었고, 그 능력을 실험해보기 위해 근처의 티떱숲에 홍수를 일으키려고 한다. 이 숲에는 고슴도치가 한 마리 살고 있다. 고슴도치는 제 www.acmicpc.net from collections import deque import sys; input = sys.stdin.readline def bfs_step(start_array, visited, opposit_visited, isSonic): delta = [(-1, 0), (1, 0), (0, -1), (0, 1)] ret = deque() while start_array: cur_x, cur_y = start_ar..

STUDY/Algorithm 2021.08.10

[백준] 2573 빙산, python

https://www.acmicpc.net/problem/2573 2573번: 빙산 첫 줄에는 이차원 배열의 행의 개수와 열의 개수를 나타내는 두 정수 N과 M이 한 개의 빈칸을 사이에 두고 주어진다. N과 M은 3 이상 300 이하이다. 그 다음 N개의 줄에는 각 줄마다 배열의 각 행을 www.acmicpc.net import sys; input = sys.stdin.readline; H, W = map(int, input().split()) glacier = [list(map(int, input().split())) for _ in range(H)] answer = 0 while True: answer += 1 visit = [[0 for _ in range(W)] for _ in range(H)] ..

STUDY/Algorithm 2021.08.03