結果

問題 No.20 砂漠のオアシス
ユーザー h_nosonh_noson
提出日時 2016-05-18 13:38:01
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 17 ms / 5,000 ms
コード長 1,393 bytes
コンパイル時間 676 ms
コンパイル使用メモリ 80,940 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-21 06:53:12
合計ジャッジ時間 1,579 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 3 ms
5,376 KB
testcase_05 AC 14 ms
5,376 KB
testcase_06 AC 8 ms
5,376 KB
testcase_07 AC 17 ms
5,376 KB
testcase_08 AC 10 ms
5,376 KB
testcase_09 AC 16 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 3 ms
5,376 KB
testcase_14 AC 3 ms
5,376 KB
testcase_15 AC 3 ms
5,376 KB
testcase_16 AC 5 ms
5,376 KB
testcase_17 AC 4 ms
5,376 KB
testcase_18 AC 4 ms
5,376 KB
testcase_19 AC 5 ms
5,376 KB
testcase_20 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <iomanip>
using namespace std;

#define RREP(i,s,e) for (i = s; i >= e; i--)
#define rrep(i,n) RREP(i,(int)(n)-1,0)
#define REP(i,s,e) for (i = s; i <= e; i++)
#define rep(i,n) REP(i,0,(int)(n)-1)
#define INF 100000000

typedef long long ll;

int main() {
    int i, j, n, v, ox, oy;
    int l[201][201];
    int hp[2][201][201] {};
    priority_queue<tuple<int,int,int,bool>> q; // (hp,x,y,oasis)
    cin >> n >> v >> ox >> oy;
    REP (i,1,n) REP (j,1,n) cin >> l[i][j];
    q.push(make_tuple(v,1,1,0));
    hp[0][1][1] = v;
    while (!q.empty()) {
        int y = get<1>(q.top());
        int x = get<2>(q.top());
        bool oasis = get<3>(q.top());
        q.pop();
        int dxy[4] = {-1,0,1,0};
        rep (i,4) {
            int nx = x + dxy[i];
            int ny = y + dxy[(i+1)%4];
            if (nx < 1 || nx > n || ny < 1 || ny > n)
                continue;
            bool noasis = oasis || nx == ox && ny == oy;
            int nhp = (hp[oasis][y][x] - l[ny][nx]) * (noasis != oasis ? 2 : 1);
            if (hp[noasis][ny][nx] < nhp) {
                hp[noasis][ny][nx] = nhp;
                q.push(make_tuple(nhp,ny,nx,noasis));
            }
        }
    }
    if (hp[0][n][n] || hp[1][n][n])
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
    return 0;
}
0