목록알고리즘 (15)
Hyunwoo's DATA
for문에서 str(i)의 길이를 합치는걸로 풀면 시간초과가 뜨게끔 문제가 설계되어있다. 따라서 10진수 숫자로 접근하여 문제를 풀어야만 했다. 문제는 쉬웠지만 시간초과로 애를 먹은 문제였다. n=int(input()) sum=0 index=len(str(n))-1 for i in range(0,index): sum+=9*(10**i)*(i+1) sum+=(n-10**(index)+1)*(index+1) print(sum)
https://www.acmicpc.net/problem/6064 6064번: 카잉 달력 입력 데이터는 표준 입력을 사용한다. 입력은 T개의 테스트 데이터로 구성된다. 입력의 첫 번째 줄에는 입력 데이터의 수를 나타내는 정수 T가 주어진다. 각 테스트 데이터는 한 줄로 구성된다. www.acmicpc.net 시간초과가 계속 떠서 애먹었다. 최소공배수로 접근하면 시간초과가 뜸으로 M, N, x, y에서 답 a는 (a-x)/M=0 and (a-y)/N=0를 함수로 활용하여 문제를 접근하여 풀었다. for _ in range(int(input())): M, N, x, y=map(int,input().split()) ans=-1 while x
https://www.acmicpc.net/problem/14719 x, y=map(int,input().split()) num=list(map(int,input().split())) maxH=1 for i in range(len(num)): if maxH temp: temp=num[i] total+=temp-num[i] temp=0 for i in range(y-1,index,-1): if num[i]>temp: temp=num[i] total+=temp-num[i] print(total)