목록알고리즘/문제 (27)
어디까지 갈 수 있을까?

문제링크 www.acmicpc.net/problem/3190 사과를 먹으면 몸이 길어지는 뱀이 몇 초부터 이동을 못하게 되는지 구하는 문제이다 [답코드] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 import sys input=sys.stdin.readline n=int(input()) #보드의 크기 board=[[-1]*n..
문제링크 programmers.co.kr/learn/courses/30/lessons/60057 카카오 문제는 예제외에 다른 테스트케이스들도 많이 생각하고 돌려야하는 것 같다 [답코드] 시도 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 def solution(s): #시뮬레이션 문제? answer = len(s) if len(s)==1: return 1 #반복 문자열 갯수 for i in range(1, (len(s) // 2)+1): simul_answer=0 #인덱스 re=0 #반복 횟수 for j in range(0, len(s)-i, i): if s[j:j+i]==s[j+i:j+2*i]:..

문제링크 programmers.co.kr/learn/courses/30/lessons/42891 [답코드] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 import heapq def solution(food_times, k): q=[] #(시간, 인덱스) for i in range(len(food_times)): heapq.heappush(q, (food_times[i], i+1)) pre_food=0 now_food=q[0][0] n=len(food_times) while True: #바퀴수당으로 생각하기 if k - (now_food - pre_food) *n

문제링크 www.acmicpc.net/problem/10775 고통의 시간을 거치고 드디어 맞았다!! 🎉👏🎉👏 [답코드] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 import sys input=sys.stdin.readline sys.setrecursionlimit(10**6) # 최대 재귀 깊이 제한 늘림 # 특정 원소가 속한 집합을 찾기 def find_parent(parent, x): # 루트 노드가 아니라면, 루트 노드를 찾을 때까지 재귀적으로 호출 if parent[x] != x: parent[x] = find_parent(parent..

문제링크 www.acmicpc.net/problem/2224 [답코드] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 import sys input = sys.stdin.readline INF = int(1e9) # 무한을 의미하는 값으로 10억을 설정 # 2차원 리스트(그래프 표현)를 만들고, 모든 값을 무한으로 초기화 graph = [[INF] * (52) for _ in range(52)] for..
문제링크 www.acmicpc.net/problem/11403 [답코드] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 import sys input = sys.stdin.readline INF = int(1e9) # 무한을 의미하는 값으로 10억을 설정 n = int(input()) graph=[] for _ in range(n): graph.append(list(map(int, input().split()))) # 점화식에 따라 플로이드 워셜 알고리즘을 수행 for k in range(n): for a in range(n): for b in range(n): if graph[a][k] and graph[k][b] : graph[a][b]=1..
문제링크 www.acmicpc.net/problem/2110 이분탐색 진리의 라이브러리 bisect를 사용하자 [답코드] 1 2 3 4 5 6 7 8 9 10 11 12 13 import sys from bisect import bisect_left, bisect_right input=sys.stdin.readline for _ in range(int(input())): n, m=map(int, input().split()) a=list(map(int, input().split())) b=list(map(int, input().split())) a.sort() count=0 for i in b: count+=len(a)-bisect_right(a, i) print(count) cs

문제링크 www.acmicpc.net/problem/2606 [답코드] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 import sys from collections import deque input=sys.stdin.readline def bfs(): q=deque() q.append(1) visited[1]=True global result while q: v=q.popleft() for i in graph[v]: if not visited[i]: q.append(i) visited[i]=True result+=1 n=int(input()) graph=[[] for _ in ..