結果
| 問題 |
No.20 砂漠のオアシス
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2018-10-09 18:11:53 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,435 bytes |
| コンパイル時間 | 866 ms |
| コンパイル使用メモリ | 77,612 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-10-12 16:37:37 |
| 合計ジャッジ時間 | 1,642 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 19 WA * 2 |
ソースコード
#include<iostream>
#include<queue>
using namespace std;
#define inRange(x,a,b) (a <= x && x < b)
int dx[8] = {0,0,1,-1,1,1,-1,-1};
int dy[8] = {1,-1,0,0,1,-1,1,-1};
const int INF = 1<<21;
int n, v, x, y, mat[200][200], dist[200][200];
void dijk(int fi, int fj){
for(int i = 0; i < n; i++){
for(int j = 0; j < n; j++){
dist[i][j] = INF;
}
}
dist[fi][fj] = 0;
priority_queue<pair<int,pair<int,int>>> pq;
pq.push({0,{fi,fj}});
while(!pq.empty()){
auto p = pq.top(); pq.pop();
int c = -p.first, i = p.second.first, j = p.second.second;
if(c > dist[i][j]) continue;
for(int k = 0; k < 4; k++){
int ni = i + dx[k], nj = j + dy[k];
if(!inRange(ni,0,n) || !inRange(nj,0,n)) continue;
if(dist[ni][nj] > mat[i][j] + c){
dist[ni][nj] = mat[i][j] + c;
pq.push({-dist[ni][nj], {ni,nj}});
}
}
}
}
int main(){
cin >> n >> v >> x >> y;
x--; y--;
for(int i = 0; i < n; i++){
for(int j = 0; j < n; j++){
cin >> mat[i][j];
}
}
dijk(0,0);
bool judge = false;
if(dist[n-1][n-1] < v) judge = true;
if(x+y != -2){
dijk(y,x);
if((v-dist[0][0])*2-dist[n-1][n-1] > 0) judge = true;
}
if(judge) cout << "YES" << endl;
else cout << "NO" << endl;
return 0;
}