結果

問題 No.496 ワープクリスタル (給料日前編)
ユーザー ikdikd
提出日時 2017-03-24 23:40:39
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 5 ms / 2,000 ms
コード長 1,072 bytes
コンパイル時間 1,529 ms
コンパイル使用メモリ 53,404 KB
実行使用メモリ 5,460 KB
最終ジャッジ日時 2023-09-20 05:25:14
合計ジャッジ時間 2,511 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
5,364 KB
testcase_01 AC 4 ms
5,372 KB
testcase_02 AC 3 ms
5,364 KB
testcase_03 AC 4 ms
5,376 KB
testcase_04 AC 3 ms
5,356 KB
testcase_05 AC 3 ms
5,352 KB
testcase_06 AC 4 ms
5,356 KB
testcase_07 AC 4 ms
5,428 KB
testcase_08 AC 5 ms
5,404 KB
testcase_09 AC 4 ms
5,456 KB
testcase_10 AC 4 ms
5,348 KB
testcase_11 AC 4 ms
5,344 KB
testcase_12 AC 4 ms
5,460 KB
testcase_13 AC 4 ms
5,404 KB
testcase_14 AC 4 ms
5,360 KB
testcase_15 AC 4 ms
5,368 KB
testcase_16 AC 4 ms
5,404 KB
testcase_17 AC 4 ms
5,420 KB
testcase_18 AC 4 ms
5,368 KB
testcase_19 AC 4 ms
5,388 KB
testcase_20 AC 3 ms
5,344 KB
testcase_21 AC 4 ms
5,360 KB
testcase_22 AC 5 ms
5,364 KB
testcase_23 AC 4 ms
5,404 KB
testcase_24 AC 4 ms
5,404 KB
testcase_25 AC 5 ms
5,344 KB
testcase_26 AC 4 ms
5,400 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>

using namespace std;
#define repeat(i, n) for(int i=0; i<(n); i++)
int memo[51][101][101];
const int inf=1e8;

int main(){

   int gx, gy, N, F;
   cin>> gx>> gy>> N>> F;
   int dx[N], dy[N], c[N];
   repeat(i, N) cin>> dx[i]>> dy[i]>> c[i];

   repeat(i, 51){
      repeat(x, 101){
         repeat(y, 101){
            if(x==0&&y==0) memo[i][x][y]=0;
            else memo[i][x][y]=inf;
         }
      }
   }

   repeat(i, N){
      repeat(x, gx+1){
         repeat(y, gy+1){
            memo[i+1][x][y]=min(memo[i+1][x][y], memo[i][x][y]);
            if(memo[i][x][y]==inf) continue;
            if(x+dx[i]>gx||y+dy[i]>gy) continue;
            if(c[i]>(dx[i]+dy[i])*F) continue;
            memo[i+1][x+dx[i]][y+dy[i]]
            =min(memo[i+1][x+dx[i]][y+dy[i]], memo[i][x][y]+c[i]);
         }
      }
   }

   int C=inf;
   repeat(x, gx+1){
      repeat(y, gy+1){
         if(memo[N][x][y]==inf) continue;
         int _c=F*((gx-x)+(gy-y));
         _c+=memo[N][x][y];
         C=min(C, _c);
      }
   }

   cout<< C<< endl;

   return 0;
}
0