목록Algorithm/Ch 3. 응용 자료구조 (5)
토니의 연습장
https://www.acmicpc.net/problem/5525N = int(input())M = int(input())S = input()# 해쉬 값 계산 위한 준비mod = 1e9 + 7 # 10억 7 (큰 소수)po = [0]*Mpo[0] = 1for i in range(1,M): po[i]=po[i-1]*31 % mod# PnPn = "I"for i in range(N): # O가 N개 Pn += "OI" K = len(Pn)# Pn의 해쉬 값 계산Pn_hash = 0for i in range(K): Pn_hash *= 31 Pn_hash %= mod Pn_hash += ord(Pn[i])-ord('A')+1 Pn_hash %= mod# S[0:len..
https://www.acmicpc.net/problem/1417from queue import PriorityQueueN = int(input())P = [0]*Nfor i in range(N): P[i] = int(input()) pq = PriorityQueue() # default : 최솟값을 우선적으로 반환하는 큐for i in range(1,N): # 기호1번 제외 pq.put(-P[i]) # -를 붙임으로써 음수들로 들어가게끔 처리 if N == 1: print(0)else: count = 0 while True: max_value = -pq.get() # 음수중 최소값 반환에 앞에 -를 붙임으로써 절대값 기준 최댓값이 반환되게..
https://www.acmicpc.net/problem/2606N = int(input())M = int(input())adj = [[] for _ in range(N)] # 인접 리스트 [ [], [], ... , []]for _ in range(M): a, b = list(map(int, input().split())) adj[a-1].append(b-1) adj[b-1].append(a-1) check = [0]*Ncheck[0] = 1while True: new = False # if updated for i in range(N): if check[i] == 0: continue # chec..
https://www.acmicpc.net/problem/1068N = int(input())parent = list(map(int, input().split()))R = int(input())# 루트 노드 찾기for i in range(N): if parent[i]==-1: root = i break # 사라지는 노드 판별black = [0]*Nfor i in range(N): u = i while True: if u == R: black[i] = 1 break if u == root: break u = parent[u] # 자식 있는..
https://www.acmicpc.net/problem/2559N, K = list(map(int, input().split()))A = list(map(int, input().split()))# 누적합psum = [0]*Npsum[0] = A[0]for i in range(1,N): psum[i] = psum[i-1]+A[i] # 연속된 K일 온도합temp_sum = []for i in range(0,N-K+1): # i ~ i+K-1 if i==0: sum=psum[i+K-1] else: sum=psum[i+K-1]-psum[i-1] temp_sum.append(sum)print(max(temp_sum)) https://www...