結果

問題 No.409 ダイエット
ユーザー 0w10w1
提出日時 2017-04-25 21:41:35
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 319 ms / 2,000 ms
コード長 1,022 bytes
コンパイル時間 668 ms
コンパイル使用メモリ 87,240 KB
実行使用メモリ 124,692 KB
最終ジャッジ日時 2023-09-08 17:27:21
合計ジャッジ時間 20,056 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 89 ms
71,748 KB
testcase_01 AC 97 ms
71,676 KB
testcase_02 AC 87 ms
71,864 KB
testcase_03 AC 93 ms
71,728 KB
testcase_04 AC 89 ms
71,892 KB
testcase_05 AC 88 ms
71,784 KB
testcase_06 AC 88 ms
71,880 KB
testcase_07 AC 88 ms
71,624 KB
testcase_08 AC 88 ms
71,652 KB
testcase_09 AC 87 ms
71,788 KB
testcase_10 AC 86 ms
71,588 KB
testcase_11 AC 88 ms
71,892 KB
testcase_12 AC 89 ms
71,836 KB
testcase_13 AC 89 ms
71,752 KB
testcase_14 AC 90 ms
71,760 KB
testcase_15 AC 88 ms
71,800 KB
testcase_16 AC 89 ms
71,796 KB
testcase_17 AC 87 ms
71,624 KB
testcase_18 AC 85 ms
71,908 KB
testcase_19 AC 87 ms
71,724 KB
testcase_20 AC 86 ms
71,900 KB
testcase_21 AC 86 ms
71,788 KB
testcase_22 AC 88 ms
71,560 KB
testcase_23 AC 85 ms
71,588 KB
testcase_24 AC 88 ms
71,708 KB
testcase_25 AC 92 ms
71,860 KB
testcase_26 AC 92 ms
71,748 KB
testcase_27 AC 88 ms
71,588 KB
testcase_28 AC 88 ms
71,844 KB
testcase_29 AC 87 ms
71,648 KB
testcase_30 AC 88 ms
71,772 KB
testcase_31 AC 86 ms
71,864 KB
testcase_32 AC 86 ms
71,684 KB
testcase_33 AC 86 ms
71,708 KB
testcase_34 AC 86 ms
71,784 KB
testcase_35 AC 150 ms
78,592 KB
testcase_36 AC 130 ms
78,700 KB
testcase_37 AC 130 ms
78,836 KB
testcase_38 AC 128 ms
78,684 KB
testcase_39 AC 128 ms
78,900 KB
testcase_40 AC 124 ms
78,648 KB
testcase_41 AC 121 ms
78,660 KB
testcase_42 AC 130 ms
78,932 KB
testcase_43 AC 127 ms
78,016 KB
testcase_44 AC 127 ms
78,860 KB
testcase_45 AC 124 ms
78,580 KB
testcase_46 AC 122 ms
78,732 KB
testcase_47 AC 129 ms
78,920 KB
testcase_48 AC 125 ms
78,856 KB
testcase_49 AC 124 ms
78,896 KB
testcase_50 AC 127 ms
78,764 KB
testcase_51 AC 130 ms
78,904 KB
testcase_52 AC 126 ms
79,064 KB
testcase_53 AC 125 ms
78,752 KB
testcase_54 AC 130 ms
78,968 KB
testcase_55 AC 240 ms
98,864 KB
testcase_56 AC 212 ms
121,208 KB
testcase_57 AC 304 ms
122,520 KB
testcase_58 AC 202 ms
96,284 KB
testcase_59 AC 250 ms
104,180 KB
testcase_60 AC 220 ms
94,180 KB
testcase_61 AC 285 ms
117,036 KB
testcase_62 AC 282 ms
121,564 KB
testcase_63 AC 286 ms
116,516 KB
testcase_64 AC 227 ms
98,332 KB
testcase_65 AC 313 ms
116,960 KB
testcase_66 AC 297 ms
121,916 KB
testcase_67 AC 261 ms
112,120 KB
testcase_68 AC 248 ms
104,704 KB
testcase_69 AC 289 ms
116,888 KB
testcase_70 AC 276 ms
115,068 KB
testcase_71 AC 216 ms
97,840 KB
testcase_72 AC 305 ms
124,692 KB
testcase_73 AC 277 ms
119,576 KB
testcase_74 AC 238 ms
103,016 KB
testcase_75 AC 309 ms
119,388 KB
testcase_76 AC 246 ms
110,232 KB
testcase_77 AC 267 ms
97,656 KB
testcase_78 AC 217 ms
100,264 KB
testcase_79 AC 231 ms
95,120 KB
testcase_80 AC 294 ms
124,664 KB
testcase_81 AC 307 ms
119,616 KB
testcase_82 AC 253 ms
109,736 KB
testcase_83 AC 305 ms
111,136 KB
testcase_84 AC 233 ms
106,528 KB
testcase_85 AC 147 ms
79,960 KB
testcase_86 AC 250 ms
103,776 KB
testcase_87 AC 278 ms
114,944 KB
testcase_88 AC 206 ms
93,224 KB
testcase_89 AC 305 ms
110,056 KB
testcase_90 AC 212 ms
90,508 KB
testcase_91 AC 319 ms
113,740 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque

N, A, B, W = map( int, input().split() )
D = list( map( int, input().split() ) )
dp = [ 0 for i in range( N + 1 ) ]

def get_cost( x, rb ):
  d = rb - x - 1
  return dp[ x ] + d * ( d + 1 ) // 2 * B - d * A + D[ rb - 1 ]

dq = deque()
dp[ 0 ] = W
dq.append( [ 0, 1, N ] )
for i in range( 1, N + 1 ):
  while dq[ 0 ][ 2 ] < i:
    dq.popleft()
  dp[ i ] = get_cost( dq[ 0 ][ 0 ], i )
  while len( dq ):
    x, lb, rb = dq[ len( dq ) - 1 ]
    if get_cost( x, lb ) >= get_cost( i, lb ):
      dq.pop()
      if len( dq ):
        dq[ len( dq ) - 1 ][ 2 ] = N
    else:
      break
  best = -1
  x, lb, rb = dq[ len( dq ) - 1 ][ 0 ], i + 1, N
  while lb <= rb:
    mid = lb + rb >> 1
    if get_cost( x, mid ) >= get_cost( i, mid ):
      best = mid
      rb = mid - 1
    else:
      lb = mid + 1
  if best == -1: continue
  dq[ len( dq ) - 1 ][ 2 ] = best - 1
  dq.append( [ i, best, N ] )

print( min( dp[ i ] + ( N - i ) * ( N - i + 1 ) // 2 * B - ( N - i ) * A for i in range( N + 1 ) ) )
0