結果

問題 No.20 砂漠のオアシス
ユーザー Mi_SawaMi_Sawa
提出日時 2015-04-09 00:24:50
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 18 ms / 5,000 ms
コード長 2,217 bytes
コンパイル時間 1,552 ms
コンパイル使用メモリ 161,920 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-03 07:28:20
合計ジャッジ時間 2,741 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
#define all(x) begin(x),end(x)
#define rall(x) (x).rbegin(),(x).rend()
#define REP(i,b,n) for(int i=(int)(b);i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define repsz(i,v) rep(i,(v).size())
#define aur auto&
#define bit(n) (1LL<<(n))
#define eb emplace_back
#define mt make_tuple
#define fst first
#define snd second
using namespace std;
typedef long long ll;
//#define int long long
template<class C>int size(const C &c){ return c.size(); }
template<class T>bool chmin(T&a,const T&b){if(a<=b)return false;a=b;return true;}
template<class T>bool chmax(T&a,const T&b){if(a>=b)return false;a=b;return true;}

template<typename X> inline bool valid_index(const X &x){ return true; }
template<typename V, typename ...Args>
inline bool valid_index(const V &v, const int &i, const Args &...args){ return 0<=i and i<v.size() and valid_index(v[i], args...); }


int dxy[] = {0, 1, 0, -1, 0};
vector<vector<int>> dijk(vector<vector<int>> &b, int sx, int sy){
    using Elem = tuple<int, int, int>;

    const int n = size(b);
    priority_queue<Elem, vector<Elem>, greater<Elem>> pq;
    vector<vector<int>> d(n, vector<int>(n, numeric_limits<int>::max()));
    if(!valid_index(b, sx, sy)) return d;
    pq.emplace(d[sx][sy] = 0, sx, sy);
    while(!pq.empty()){
        int c, x, y; tie(c, x, y) = pq.top(); pq.pop();
        if(c > d[x][y]) continue;
        rep(dir, 4){
            int xx = x + dxy[dir], yy = y + dxy[dir+1];
            if(valid_index(b, xx, yy) and chmin(d[xx][yy], c + b[xx][yy]))
                pq.emplace(d[xx][yy], xx, yy);
        }
    }
    return d;
}


bool solve(){
    int n, v, ox, oy; cin >> n >> v >> oy >> ox; --ox; --oy;
    vector<vector<int>> b(n, vector<int>(n));
    rep(i, n) rep(j, n) cin >> b[i][j];
    auto s = dijk(b, 0, 0), o = dijk(b, ox, oy);
    string res = "NO";
    if(s[n-1][n-1] < v) res = "YES";
    if(valid_index(s, ox, oy) and s[ox][oy] < v and o[n-1][n-1] < 2 * (v - s[ox][oy])) res = "YES";
    cout << res << endl;
    return true;
}
signed main(){
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << std::fixed << std::setprecision(10);
    solve();
    return 0;
}
// vim:set foldmethod=marker commentstring=//%s:
0