본문 바로가기
320x100

PS84

[CLASS 3]백준 11279번, 1927번 - 최대 최소 힙 11279번 : 최대 힙 최대 힙을 구현하는 문제이다. 자료구조를 잘 이해하고 있다면 직접 구현할 수 있다. 나는 정말 열심히 최대 힙을 구현했는데 시간 초과에 걸렸다... 시간 제한이 매우 빡세다 그래서 갈아엎고 구글에서 최대 힙에 관해 검색한 뒤 따라 구현했는데도 틀렸다. 내 코드(틀렸습니다): import sys input = sys.stdin.readline class maxHeap: def __init__(self): self.data = [None] def insert(self,item): self.data.append(item) i = len(self.data) - 1 while i > 1: if self.data[i] > self.data[i//2]: self.data[i],self.dat.. 2021. 2. 11.
[CLASS 3]백준 11724번, 1389번, 1697번, 2178번, 2667번 11724번 : 연결 요소의 개수 어... 그냥 그래프 탐색 문제이다. dfs혹은 bfs중 어떤 것으로 풀든 상관 없다. 내 코드: # dawitblog.tistory.com from sys import stdin from collections import deque input = stdin.readline n,m = map(int,input().split()) # 정점 저장 nodes = [[] for _ in range(n+1)] # 방문 처리 visited = [False] * (n+1) for _ in range(m): i,j = map(int,input().split()) nodes[i].append(j) nodes[j].append(i) # 너비 우선 탐색 def bfs(start): glob.. 2021. 2. 9.
[CLASS 3]백준 5525번, 18870번, 1074번 5525번 : IOIOI 별로 어려워보이지 않는 문자열 문제이다. 무난하게 풀 수 있었다. 내 코드: n,m,s = int(input()),int(input()),input() ls = list(s) # 직전에 뽑은 글자가 O였는지 확인 wasO = True # 2회 이전에 I가 있었는지 확인 isOpen = False tempCount = 0 realCount = 0 while ls: char = ls.pop() # I를 뽑았는데 직전이 O였다면 if char == 'I' and wasO: wasO = False # 2회 이전에 I가 있었다면 if isOpen: tempCount += 1 else: isOpen = True # O를 뽑았는데 직전에 O가 아니었다면(I였다면) elif char == 'O.. 2021. 2. 9.
[CLASS 3]백준 5430번 : AC 5430번 : AC 처음에 이 문제를 접했을 때는, 그냥 reverse로 뒤집고 pop몇번 하면 되는거 아닌가? 라고 생각했다. 그래서 다음과 같은 코드를 작성했다. 내 코드(시간 초과): from sys import stdin input = stdin.readline for _ in range(int(input())): cmd = input().rstrip() length = int(input()) if length: li = list(input()[1:-2].split(',')) else: _ = input() li = [] Dcount = cmd.count('D') if Dcount > length: print('error') continue elif Dcount == length: print('[.. 2021. 2. 5.