結果
| 問題 | No.20 砂漠のオアシス |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2018-10-09 18:31:14 |
| 言語 | C++14 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,471 bytes |
| 記録 | |
| コンパイル時間 | 785 ms |
| コンパイル使用メモリ | 76,544 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-10-12 16:37:54 |
| 合計ジャッジ時間 | 1,585 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| 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<<25;
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({-dist[fi][fj],{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[ni][nj] + c){
dist[ni][nj] = mat[ni][nj] + 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] > 0 && (v-dist[0][0])*2-dist[n-1][n-1] > 0) judge = true;
}
if(judge) cout << "YES" << endl;
else cout << "NO" << endl;
return 0;
}