結果

問題 No.34 砂漠の行商人
ユーザー mamekinmamekin
提出日時 2015-01-12 21:44:55
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,390 bytes
コンパイル時間 903 ms
コンパイル使用メモリ 103,864 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-04 05:06:53
合計ジャッジ時間 2,127 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
using namespace std;

const int INF = INT_MAX / 4;
const int dy[] = {-1, 0, 1, 0};
const int dx[] = {0, -1, 0, 1};

int main()
{
    int n, v;
    cin >> n >> v;
    vector<vector<int> > level(n+2, vector<int>(n+2, INF));
    for(int y=1; y<=n; ++y){
        for(int x=1; x<=n; ++x){
            cin >> level[y][x];
        }
    }

    vector<vector<int> > dp(n+2, vector<int>(n+2, 0));
    dp[1][1] = v;
    priority_queue<tuple<int, int, int> > pq;
    pq.push(make_tuple(v, 1, 1));
    while(!pq.empty()){
        int hp, y, x;
        tie(hp, y, x) = pq.top();
        pq.pop();
        if(hp < dp[y][x])
            continue;

        for(int i=0; i<4; ++i){
            int y2 = y + dy[i];
            int x2 = x + dx[i];
            int hp2 = hp - level[y2][x2];
            if(hp2 > dp[y2][x2]){
                dp[y2][x2] = hp2;
                pq.push(make_tuple(hp2, y2, x2));
            }
        }
    }

    if(dp[n][n] > 0)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;

    return 0;
}
0