[백준 파이썬 11003번]최솟값 찾기★VER2.0★시간초과 고려
2022. 12. 29. 17:31
728x90
반응형
https://www.acmicpc.net/problem/11003
VERSION 2.0
import sys
import collections
from collections import deque
N, L = map(int , sys.stdin.readline().rstrip().split(' '))
D_i = list(map(int , sys.stdin.readline().split(' ')))
# minimum = min(D_i)
# D_0 = A_0-3+1 ~ A_0
# D_2 = A_2-3+1 ~ A_2 ==> A_0 ~ A_2
# D_3 = A_3-3+1 ~ A_3 ==> A_1 ~ A_3
# D_4 = A_4-3+1 ~ A_4 ==> A_2 ~ A_4
# 123 234 345 456 ==> S = 6 P =3 ==> S-P+1 = 4 ==> 4번 구한다.
res = deque()
# N = 5 L = 3
# D_i = 1 2 3 4 5
# D_0 = 1 ==> i-L+1 < 0
# D_1 = 1 ==> 1-3+1 = -1 A_0 ~ A_1
for i in range(N):
while True:
if len(res)==0 or res[-1][0] <= D_i[i]:
break
else:
res.pop()
res.append((D_i[i] , i))
if res[0][1] <= i-L:
res.popleft()
print(res[0][0] , end = ' ')
#%%
시간초과
VERSION 1.0
import sys
import collections
from collections import deque
N, L = map(int , sys.stdin.readline().rstrip().split(' '))
D_i = list(map(int , sys.stdin.readline().split(' ')))
#minimum = min(D_i)
#D_0 = A_0-3+1 ~ A_0
#D_2 = A_2-3+1 ~ A_2 ==> A_0 ~ A_2
#D_3 = A_3-3+1 ~ A_3 ==> A_1 ~ A_3
#D_4 = A_4-3+1 ~ A_4 ==> A_2 ~ A_4
#123 234 345 456 ==> S = 6 P =3 ==> S-P+1 = 4 ==> 4번 구한다.
#N = 5 L = 3
#D_i = 1 2 3 4 5
#D_0 = 1 ==> i-L+1 < 0
#D_1 = 1 ==> 1-3+1 = -1 A_0 ~ A_1
end_idx = 0
for i in range(N):
idx = end_idx-L+1
if end_idx == 0 or idx<=0:
print(min(D_i[0:end_idx+1]) , end = ' ')
end_idx+=1
else:
print(min(D_i[idx: end_idx+1]) , end = ' ')
end_idx+=1
#%%
728x90
반응형
'Python(백준) > 배열' 카테고리의 다른 글
★VER2.0★max()안쓰고 구하기★[백준 파이썬 2562번 최대] (0) | 2023.03.27 |
---|---|
★VER 2.0★min,max★1차원 배열 최소 최대숫자 알아보기 [백준 Python 10818번] (0) | 2023.03.27 |
[백준 파이썬 12891번]좋다★DNA 비밀번호★WINDOWS SLIDING★VER2.0★시간초과 고려 (0) | 2022.12.29 |
[Python] 백준 8958번 ox퀴즈 (0) | 2022.09.14 |
[Python] 백준 2562번 최대값 (0) | 2022.09.14 |