結果

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

テストケース

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

ソースコード

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] != MOD && 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] != MOD && 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