結果
| 問題 |
No.20 砂漠のオアシス
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2015-04-12 12:32:11 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 25 ms / 5,000 ms |
| コード長 | 1,906 bytes |
| コンパイル時間 | 581 ms |
| コンパイル使用メモリ | 74,836 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-10-13 05:05:09 |
| 合計ジャッジ時間 | 1,421 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 21 |
ソースコード
#include <iostream>
#include <vector>
#include <set>
#include <queue>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <fstream>
#include <sstream>
using namespace std;
typedef long long ll;
int N, V, OX, OY;
int L[600][600];
int cost[600][600];
int dy[] = {1,-1,0,0};
int dx[] = {0,0,1,-1};
const int INF = 1 << 25;
int dijkstra(int sx, int sy, int gx, int gy){
for(int i=0;i<N;i++)for(int j=0;j<N;j++)cost[i][j] = INF;
cost[sx][sy] = 0;
priority_queue<pair<int,int>, vector<pair<int,int>>, greater<pair<int,int>>> Q;
Q.push(make_pair(0, sx * N + sy));
while(!Q.empty()){
auto now = Q.top(); Q.pop();
int x = now.second / N;
int y = now.second % N;
int c = now.first;
for(int i=0;i<4;i++){
int nx = x + dx[i];
int ny = y + dy[i];
if(nx < 0 || nx >= N)continue;
if(ny < 0 || ny >= N)continue;
int nc = c + L[nx][ny];
if(nc < cost[nx][ny]){
cost[nx][ny] = nc;
Q.push(make_pair(nc, nx * N + ny));
}
}
}
return cost[gx][gy];
}
int main(){
cin >> N >> V >> OX >> OY;
for(int y=0;y<N;y++){
for(int x=0;x<N;x++){
cin >> L[x][y];
}
}
OX--;
OY--;
bool res = false;
if(OX >= 0 && OY >= 0){
int oasisCost = dijkstra(0, 0, OX, OY);
int nv = V;
nv -= oasisCost;
if(nv > 0){
nv *= 2;
int goalCost = dijkstra(OX, OY, N-1, N-1);
nv -= goalCost;
if(nv > 0){
res = true;
}
}
}
int goalCost = dijkstra(0, 0, N-1, N-1);
if(V - goalCost > 0)res = true;
cout << (res ? "YES" : "NO") << endl;
return 0;
}