본문 바로가기

분류 전체보기

(402)
[백준 2086번] 피보나치 수의 합 (Python3) import sys input = sys.stdin.readline memory = {1:1,2:1,3:2,4:3,5:5} def Fibo(n): if memory.get(n): return memory[n] else: if n%2 == 1: memory[n] = (Fibo(n//2)**2+Fibo(n//2+1)**2)%1000000000 else: memory[n] = (Fibo(n+1)-Fibo(n-1))%1000000000 return memory[n] a,b = map(int,input().split()) print((Fibo(b+2)-Fibo(a+1))%1000000000) 일단 풀이는 매우 쉽다. 피보나치 수열의 합을 쭉 나열해보면 0 1 2 4 7 12 20 33 54 88 ... 이 나오는..
[백준 4574번] 스도미노쿠 (Python3) import sys input = sys.stdin.readline dy = [1,-1,0,0] dx = [0,0,1,-1] def put(n,c): y,x = c y,x = ord(y)-65,int(x)-1 board[y][x] = n checky[y][n] = 1 checkx[x][n] = 1 checksq[(y//3,x//3)][n] = 1 def check(y,x,n): if checky[y][n] or checkx[x][n] or checksq[(y//3,x//3)][n]: return True return False def sudoku(y,x): global finish if finish: return if y == 9: finish = True print("Puzzle",test) print..
[백준 2307번] 도로검문 (Python3) import sys input = sys.stdin.readline from heapq import heappush,heappop INF = sys.maxsize def Dijkstra(): DP = [INF]*N hq = [] heappush(hq,(0,0,0)) while hq: w,now,last = heappop(hq) if DP[now]
[백준 5670번] 휴대폰 자판 (Python3) import sys input = sys.stdin.readline while True: try: N = int(input()) except: break Dict = {i:{} for i in "abcdefghijklmnopqrstuvwxyz"} words = [] for i in range(N): word = input().strip() words.append(word) last = Dict for letter in word: if not last.get(letter): last[letter] = {} last = last[letter] last[0] = {} cnt = 0 for word in words: last = Dict for letter in word: if len(last) != 1: cn..
[백준 1655번] 가운데를 말해요 (Python3) import sys input = sys.stdin.readline from heapq import heappush,heappop N = int(input()) maxhq = [] minhq = [] heappush(maxhq,10**6) heappush(minhq,10**6) for i in range(N): n = int(input()) if n>minhq[0]: heappush(minhq,n) else: heappush(maxhq,-n) while True: if len(minhq)>len(maxhq): heappush(maxhq,-heappop(minhq)) continue if len(maxhq)>len(minhq)+1: heappush(minhq,-heappop(maxhq)) continue ..
[백준 1102번] 발전소 (Python3) import sys input = sys.stdin.readline INF = 10**6 def DFS(bit): if bin(bit).count("1") >= P: DP[bit] = 0 return if DP[bit] != INF: return for next in range(N): if bit&(1
[백준 1081번] 합 (Python3) import sys input = sys.stdin.readline from collections import deque def page(N,n): c = len(str(N))-1 a = int(str(N)[0]) if c == 0: if n > a: return 0 else: return 1 result = a*c*10**(c-1) + page(N-a*10**c,n) if n > a: return result if n == a: return result + (N-a*10**c+1) return result + 10**c def sumpage(N): result = 0 for n in range(1,10): result += page(N,n)*n return result L,U = map(int,inpu..
[백준 1036번] 36진수 (Python3) import sys input = sys.stdin.readline from collections import deque n36 = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ" def caldiff(num): L = len(num) for i in range(L): n = int(num[L-i-1],36) diff[n] += (35-n)*(36**i) def make36(x): if x == 0: return 0 dq = deque() while x: dq.appendleft(n36[x%36]) x //= 36 return "".join(dq) N = int(input()) SUM = 0 diff = [0]*36 for i in range(N): num = input().stri..