結果
| 問題 | 
                            No.496 ワープクリスタル (給料日前編)
                             | 
                    
| コンテスト | |
| ユーザー | 
                             tottoripaper
                         | 
                    
| 提出日時 | 2017-03-24 22:57:30 | 
| 言語 | C++11(廃止可能性あり)  (gcc 13.3.0)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 11 ms / 2,000 ms | 
| コード長 | 1,078 bytes | 
| コンパイル時間 | 3,494 ms | 
| コンパイル使用メモリ | 158,716 KB | 
| 実行使用メモリ | 34,664 KB | 
| 最終ジャッジ日時 | 2024-07-05 22:57:53 | 
| 合計ジャッジ時間 | 2,354 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge2 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 4 | 
| other | AC * 23 | 
ソースコード
#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;
}
            
            
            
        
            
tottoripaper