본문 바로가기

분류 전체보기

(402)
[백준 3653번] 영화 수집 (Python3) import sys input = sys.stdin.readline def update(i,v): while i
[백준 2561번] 세 번 뒤집기 (Python3) from itertools import * def find(seq): start=end=0 for i in range(N+1): if i!=seq[i]: if not start: start=i end = i return (start,end) if start else (1,1) def Interval(seq,start,end): interval = []; s = start while s
[백준 2505번] 두 번 뒤집기 (Python3) from itertools import * def find(seq): start=end=0 for i in range(N+1): if i!=seq[i]: if not start: start=i end = i return (start,end) if start else (1,1) def reverse(seq,start,end): return seq[:start]+[*reversed(seq[start:end+1])]+seq[end+1:] N = int(input()) seq = [0]+[*map(int,input().split())] start,end = find(seq) interval = []; s = start while s
[백준 8012번] 한동이는 영업사원! (Python3) import sys input = sys.stdin.readline from collections import * def findparent(x,d): for i in range(l+1): if d&(1
[백준 2463번] 비용 (Python3) import sys input = sys.stdin.readline def findparent(x): if parent[x]!=x: parent[x] = findparent(parent[x]) return parent[x] N,M = map(int,input().split()) graph = sorted([[*map(int,input().split())] for i in range(M)],key=lambda x:-x[2]) parent = [i for i in range(N+1)]; group = [1]*(N+1) result = 0; connected = 0 for x,y,c in graph: if findparent(x)!=findparent(y): connected += group[parent[x]..
[백준 15972번] 물탱크 (Python3) import sys input = sys.stdin.readline from collections import * N,M,H = map(int,input().split()) tank = [[H]*M for i in range(N)] column = [[*map(int,input().split())] for i in range(N+1)] row = [[*map(int,input().split())] for i in range(N)] dq = [deque() for i in range(H+1)] for y in range(N): if row[y][0]!=-1: dq[row[y][0]].append((y,0)) if row[y][-1]!=-1: dq[row[y][-1]].append((y,M-1)) for x..
[백준 15480번] LCA와 쿼리 (Python3) import sys input = sys.stdin.readline from collections import * def findparent(x,d): for i in range(l+1): if d&(1
[백준 1415번] 사탕 (Python3) import sys,math,collections input = sys.stdin.readline N = int(input()) candy = [int(input()) for i in range(N)] S = sum(candy) candy = collections.Counter(candy); N = len(candy) DP = [[0]*(S+1) for i in range(N+1)]; DP[0][0] = 1 n = 0 for c in candy: for s in range(S+1): DP[n+1][s] = DP[n][s] for i in range(1,candy[c]+1): if s-i*csq: continue i = 2 while i*p