BOJ/🥇18

★Math & Geometry Advanced I - 1 Solved★ ★ 1011 Fly me to the Alpha Centauri ★import sysinput=sys.stdin.readlinefor _ in range(int(input())): x,y=map(int,input().split()) diff=y-x closest_root=int(diff**(1/2)) if diff == (closest_root**2): print(closest_root*2-1) elif (diff-(closest_root**2)) 🍋 kn은 kn-1 / kn / kn+1 중 한 개만 가능 + 맨 앞과 맨 뒤의 거리 step은 1만 가능하다는 조건 하에 수학 규칙성을 찾는 문제→ y-x를 diff라고 한다면, 중복된 step 간격 없이 오름차순 -.. BOJ/🥇 2024. 4. 27.
★Implementation&Simluation Upper-Advanced I - 1 Solved★ ★ 19237 어른 상어 ★ import sys input=sys.stdin.readline from collections import deque N,M,k=map(int,input().split()) #NxNsize / M sharks / smell limit k trace=[] smell=[[0]*N for _ in range(N)] sharks=deque() shark_ds_priorities=[] #shark_ds dx,dy=['?',-1,1,0,0],['?',0,0,-1,1] num_of_sharks=M for i in range(N): l=list(map(int,input().split())) trace.append(l) for j in range(N): if l[j] != 0: sharks... BOJ/🥇 2024. 3. 3.
★Stack & Queue & Deque Advanced I - 1 Solved★ ★ 9935 문자열 폭발 ★ import sys input=sys.stdin.readline s=list(input().rstrip()) explode=list(input().rstrip()) explode_length=len(explode) ans=[] for x in range(len(s)): ans.append(s[x]) if s[x] == explode[-1]: if explode_length BOJ/🥇 2024. 2. 24.
★Two-Pointers Advanced I - 7 Solved★ ★ 15961 회전 초밥 ★ import sys input=sys.stdin.readline from collections import defaultdict N,d,k,c=map(int,input().split()) kinds=[int(input()) for _ in range(N)] y,ans,cnt,freq=0,0,0,defaultdict(int) for x in range(N): while cnt BOJ/🥇 2024. 2. 11.
★Implementation&Simluation Advanced I - 5 Solved★ ★ 21610 마법사 상어와 비바라기 ★ import sys input=sys.stdin.readline from collections import deque N,M=map(int,input().split()) baskets=[] for _ in range(N): baskets.append(list(map(int,input().split()))) moves=[] for _ in range(M): moves.append(tuple(map(int,input().split()))) clouds=deque([[N-2,0],[N-2,1],[N-1,0],[N-1,1]]) #(1) clouds moving dx,dy=[0,-1,-1,-1,0,1,1,1],[-1,-1,0,1,1,1,0,-1] for move in mo.. BOJ/🥇 2024. 1. 28.
★Backtracking Upper-Advanced I - 1 Solved★ ★ 9663 N-Queen ★ #n-queens #place n queens (not placed in the same row / col / diagonal dir) def track(x): global ans if x == N: #finished ans+=1 return else: for ny in range(N): if v1[ny] == v2[x+ny] == v3[x-ny] == False: v1[ny] = v2[x+ny] = v3[x-ny] = True track(x+1) v1[ny] = v2[x+ny] = v3[x-ny] = False N=int(input()) ans=0 v1=[False]*(N) #horizontal 0~(N-1) v2=[False]*(2*N-1) #diagonal (right.. BOJ/🥇 2024. 1. 24.
★Backtracking Advanced I - 3 Solved★ ★ 7490 0 만들기 ★ import sys input=sys.stdin.readline def track(nums,exp,start): if start == len(nums)+1: res=eval(exp) if res == 0: ans=[] for i in range(len(exp)): if i>=1 and exp[i-1].isdigit() and exp[i].isdigit(): ans.extend([' ',exp[i]]) else: ans.append(exp[i]) print(*ans,sep='') else: #needs to be added for x in [' ','+','-']: if x == ' ': exp+=str(start) track(nums,exp,start+1) exp=exp[:-1.. BOJ/🥇 2024. 1. 21.
★DP Upper-Advanced I - 8 Solved★ ★ 12015 가장 긴 증가하는 부분 수열 2 ★ import sysinput=sys.stdin.readlineN=int(input())A=list(map(int,input().split()))#binary searchdef binary_search(l, x): start,end=0,len(l)-1 while start 🍜 LIS(O(nlogn)) 문제★ 12738 가장 긴 증가하는 부분 수열 3 ★ 🍜 수열 원소가 음수여도 LIS(O(nlogn)) 알고리즘은 성립★ 1365 꼬인 전깃줄 ★ import sysinput=sys.stdin.readlineN=int(input())n=list(map(int,input().split()))de.. BOJ/🥇 2024. 1. 5.
★Binary Search Advanced I - 2 Solved★ ★ 2295 세 수의 합 ★ import sys input=sys.stdin.readline def binary_search(target, l): start,end=0,len(l)-1 while start target: end=mid-1 else: start=mid+1 return False #O(N^2logN) N=int(input()) U=set() for _ in range(N): U.add(int(input())) L=list(U) L.sort() two=[] for x in range(len(L)): for y in range(x,len(L)): two.append(L[x]+L[y]) two.sort() for x in range(len(L)-1,-1,-1): for y in range(0,x).. BOJ/🥇 2023. 12. 29.
★Coordinate Compression Advanced - 2 Solved★ ★ 18869 멀티버스 II ★ import sys input=sys.stdin.readline from collections import defaultdict M,N=map(int,input().split()) cu_list,ans=[],0 def get_compressed_coordinate(l): sort_l = sorted(set(l)) cd = {sort_l[i]: i for i in range(len(sort_l))} x = [cd[n] for n in l] return x for _ in range(M): universe=list(map(int,input().split())) compressed_universe = get_compressed_coordinate(universe) cu_list.. BOJ/🥇 2023. 12. 28.
★Tree Advanced I - 1 Solved★ ★ 1068 트리 ★ import sys input=sys.stdin.readline N=int(input()) l=list(map(int,input().split())) tree=[[] for _ in range(N)] visited=[[] for _ in range(N)] start_node = 51 ans = 0 def dfs(tree, visited, delete_node, start_node): global ans visited[start_node] = True if len(tree[start_node]) == 0: #leaf-node ans += 1 else: len_child = len(tree[start_node]) if len_child == 1: #one child node child .. BOJ/🥇 2023. 12. 22.
★BFS&DFS Advanced I - 10 Solved★ ★ 7576 토마토 ★ (최단경로) import sys input=sys.stdin.readline from collections import deque M,N=map(int,input().split()) graph=[] starts=[] depths=[[0]*M for _ in range(N)] visited=[[False]*M for _ in range(N)] def BFS(graph, depths, starts, visited): queue = deque(starts) dx,dy=[0,0,-1,1],[-1,1,0,0] while queue: v = queue.popleft() for i in range(4): nx,ny=v[0]+dx[i],v[1]+dy[i] if 0 BOJ/🥇 2023. 12. 15.