結果

問題 No.20 砂漠のオアシス
ユーザー 👑 はまやんはまやんはまやんはまやん
提出日時 2018-06-23 18:20:47
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 3,100 bytes
コンパイル時間 1,649 ms
コンパイル使用メモリ 176,504 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-13 08:32:45
合計ジャッジ時間 3,182 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
            ∧_∧  
      ∧_∧  (´<_` )  Welcome to My Coding Space!
     ( ´_ゝ`) /  ⌒i     
    /   \     | |     
    /   / ̄ ̄ ̄ ̄/  |  
  __(__ニつ/     _/ .| .|____  
     \/____/ (u ⊃  
---------------------------------------------------------------------------------------------------*/





template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
int dx[4] = { 0, 1, 0, -1 }, dy[4] = { -1, 0, 1, 0 };
int N, V, Ox, Oy, L[202][202];
//---------------------------------------------------------------------------------------------------
int vis[202][202];
void dji(int sx, int sy, vector<vector<int>> &d) {
    rep(y, 0, N) rep(x, 0, N) d[y][x] = inf;
    rep(y, 0, N) rep(x, 0, N) vis[y][x] = 0;

    min_priority_queue<pair<int, int>> que;
    que.push({ 0, sy * N + sx });
    d[sy][sx] = 0;
    while (!que.empty()) {
        auto q = que.top();
        que.pop();

        int c = q.first;
        int x = q.second % N;
        int y = q.second / N;

        if (vis[y][x]) continue;
        vis[y][x] = 1;
        
        rep(i, 0, 4) {
            int xx = x + dx[i];
            int yy = y + dy[i];
            if (0 <= xx and xx < N and 0 <= yy and yy < N) if(!vis[yy][xx]) {
                if (d[y][x] + L[yy][xx] < d[yy][xx]) {
                    d[yy][xx] = d[y][x] + L[yy][xx];
                    que.push({ d[yy][xx], yy * N + xx });
                }
            }
        }
    }
}
//---------------------------------------------------------------------------------------------------
#define yes "YES"
#define no "NO"
string solve() {
    vector<vector<int>> d1(N, vector<int>(N));
    dji(0, 0, d1);
    vector<vector<int>> d2(N, vector<int>(N));
    dji(Ox, Oy, d2);

    // start -> goal
    if (d1[N - 1][N - 1] <= V) return yes;

    // start -> oasis -> goal
    if (d1[Oy][Ox] <= V and d1[Oy][Ox] + d2[N-1][N-1] <= (V - d1[Oy][Ox]) * 2) return yes;

    return no;
}
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> N >> V >> Ox >> Oy;
    Ox--; Oy--;
    rep(y, 0, N) rep(x, 0, N) cin >> L[y][x];
    cout << solve() << endl;
}
0