結果

問題 No.496 ワープクリスタル (給料日前編)
ユーザー 0w10w1
提出日時 2017-04-09 21:00:17
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 346 ms / 2,000 ms
コード長 1,179 bytes
コンパイル時間 304 ms
コンパイル使用メモリ 86,892 KB
実行使用メモリ 86,100 KB
最終ジャッジ日時 2023-09-25 01:31:41
合計ジャッジ時間 6,649 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 83 ms
71,820 KB
testcase_01 AC 83 ms
71,460 KB
testcase_02 AC 86 ms
71,904 KB
testcase_03 AC 83 ms
71,768 KB
testcase_04 AC 83 ms
71,608 KB
testcase_05 AC 86 ms
71,468 KB
testcase_06 AC 83 ms
71,764 KB
testcase_07 AC 83 ms
71,540 KB
testcase_08 AC 290 ms
84,392 KB
testcase_09 AC 280 ms
84,184 KB
testcase_10 AC 143 ms
79,788 KB
testcase_11 AC 120 ms
78,288 KB
testcase_12 AC 186 ms
80,252 KB
testcase_13 AC 197 ms
80,508 KB
testcase_14 AC 194 ms
80,728 KB
testcase_15 AC 201 ms
80,312 KB
testcase_16 AC 194 ms
81,148 KB
testcase_17 AC 207 ms
80,936 KB
testcase_18 AC 203 ms
80,572 KB
testcase_19 AC 203 ms
80,704 KB
testcase_20 AC 169 ms
79,376 KB
testcase_21 AC 166 ms
79,992 KB
testcase_22 AC 343 ms
85,808 KB
testcase_23 AC 332 ms
85,828 KB
testcase_24 AC 319 ms
85,356 KB
testcase_25 AC 324 ms
85,588 KB
testcase_26 AC 346 ms
86,100 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from copy import deepcopy

Gx, Gy, N, F = map( int, input().split() )
X = []
Y = []
C = []
for i in range( N ):
  x, y, c = map( int, input().split() )
  X.append( x )
  Y.append( y )
  C.append( c )

if N == 0:
  exit( print( F * ( Gx + Gy ) ) )

INF = int( 1e15 )

dp = [ INF for i in range( Gy + 1 ) ]
dp = [ deepcopy( dp ) for i in range( Gx + 1 ) ]
dp = [ deepcopy( dp ) for i in range( N + 1 ) ]
dp[ 0 ][ 0 ][ 0 ] = 0
for i in range( N ):
  for j in range( Gx + 1 ):
    for k in range( Gy + 1 ):
      dp[ i + 1 ][ j ][ k ] = min( dp[ i + 1 ][ j ][ k ], dp[ i ][ j ][ k ] )
      if j + X[ i ] <= Gx and k + Y[ i ] <= Gy:
        dp[ i + 1 ][ j + X[ i ] ][ k + Y[ i ] ] = min( dp[ i + 1 ][ j + X[ i ] ][ k + Y[ i ] ], dp[ i ][ j ][ k ] + C[ i ] )
      if j + 1 <= Gx:
        dp[ i ][ j + 1 ][ k ] = min( dp[ i ][ j + 1 ][ k ], dp[ i ][ j ][ k ] + F )
        dp[ i + 1 ][ j + 1 ][ k ] = min( dp[ i + 1 ][ j + 1 ][ k ], dp[ i ][ j ][ k ] + F )
      if k + 1 <= Gy:
        dp[ i ][ j ][ k + 1 ] = min( dp[ i ][ j ][ k + 1 ], dp[ i ][ j ][ k ] + F )
        dp[ i + 1 ][ j ][ k + 1 ] = min( dp[ i + 1 ][ j ][ k + 1 ], dp[ i ][ j ][ k ] + F )
print( dp[ N ][ Gx ][ Gy ] )
0