結果

問題 No.496 ワープクリスタル (給料日前編)
ユーザー u-shou-sho
提出日時 2017-08-23 16:29:14
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,434 bytes
コンパイル時間 527 ms
コンパイル使用メモリ 61,232 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-23 13:09:48
合計ジャッジ時間 1,250 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 1 ms
5,376 KB
testcase_10 AC 1 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 1 ms
5,376 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 1 ms
5,376 KB
testcase_17 AC 2 ms
5,376 KB
testcase_18 AC 2 ms
5,376 KB
testcase_19 AC 2 ms
5,376 KB
testcase_20 AC 1 ms
5,376 KB
testcase_21 AC 2 ms
5,376 KB
testcase_22 AC 2 ms
5,376 KB
testcase_23 AC 1 ms
5,376 KB
testcase_24 AC 1 ms
5,376 KB
testcase_25 AC 2 ms
5,376 KB
testcase_26 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0