結果

問題 No.496 ワープクリスタル (給料日前編)
ユーザー tottoripapertottoripaper
提出日時 2017-03-24 22:57:30
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 11 ms / 2,000 ms
コード長 1,078 bytes
コンパイル時間 2,526 ms
コンパイル使用メモリ 143,908 KB
実行使用メモリ 34,828 KB
最終ジャッジ日時 2023-09-20 02:37:52
合計ジャッジ時間 3,884 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 10 ms
34,712 KB
testcase_01 AC 10 ms
34,504 KB
testcase_02 AC 10 ms
34,572 KB
testcase_03 AC 10 ms
34,612 KB
testcase_04 AC 10 ms
34,828 KB
testcase_05 AC 10 ms
34,600 KB
testcase_06 AC 10 ms
34,672 KB
testcase_07 AC 10 ms
34,496 KB
testcase_08 AC 11 ms
34,604 KB
testcase_09 AC 10 ms
34,508 KB
testcase_10 AC 10 ms
34,516 KB
testcase_11 AC 10 ms
34,516 KB
testcase_12 AC 10 ms
34,616 KB
testcase_13 AC 10 ms
34,612 KB
testcase_14 AC 10 ms
34,504 KB
testcase_15 AC 10 ms
34,604 KB
testcase_16 AC 10 ms
34,604 KB
testcase_17 AC 10 ms
34,716 KB
testcase_18 AC 10 ms
34,712 KB
testcase_19 AC 10 ms
34,684 KB
testcase_20 AC 11 ms
34,508 KB
testcase_21 AC 10 ms
34,716 KB
testcase_22 AC 10 ms
34,676 KB
testcase_23 AC 10 ms
34,608 KB
testcase_24 AC 11 ms
34,508 KB
testcase_25 AC 11 ms
34,680 KB
testcase_26 AC 10 ms
34,668 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)

using ll = long long;
using P = std::tuple<int,int>;

const int dx[8] = {-1, 1, 0, 0, -1, -1, 1, 1}, dy[8] = {0, 0, -1, 1, -1, 1, -1, 1};

int Gx, Gy, N, F;
int Xs[100], Ys[100], Cs[100];
int dp[200][200][200];

int rec(int x, int y, int n){
    if(x == Gx && y == Gy){
        return 0;
    }
    if(dp[y][x][n] != -1){
        return dp[y][x][n];
    }
    // printf("%d, %d, %d\n", x, y, n);

    int res = (Gx - x + Gy - y) * F; //rec(x, y, n+1);

    for(int i=n;i<N;++i){
        int nx = x + Xs[i], ny = y + Ys[i];
        if(nx > Gx || ny > Gy){continue;}

        res = min(res, Cs[i] + rec(nx, ny, i+1));        
    }

    return dp[y][x][n] = res;
}

int main(){
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);

    memset(dp, -1, sizeof(dp));
    
    std::cin >> Gx >> Gy >> N >> F;

    for(int i=0;i<N;++i){
        std::cin >> Xs[i] >> Ys[i] >> Cs[i];
    }

    std::cout << rec(0, 0, 0) << std::endl;
}
0