본문 바로가기

분류 전체보기

(402)
[프로그래머스] 경사로의 개수 (Python) dy,dx = [1,-1,0,0],[0,0,1,-1] mod = 10**9+7 def multiply(A,B): result = [[0]*L for i in range(L)] for y in range(L): for x in range(L): for i in range(L): result[y][x] += A[y][i]*B[i][x] result[y][x] %= mod return result def cal(A,N): if N==1: return A C1 = cal(A,N//2); C2 = multiply(C1,C1) return multiply(C2,A) if N%2 else C2 def solution(grid, D, k): global N,M,L N,M = len(grid),len(grid[0]); ..
[프로그래머스] 에어컨 (Python) def solution(T, T1, T2, a, b, onboard): if T
[프로그래머스] 상담원 인원 (Python) from heapq import * from itertools import * def solution(k, n, reqs): answer = 10**9 for com in combinations(range(1,n),k-1): com = [0,*com,n] S = 0 hq = [[] for i in range(k+1)] for a,b,c in reqs: while hq[c] and hq[c][0]
[백준 8980번] 택배 (Python) import sys from heapq import * input = sys.stdin.readline N,C = map(int,input().split()) box = [[*map(int,input().split())] for i in range(int(input()))] send = [[] for i in range(N+1)] receive = [0]*(N+1) for i,j,v in box: send[i].append((j,v)) hq = []; result = c = 0 for i in range(N+1): for j,v in send[i]: c += v receive[j] += v heappush(hq,(-j,v)) result += receive[i] c -= receive[i] while c..
[백준 2188번] 축사 배정 (Python) def DFS(i): if visited[i]: return visited[i] = 1 for j in graph[i]: if match[j]
[백준 16639번] 괄호 추가하기 3 (Python) N = int(input())//2+1; eq = input() DP = [[[1e12,-1e12] for i in range(N)] for i in range(N+1)] DP[1] = [(int(eq[i*2]),int(eq[i*2])) for i in range(N)] for l in range(2,N+1): for i in range(N-l+1): for ll in range(1,l): for m1 in range(2): for m2 in range(2): x = eval(str(DP[ll][i][m1])+eq[(i+ll)*2-1]+str(DP[l-ll][i+ll][m2])) DP[l][i] = min(DP[l][i][0],x),max(DP[l][i][1],x) print(DP[N][0][1]) DP..
[백준 16638번] 괄호 추가하기 2 (Python) N = int(input())//2 eq = input() result = -1e12 for bit in range(1
[백준 3153번] 타워 디펜스 (Python) d = [1,0,-1,0] dd = {(1,-1,-1,1):1,(1,1,-1,-1):2,(-1,1,1,-1):3,(-1,-1,1,1):4} def DFS(now): global id ID[now] = nowid = id stack.append(now) for next in graph[now]: if check[next]: continue if not ID[next]: id += 1 DFS(next) ID[now] = min(ID[now],ID[next]) if ID[now]==nowid: SCC.append([]) while 1: x = stack.pop() check[x] = 1; SCC[-1].append(x) if x==now: return def dfs(now): TF[now] = 1; TF[no..