전체 글
-
2776. [Python]암기왕Python_알고리즘/Silver IV 2025. 1. 14. 04:09
1. 문제 https://www.acmicpc.net/problem/2776 2. 접근 방법 시간 제한: 2초메모리 제한: 256MB딕셔너리 3. 파이썬 코드 import sys# 많은 인풋처리T = int(sys.stdin.readline())# 테스트 케이스 반복문for i in range(1,T+1): # 딕셔너리 선언 num_dict = {} N = int(sys.stdin.readline()) nums = list(map(int,sys.stdin.readline().split())) M = int(sys.stdin.readline()) nums_check = list(map(int,sys.stdin.readline().split())) # 딕셔너리에 값 저장 ..
-
14562. [Python]태권왕Python_알고리즘/Silver I 2025. 1. 2. 18:46
1. 문제 https://www.acmicpc.net/problem/14562 2. 접근 방법 시간 제한: 2초메모리 제한: 128MB그래프 이론너비 우선 탐색 3. 파이썬 코드 import sysfrom collections import deque# BFS 통한 탐색def BFS(start,target): # 초기값으로 시간, 시작점, 목표점 q = deque([(0,start,target)]) while q: time, current, target = q.popleft() # 현재 점수가 목표점수와 같은 경우 if current == target: # 시간 출력 print(time) br..
-
31263. [Python]대한민국을 지키는 가장 긴 힘Python_알고리즘/Silver III 2025. 1. 2. 17:43
1. 문제 https://www.acmicpc.net/problem/31263 2. 접근 방법 시간 제한: 1초메모리 제한: 1024MBTop-Down 3. 파이썬 코드 N = int(input())number = input()# 사람 수 체크cnt = 0# 인덱스 접근index = N-1# 인덱스 값이 0 보다 크거나 같을때 반복while index >= 0: # 만약 현재 인덱스 -2 값이 0 보다 작은경우 사람 추가 후 탈출 if index - 2 641: # 현재 일수를 나눠서 그 자리수 체크 day_str = str(day) # 만약 자리수가 한자리면 인덱스 -1 두자리면 -2 if int(day_str..
-
14655. [Python]욱제는 도박쟁이야!!Python_알고리즘/Silver V 2025. 1. 2. 17:09
1. 문제 https://www.acmicpc.net/problem/14655 2. 접근 방법 시간 제한: 2초메모리 제한: 256MB그리디 3. 파이썬 코드 N = int(input())# 첫 경기 값들first = list(map(int,input().split()))# 둘째 경기 값들second = list(map(int,input().split()))# 첫 경기 합first_max = 0# 둘째 경기 합second_max = 0# 첫 경기합 절대값for i in first: first_max += abs(i)# 둘째 경기합 절대값for i in second: second_max += abs(i)# 두 경기합 더하기print(first_max + second_max) 4. 문제를 풀고난..
-
1256. [Python]사전Python_알고리즘/Gold II 2024. 11. 20. 16:43
1. 문제 https://www.acmicpc.net/problem/1256 2. 접근 방법 시간 제한: 2초메모리 제한: 128MB조합론 3. 파이썬 코드 def searching(N, M, K): result = [] total = N + M # 총 길이가 0보다 클때까지 while total > 0: # a의 개수가 0보다 큰 경우 만들 수 있는 조합 식 계산 if N > 0: count = comb(N + M - 1, M) else: count = 0 # K번 째 수가 위에서 계산산 조합식 count 값보다 작거나 같은 경우 a 로 시작 혹은 끝 if K comb(N + ..
-
1208. [Python]부분수열의 합 2Python_알고리즘/Gold I 2024. 11. 1. 22:58
1. 문제 2. 접근 방법 시간 제한: 1초메모리 제한: 256MB이분 탐색중간에서 만나기 3. 파이썬 코드 # input 값N, S = map(int,input().split())# 숫자 리스트num_list = list(map(int,input().split()))# 정렬num_list.sort()# 딕셔너리를 통해서 몇개 나왔는지 체크answer_dict = {}# 왼쪽 부분 합left_sum = []# 오른쪽 부분 합right_sum = []# 왼쪽 부분 합 구하는 로직for i in range(N//2): left_length = len(left_sum) for j in range(left_length): left_sum.append(left_sum[j]+num_list..
-
3980. [Python]선발 명단Python_알고리즘/Gold V 2024. 10. 21. 18:40
1. 문제 https://www.acmicpc.net/problem/3980 2. 접근 방법 시간 제한: 1초메모리 제한: 128MB백트래킹브루트 포스 3. 파이썬 코드 import sysinput = sys.stdin.readline# 백트래킹def DFS(start): # 최대값 저장 global max_value # 값 저장 global value # 최종 11에 도달했을 때 if start == 11: # 최대 값보다 값이 크면 갱신 if max_value 4. 문제를 풀고난 후 생각 모든 경우의 수를 다 탐색하면서 알고리즘을 돌리면 된다.백트래킹을 진행하되 0 번인덱스를 기준으로 백트래킹을 해주면 원하는 결과값이 나온다.테스트 케이스 개..
-
14502. [Python]연구소Python_알고리즘/Gold IV 2024. 10. 17. 21:06
1. 문제 https://www.acmicpc.net/problem/14502 2. 접근 방법 시간 제한: 1초메모리 제한: 128MB그래프 탐색브루트 포스 3. 파이썬 코드 from itertools import combinations# DFS 로직def DFS(start): stack = [start] global max_value global check_cnt while stack: next = stack.pop() for k in range(4): ny = next[0] + direction[k][0] nx = next[1] + direction[k][1] if 0 max_value: ..
-
2631. [Python]줄세우기Python_알고리즘/Gold IV 2024. 10. 12. 02:04
1. 문제 https://www.acmicpc.net/problem/2631 2. 접근 방법 시간 제한: 1초메모리 제한: 128MBLIS(DP) 알고리즘 3. 파이썬 코드 import sysinput = sys.stdin.readlineN = int(input())num_list = []# 숫자 리스트 추가for _ in range(N): num_list.append(int(input()))# LIS 알고리즘 적용할 리스트long_length = [0] * N# LIS 알고리즘for i in range(N): # i 번 값 1로 초기화 long_length[i] = 1 # 0번 인덱스부터 i 번 인덱스까지 반복문진행 for j in range(0,i): # i 번..
-
1469. [Python]숌 사이 수열Python_알고리즘/Gold V 2024. 10. 8. 22:34
1. 문제 https://www.acmicpc.net/problem/1469 2. 접근 방법 시간 제한: 2초메모리 제한: 128MB브루트 포스백트래킹 3. 파이썬 코드 import sys# 재귀 제한 해제sys.setrecursionlimit(10000)# 백트래킹def backtracking(cnt): # 리스트 2배의 길이가 됐을때 종료 if cnt == N*2: print(*answer) exit() return # 리스트 안의 값 순회 for value in num_list: # 딕셔너리 값이 존재할 경우 if num_dict[value] > 0: # 딕셔너리 값이 2인 경우 백트래킹 ..