結果
問題 |
No.496 ワープクリスタル (給料日前編)
|
ユーザー |
![]() |
提出日時 | 2017-08-23 16:29:14 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 3 ms / 2,000 ms |
コード長 | 1,434 bytes |
コンパイル時間 | 661 ms |
コンパイル使用メモリ | 61,272 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-10-15 13:05:37 |
合計ジャッジ時間 | 1,532 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 23 |
ソースコード
#include <iostream> #include <algorithm> using namespace std; struct crystal{int x,y,c, otoku;}; bool cospa( const crystal &cry1, const crystal &cry2 ){ if(cry1.otoku != cry2.otoku) return cry1.otoku < cry2.otoku; else return cry1.x+cry1.y < cry2.x+cry2.y; } int main(){ int Gx, Gy, N, F; cin >> Gx >> Gy >> N >> F; crystal crystals[N]; for(int i=0; i<N; i++){ cin >> crystals[i].x >> crystals[i].y >> crystals[i].c; if(crystals[i].x<=Gx && crystals[i].y<=Gy){ crystals[i].otoku = crystals[i].c - F*(crystals[i].x + crystals[i].y); }else{ crystals[i].otoku = 0; } } sort(crystals, crystals+N, cospa); //moveCost[i][j]=(i,j)に行くのにかかる料金 int moveCost[Gx+1][Gy+1]; for(int i=0; i<=Gx; i++){ for(int j=0; j<=Gy; j++){ moveCost[i][j] = (i+j)*F; //全部歩いたときのコスト } } for(int k=0; crystals[k].otoku<0; k++){ for(int i=Gx; i>=crystals[k].x; i--){ for(int j=Gy; j>=crystals[k].y; j--){ moveCost[i][j] = min(moveCost[i][j], moveCost[i-crystals[k].x][j-crystals[k].y] + crystals[k].c); //k番目(0<=k<N)までのクリスタルを使えるときに、(i,j)に行くのにかかる最小料金 } } } cout << moveCost[Gx][Gy] << endl; return 0; }