結果
問題 | No.20 砂漠のオアシス |
ユーザー | kopricky |
提出日時 | 2017-09-13 04:01:28 |
言語 | C++11 (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 27 ms / 5,000 ms |
コード長 | 2,211 bytes |
コンパイル時間 | 1,998 ms |
コンパイル使用メモリ | 164,604 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-11-07 17:47:51 |
合計ジャッジ時間 | 2,532 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 21 |
ソースコード
#include <bits/stdc++.h> #define ll long long #define INF 1000000005 #define MOD 1000000007 #define EPS 1e-10 #define rep(i,n) for(int i=0;i<(int)n;++i) #define each(a,b) for(auto (a): (b)) #define all(v) (v).begin(),(v).end() #define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end()) #define fi first #define se second #define pb push_back #define show(x) cout<<#x<<" = "<<(x)<<endl #define spair(p) cout<<#p<<": "<<p.fi<<" "<<p.se<<endl #define svec(v) cout<<#v<<":";rep(kbrni,v.size())cout<<" "<<v[kbrni];cout<<endl #define sset(s) cout<<#s<<":";each(kbrni,s)cout<<" "<<kbrni;cout<<endl #define smap(m) cout<<#m<<":";each(kbrni,m)cout<<" {"<<kbrni.first<<":"<<kbrni.second<<"}";cout<<endl using namespace std; typedef pair<int,int>P; const int MAX_N = 205; const int dx[] = {1,0,0,-1}; const int dy[] = {0,1,-1,0}; int cost[MAX_N][MAX_N]; int hp[MAX_N][MAX_N][2]; struct state { int a,b,c; }; int main() { cin.tie(0); ios::sync_with_stdio(false); int n,h,u,v; cin >> n >> h >> v >> u; u--,v--; rep(i,n){ rep(j,n){ cin >> cost[i][j]; } } rep(i,n){ rep(j,n){ rep(k,2){ hp[i][j][k] = 0; } } } hp[0][0][0] = h; queue<state> que; que.push((state){0,0,0}); while(!que.empty()){ state s = que.front(); que.pop(); rep(i,4){ int nx = s.a + dx[i],ny = s.b + dy[i]; if(0 <= nx && nx < n && 0 <= ny && ny < n){ if(nx == u && ny == v && s.c == 0){ if(2*(hp[s.a][s.b][s.c] - cost[nx][ny]) > hp[nx][ny][1]){ hp[nx][ny][1] = 2*(hp[s.a][s.b][s.c] - cost[nx][ny]); que.push((state){nx,ny,1}); } }else{ if(hp[s.a][s.b][s.c] - cost[nx][ny] > hp[nx][ny][s.c]){ hp[nx][ny][s.c] = hp[s.a][s.b][s.c] - cost[nx][ny]; que.push((state){nx,ny,s.c}); } } } } } if(max(hp[n-1][n-1][0],hp[n-1][n-1][1]) > 0){ cout << "YES\n"; }else{ cout << "NO\n"; } return 0; }