IT/coding study 44

[SWEA] 2383. 점심 식사시간(python)

계단마다 사람을 배치하는 것은 모든 경우의 수를 다 고려했다. 계단과 사람과의 거리를 나타내는 배열 order, 계단입구를 나타내는 배열 entry, 계단을 내려가는 횟수를 기록하는 배열 down을 만들어 구현하였다. from itertools import combinations T = int(input()) def downTo(people,stair): order,down,entry=[],[],[] stairSize=stair[2] for person in people: order.append(abs(stair[0]-person[0])+abs(stair[1]-person[1])) order.sort() time=0 while order: time+=1 while entry and len(down)

IT/coding study 2022.09.16

[acmicpc] 14891. 톱니바퀴(python)

시뮬레이션 import sys from collections import deque input=sys.stdin.readline wheels=[[]] for i in range(4): wheels.append(deque(list(input().strip()))) K=int(input()) for i in range(K): num, dir=map(int,input().split()) moves = [0] * 5 # 회전할 톱니바퀴 방향 체크 moves[num] = dir left=wheels[num][6] for j in range(num-1,0,-1): # 맨왼쪽까지 비교 if wheels[j][2]==left: break # 극이 같으면 stop moves[j]=-moves[j+1] left=wheel..

IT/coding study 2022.09.01

[programmers] 삼각 달팽이 (python)

빈 배열에 저 순서대로 채우고, 마지막에 합쳐서 출력해주었다. def solution(n): answer = [] arr=[[0]*n for _ in range(n)] arr_size=n+(n*n-n)//2 # 빈칸 제외한 부분 cnt=0 for j in range(0,n): for i in range(j,n): # 아래로 if arr[i][j]>0: continue arr[i][j]=arr[i-1][j]+1 cnt+=1 for i in range(j,n-j): # 오른쪽으로 if arr[n-1-j][i]>0: continue arr[n-1-j][i]=arr[n-1-j][i-1]+1 cnt+=1 for i in range(n-1,j,-1): # 대각선(\) 위로 if arr[i][i-j]>0: conti..

IT/coding study 2022.07.10

[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