cod
본문 바로가기

전체 글

(51)
[백준] 런타임에러 런타임에러 원인 배열 인덱스 범위를 벗어났을 경우 0으로 나눌 때 사용하는 라이브러리에서 예외를 발생시켰을 때 재귀 호출이 너무 길어질 때 2798 블랙잭 / Python 추측 에러 원인: 1) 인덱스 에러 더보기 from itertools import combinations N, M = map(int, input().split()) lst = list(map(int, input().split())) c = list(combinations(lst, 3)) sum_c = list(map(sum, c)) diff = list(map(lambda x:x-M, sum_c)) # 음수 중 가장 큰 수 m = -9999 for i in diff: if im: m = i if m != -9999: print(sum_..
[백준] 시간초과 2805 나무자르기 / Python N이 백만이기 때문에 N크기의 리스트를 끝에서부터 돌면서 확인하는 것은 시간복잡도가 n^2 -> 이분 탐색으로 mid값을 잡으면서 계산 더보기 import sys input = sys.stdin.readline N, M = map(int, input().split()) tree = list(map(int, input().split())) cut = max(tree) - (M//len(tree)+1) get = 0 while get 0]) cut -= 1 print(cut+1) 이전 코드: 나무 최대 길이부터 M값이 될때까지 1씩 빼면서 나무 모음 import sys input = sys.stdin.readline N, M = map(int, input().split()..
[백준] CLASS1 문자열을 아스키코드로 변환하는 함수 ord(x) x: A~Z -> 65~90 x: a~z -> 97~122 아스키코드를 문자열로 변환하는 함수 chr(65) = A list.sort(reverse=False) reverse=False : 오름차순 (default) reverse=True : 내림차순 list[::-1] : Reverse 여러 개의 데이터로부터 일부의 데이터만 추려낼 때 사용하는 함수 filter(조건함수, 순회 가능한 데이터) max_idx = list(filter(lambda x: list(counter.values())[x]==max(lst), range(len(lst)))) list(filter())를 이용해서 list안에 중복되는 value값이 있어도 다중의 index번호를 lis..