백준 13

[acmicpc] 10800. 컬러볼(python)

- 구간합 알고리즘 N이 200,000까지라서 이중 for문으로 구할 경우, 100억이 넘어가서 당연히 시간초과가 될 것이다. 따라서 구간합 알고리즘을 사용하는데, 이는 시간복잡도가 O(n)이다. 추가테스트 케이스 > 색과 무게가 겹치는 여러 경우를 고려하여 구성했다. 6 2 3 1 10 2 10 1 10 3 11 4 14 정답 0 3 0 3 33 44 import sys input = sys.stdin.readline N = int(input()) arr = [] result = [0] * (N + 1) color = [0] * (N + 1) weight = [0] * 2001 for i in range(N): e1, e2 = map(int, input().split()) arr.append((e2,e..

IT/coding study 2022.06.18

[acmicpc] 16918. 봄버맨(python)

유형: 시뮬레이션 1. 초기 폭탄 칸을 0, 빈 칸을 -2로 셋팅해놓는다. 2. 1초 지날 때마다 모든 칸을 1씩 증가시킨다. 2-1) 칸의 값이 3이라면, 폭탄을 폭발시킨다. => 자신의 칸과 주위의 칸을 -1로 셋팅해놓는다. 3. 출력할 때, 다시 숫자를 원래 기호로 되돌린다. import sys input=sys.stdin.readline R,C,N=map(int,input().split()) arr=[] answer=[] dirs=[(1,0),(0,1),(-1,0),(0,-1)] for _ in range(R): tmp=list(input().strip()) sample=[] for t in tmp: if t=='O': sample.append(0) else: sample.append(-2) ar..

IT/coding study 2022.06.12

[acmicpc] 3020. 개똥벌레 (python)

구간합 알고리즘 import sys input=sys.stdin.readline n, h = map(int, input().split(" ")) down = [0] * h # 석순 up = [0] * h # 종유석 for i in range(n): end=int(input())-1 if i%2==0: down[end]+=1 else: up[end]+=1 for i in range(h - 2, -1, -1): down[i] += down[i + 1] up[i] += up[i + 1] down.reverse() result=[] for j in range(len(down)): result.append(down[j]+up[j]) # 각 높이마다 장애물 합 mins=min(result) cnt=result.co..

IT/coding study 2022.03.10