結果
| 問題 |
No.20 砂漠のオアシス
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2017-12-08 01:14:10 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 1,399 bytes |
| コンパイル時間 | 1,602 ms |
| コンパイル使用メモリ | 165,292 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-11-29 05:32:26 |
| 合計ジャッジ時間 | 2,828 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 15 WA * 5 RE * 1 |
ソースコード
#include "bits/stdc++.h"
using namespace std;
#define print(x) cout<<x<<endl;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a) for(int i=0;i<a;i++)
#define printall(n,array) {for(int i=0;i<n;i++){cout<<array[i]<<" ";}cout<<endl;}
#define U() cout<<endl;
typedef long long ll;
typedef pair<int, int> PI;
typedef pair<int, PI> V;
typedef vector<int> VE;
const ll mod = 1000000007; //10^9+7
int n,v,ox,oy;
int cost[210][210];
int dist[210][210];
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
void diskstra(int y,int x){
REP(i,n)REP(j,n)dist[i][j]=mod;
priority_queue<V,vector<V>,greater<V> >que;
que.push(make_pair(0,make_pair(y,x)));
dist[y][x]=0;
while(!que.empty()){
auto c=que.top().first;
auto now=que.top().second;
que.pop();
REP(i,4){
int ny=now.first+dy[i];
int nx=now.second+dx[i];
if(ny<0||ny>=n||nx<0||nx>=n)continue;
if(dist[ny][nx]<=c+cost[ny][nx])continue;
dist[ny][nx]=c+cost[ny][nx];
que.push(make_pair(dist[ny][nx],make_pair(ny,nx)));
}
}
}
int main(){
cin>>n>>v>>ox>>oy;
ox--;oy--;
REP(i,n)REP(j,n)cin>>cost[j][i];
diskstra(0,0);
if(dist[n-1][n-1]<v){print("YES");return 0;}
if(dist[oy][ox]>=v){print("NO");return 0;}
//REP(i,n){REP(j,n)cout<<dist[j][i]<<" ";cout<<endl;}///
v=(v-dist[oy][ox])*2;
diskstra(oy,ox);
if(dist[n-1][n-1]<v){print("YES");return 0;}
print("NO");return 0;
}