結果
問題 |
No.20 砂漠のオアシス
|
ユーザー |
![]() |
提出日時 | 2015-06-04 00:40:16 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 29 ms / 5,000 ms |
コード長 | 1,648 bytes |
コンパイル時間 | 695 ms |
コンパイル使用メモリ | 84,744 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-10-13 05:12:25 |
合計ジャッジ時間 | 1,542 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 21 |
ソースコード
#include <algorithm> #include <cstdio> #include <cstdlib> #include <cctype> #include <cmath> #include <iostream> #include <queue> #include <list> #include <map> #include <numeric> #include <set> #include <sstream> #include <string> #include <vector> using namespace std; #define REP(i,a,n) for(int i=(a); i<(int)(n); i++) #define rep(i,n) REP(i,0,n) #define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it) #define ALLOF(c) (c).begin(), (c).end() typedef long long ll; #define INF 1000000000 int N; int L[205][205]; int vx[4] = {0,0,1,-1}; int vy[4] = {1,-1,0,0}; struct ST { int x, y, v; }; bool operator>(const ST& a, const ST& b){ return a.v > b.v; } int dijkstra(int sx, int sy, int gx, int gy){ bool visited[205][205]; REP(i,1,N+1){ REP(j,1,N+1){ visited[i][j] = false; } } priority_queue<ST, vector<ST>, greater<ST> > q; q.push((ST){sx,sy,0}); while(!q.empty()){ ST st = q.top(); q.pop(); if(visited[st.y][st.x]) continue; visited[st.y][st.x] = true; if(st.x == gx && st.y == gy) return st.v; rep(k,4){ int nx = st.x + vx[k], ny = st.y + vy[k]; if(1<=nx&&nx<=N && 1<=ny&&ny<=N){ q.push((ST){nx,ny,st.v+L[ny][nx]}); } } } return INF; } int main(){ int V, Ox, Oy; cin >> N >> V >> Ox >> Oy; REP(i,1,N+1){ REP(j,1,N+1){ cin >> L[i][j]; } } int ret1 = V - dijkstra(1,1,N,N); int ret2 = 0; if(Ox>=1){ int a = V-dijkstra(1,1,Ox,Oy); if(a>=0){ ret2 = 2*a - dijkstra(Ox,Oy,N,N); } } if(max(ret1, ret2) > 0) cout << "YES" << endl; else cout << "NO" << endl; return 0; }