320x100 Blog189 [CLASS 3]백준 7662번 - 이중 우선순위 큐 7662번 : 이중 우선순위 큐 힙은 힙이지만, 최대와 최소를 모두 구할 수 있는 힙을 구현해야 한다. 힙큐 모듈과 각각의 요소에 True 혹은 False를 같이 넣음으로써 판단해보려고 했지만.. 시간 초과에 걸려버렸다. 내 코드(시간 초과): # dawitblog.tistory.com from sys import stdin input = stdin.readline import heapq for _ in range(int(input())): maxHeap = [] minHeap = [] size = 0 for _ in range(int(input())): cmd = input().split() if cmd[0] == 'I': # 두 큐에 모두 삽입 heapq.heappush(maxHeap,[-int(cm.. 2021. 2. 16. [CLASS 3]백준 1107번 - 리모컨 1107번 : 리모컨 음... 조건을 통해 채널입력으로 갈 수 있는 가장 가까운 수를 얻어내는 방식으로 풀려고 했는데, 생각보다 너무 고려할 것이 많고 복잡해서 그냥 포기하고(..) 브루트 포스로 풀었다. 자존심 상해... 브루트 포스로 풀면 잘~ 풀린다. 내 코드: # dawitblog.tistory.com # 브루트포스 ch,m = int(input()),int(input()) count = abs(100-ch) if m: l = input().split() # 고장난 버튼 빼고 누를 수 있는 버튼 available = [str(k) for k in range(10) if str(k) not in l] if available: for num in range(1000001): num = str(num).. 2021. 2. 16. [CLASS 3]백준 11403번 - 경로 찾기 11403번 : 경로 찾기 처음에는 약간 재귀의 냄새(?)가 났는데 하다보니 결국 bfs로 풀게 되었다. bfs로 풀면 장점은 속도가 좀 빠르다는 것이고 단점은 구현이 약간 더 어렵다. 내 코드(BFS): # dawitblog.tistory.com from sys import stdin from collections import deque input = stdin.readline n = int(input()) # 입력받은 행렬 mat = [list(map(int,input().split())) for _ in range(n)] # 출력할 행렬 mat2 = [] # 각 정점마다 수행 for i in range(n): temp = mat[i].copy() visited = [False] * n queue =.. 2021. 2. 13. [CLASS 3]백준 11286번 - 절댓값 힙 11286번 : 절댓값 힙 직접 구현하지는 않고 힙큐 모듈을 사용했다. 내 코드: # dawitblog.tistory.com from sys import stdin import heapq input = stdin.readline plusHeap = [] minusHeap = [] for _ in range(int(input())): req = int(input()) if req: if req > 0: heapq.heappush(plusHeap,req) else: heapq.heappush(minusHeap,-req) else: if not plusHeap and not minusHeap: print(0) elif not plusHeap: print(-heapq.heappop(minusHeap)) elif.. 2021. 2. 13. 이전 1 ··· 20 21 22 23 24 25 26 ··· 48 다음