코테 준비
-
[백준] 25501. 재귀의 귀재코테 준비/구현 2023. 1. 18. 02:48
def recursion(s,l,r): global count if l>=r: return 1 elif s[l]!=s[r]: return 0 else: count+=1 return recursion(s,l+1,r-1) def isPalindrome(s): return recursion(s,0,len(s)-1) t=int(input()) for i in range(t): s=input() count=1 print(isPalindrome(s),count)
-
[백준] 1074. Z (다시 풀기)코테 준비/분할정복 2023. 1. 15. 02:45
import sys n,r,c=map(int,sys.stdin.readline().split()) def Z(n,r,c,count): if n==1: if r==0 and c==0: print(count) if r==0 and c==1: print(count+1) if r==1 and c==0: print(count+2) if r==1 and c==1: print(count+3) else: #왼쪽 위는 숫자를 늘릴 필요 없음 if r=(2**n)//2: #오른쪽 위 count+=((2**n)//2)**2 c-=((2**n)//2) elif r>=(2**n)//2 and c=(2**n)//2 and c>=(2**n)//2: #오른쪽 아래 count+=((2**n)//2)**2*3 r-=((2**n)//2)..
-
[백준] 1193. 분수 찾기코테 준비/구현 2023. 1. 14. 01:54
x=1일때 (1,1) x=2일때 (1,2) x=4일때 (3,1) . x=(i*(i+1)/2)+1일때 i가 짝수면 (i+1,1), 홀수면 (1,i+1) import sys x=int(sys.stdin.readline()) for i in range(x): if ((i*(i+1))//2)+1x: break a=(i+1)-(x-((i*(i+1))//2)-1) b=1+(x-((i*(i+1))//2)-1) if i%2==0: print(str(a)+"/"+str(b)) else: print(str(b)+"/"+str(a))
-
[백준] 7662. 이중우선순위큐코테 준비/Stack, Queue 2023. 1. 13. 02:26
시간초과때문에 heapq를 사용해야 시간을 단축시킬 수 있다. list로 하면 시간복잡도가 O(n)인데 heapq로 하면 O(log2n)이라서 heapq로 최소힙, 최대힙 따로 만들어서 해야함 import heapq import sys t=int(sys.stdin.readline()) for i in range(t): n=int(sys.stdin.readline()) minqueue=[] #최소 힙 maxqueue=[] #최대 힙 visited=[0]*n for j in range(n): pqueue=sys.stdin.readline().rstrip() if pqueue.split()[0]=='I': x=int(pqueue.split()[1]) heapq.heappush(minqueue,(x,j)) he..
-
-
[프로그래머스] 이중우선순위큐코테 준비/Stack, Queue 2023. 1. 12. 20:53
def solution(operations): queue=[] for i in operations: if i.split()[0]=='I': queue.append(int(i.split()[1])) elif i=='D 1': if queue: queue.sort() queue.pop() elif i=='D -1': if queue: queue.sort(key=lambda x:-x) queue.pop() if queue: queue.sort(key=lambda x:-x) return [queue[0],queue[-1]] else: return [0,0]