結果
| 問題 | No.20 砂漠のオアシス |
| コンテスト | |
| ユーザー |
Bantako
|
| 提出日時 | 2018-12-30 18:22:35 |
| 言語 | C++14 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 18 ms / 5,000 ms |
| コード長 | 1,561 bytes |
| 記録 | |
| コンパイル時間 | 1,925 ms |
| コンパイル使用メモリ | 174,612 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-10-08 04:20:28 |
| 合計ジャッジ時間 | 2,799 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 21 |
コンパイルメッセージ
main.cpp:35:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
35 | main(){
| ^~~~
ソースコード
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
typedef pair<int, int> P;
typedef pair<int, P> PP;
int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
int cost[210][210];//cost[i][j] i->jのコスト
int dist[210][210];//距離
int N,V,X,Y;
void dijkstra(int y, int x){
rep(i, 0, N)rep(j, 0, N)dist[i][j] = INF;
//<cost, (座標)>
priority_queue<P, vector<PP>, greater<PP> > 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();
// if(dist[now.first][now.second] < c) continue;
rep(i, 0, 4){
int ny = now.first + dy[i], nx = now.second + dx[i];
if(!(0 <= ny && ny < N && 0 <= nx && 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)));
}
}
}
main(){
cin >> N >> V >> X >> Y;
rep(i,0,N)rep(j,0,N)cin >> cost[i][j];
string ans[] = {"NO", "YES"};
dijkstra(0, 0);
if(dist[N-1][N-1] < V){
cout << "YES" << endl;
return 0;
}
if(X != 0 || Y != 0 && dist[Y-1][X-1] < V){
int ocost = dist[Y-1][X-1];
dijkstra(Y-1, X-1);
if(2 * (V - ocost) > dist[N-1][N-1]){
cout << "YES" << endl;
return 0;
}
}
cout << "NO" << endl;
}
Bantako