結果

問題 No.20 砂漠のオアシス
ユーザー uenokuuenoku
提出日時 2017-01-07 12:00:25
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 2,944 bytes
コンパイル時間 647 ms
コンパイル使用メモリ 73,384 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-21 07:01:28
合計ジャッジ時間 1,320 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 AC 1 ms
6,940 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 8 ms
6,944 KB
testcase_07 WA -
testcase_08 AC 7 ms
6,940 KB
testcase_09 AC 8 ms
6,940 KB
testcase_10 AC 1 ms
6,944 KB
testcase_11 WA -
testcase_12 AC 2 ms
6,940 KB
testcase_13 AC 2 ms
6,940 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 3 ms
6,944 KB
testcase_18 WA -
testcase_19 AC 4 ms
6,940 KB
testcase_20 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
using namespace std;
typedef long long int lli;
lli MOD = 1000000007;
int f[205][205];
int n;
int v, ox, oy;
bool inrange(int x, int y)
{
    return 0 <= x && x < n && 0 <= y && y < n;
}
struct node {
    lli d, x, y;
};
int vx[] = {1, 0, -1, 0};
int vy[] = {0, 1, 0, -1};
int main()
{
    cin >> n >> v >> ox >> oy;
    ox--, oy--;
    lli dis[205][205] = {};

    auto comp = [](const node l, const node r) -> bool { return l.d < r.d; };
    rep(i, n) rep(j, n) cin >> f[i][j];
    {
        priority_queue<node, vector<node>, decltype(comp)> que(comp);
        que.push({f[0][0], 0, 0});
        rep(i, 205) rep(j, 205) dis[i][j] = MOD;
        while (!que.empty()) {
            node cur = que.top();
            que.pop();
            if (dis[cur.x][cur.y] < cur.d || dis[cur.x][cur.y] > v)
                continue;
            //cout << cur.x << ' ' << cur.y << endl;
            dis[cur.x][cur.y] = cur.d;
            rep(i, 4)
            {
                int nx = cur.x + vx[i];
                int ny = cur.y + vy[i];
                if (inrange(nx, ny)) {
                    if (dis[nx][ny] > cur.d + f[nx][ny]) {
                        que.push({cur.d + f[nx][ny], nx, ny});
                        dis[nx][ny] = cur.d + f[nx][ny];
                    }
                }
            }
        }
    }
    if (ox == -1) {
        cout << (dis[n - 1][n - 1] < v ? "YES" : "NO") << endl;
    } else {
        if (dis[n - 1][n - 1] < v) {
            cout << "YES" << endl;
            return 0;
        }
        if (dis[ox][oy] < v) {
            v = 2 * (v - f[ox][oy]);
            priority_queue<node, vector<node>, decltype(comp)> que(comp);

            que.push({0, ox, oy});
            rep(i, 205) rep(j, 205) dis[i][j] = MOD;
            while (!que.empty()) {
                node cur = que.top();
                que.pop();
                if (dis[cur.x][cur.y] < cur.d || dis[cur.x][cur.y] > v)
                    continue;
                //cout << cur.x << ' ' << cur.y << endl;
                dis[cur.x][cur.y] = cur.d;
                rep(i, 4)
                {
                    int nx = cur.x + vx[i];
                    int ny = cur.y + vy[i];
                    if (inrange(nx, ny)) {
                        if (dis[nx][ny] > cur.d + f[nx][ny]) {
                            que.push({cur.d + f[nx][ny], nx, ny});
                            dis[nx][ny] = cur.d + f[nx][ny];
                        }
                    }
                }
            }
            if (dis[n - 1][n - 1] < v) {
                cout << "YES" << endl;
            } else {
                cout << "NO" << endl;
            }
        } else {
            cout << "NO" << endl;
        }
    }
}
0