結果
| 問題 | No.20 砂漠のオアシス |
| コンテスト | |
| ユーザー |
こる
|
| 提出日時 | 2017-02-17 17:25:20 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 3,902 bytes |
| 記録 | |
| コンパイル時間 | 686 ms |
| コンパイル使用メモリ | 77,796 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-10-13 05:49:37 |
| 合計ジャッジ時間 | 1,510 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 16 WA * 5 |
ソースコード
#include<iostream>
#include<string>
#include<vector>
#include<set>
#include<algorithm>
#include<queue>
#include<functional>
#define ll long long
#define PLL pair<ll,ll>
#define VS vector<string>
#define VL vector<ll>
#define rep(i,a) for (ll i=0;i<a;i++)
#define nrep(i,n,a) for (ll i=n;i<a;i++)
#define INF 1145141919810
#define VMIN(vec) *std::max_element(vec.begin(),vec.end())
#define VMIN(vec) *std::max_element(vec.begin(),vec.end())
#define TS(n) to_string(n)
using namespace std;
/*
struct NODE {
ll level, dist ,x ,y;
};
bool operator< (const NODE &node1, const NODE &node2) { return node1.dist < node2.dist; }
bool operator> (const NODE &node1, const NODE &node2) { return node1.dist > node2.dist; }
NODE nodes[210][210];
bool flag[210][210];
*/
ll dist[210][210];
ll cost[210][210];
int dy[] = { 1, 0, -1, 0 };
int dx[] = { 0, 1, 0, -1 };
ll N, V, Ox, Oy;
void diskstra(int y, int x){
rep(i, N) rep(j, N) dist[i][j] = INF;
//<cost, (座標)>
priority_queue<PLL, vector<pair<ll,PLL> >, greater<pair<ll,PLL> > > 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, 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)));
}
}
}
/*
void update(priority_queue<NODE ,vector<NODE> ,greater<NODE> > &pq,NODE node,ll x, ll y) {
//cout << "update:" << x << " " << y << flag[x][y]<<endl;
ll cost = node.dist + nodes[x][y].level;
if ( nodes[x][y].dist > cost) {
nodes[x][y].dist = cost;
if (!flag[x][y]) {
flag[x][y] = true;
pq.push(nodes[x][y]);
//cout << "update_pq_size=" << pq.size() << endl;
}
}
}
*/
int main() {
cin >> N >> V >> Ox >> Oy;
rep(i, N) rep(j, N) {
/*
cin >> nodes[i][j].level;
nodes[i][j].dist = INF;
nodes[i][j].x = i; nodes[i][j].y = j; flag[i][j] = false;
*/
cin >> cost[i][j];
}
/*
priority_queue<NODE, vector<NODE>, greater<NODE> > pq;
nodes[0][0].dist = 0;
pq.push(nodes[0][0]);
NODE node;
while (!pq.empty()) {
node = pq.top(); pq.pop();
//cout << node.x << " " << node.y << endl;
flag[node.x][node.y] = false;
if (node.x > 0) { update(pq, node, node.x - 1, node.y); }
if (node.x < N - 1) { update(pq, node, node.x + 1, node.y); }
if (node.y > 0) { update(pq, node, node.x, node.y - 1); }
if (node.y < N - 1) { update(pq, node, node.x, node.y + 1); }
//cout << "main_pq_size=" << pq.size() << endl;
}ll start_to_end = V - nodes[N - 1][N - 1].dist;
if (nodes[N-1][N-1].dist<V){
cout << "YES" << endl;
return 0;
}
if (Ox == 0 && Oy == 0){
cout << "NO" << endl;
return 0;
}
ll start_to_O = (V - nodes[Ox - 1][Oy - 1].dist)*2;
rep(i, N) rep(j, N) nodes[i][j].dist = INF;
nodes[Ox - 1][Oy - 1].dist = 0;
pq.push(nodes[Ox - 1][Oy - 1]);
while (!pq.empty()) {
node = pq.top(); pq.pop();
//cout << node.x << " " << node.y << endl;
flag[node.x][node.y] = false;
if (node.x > 0) { update(pq, node, node.x - 1, node.y); }
if (node.x < N - 1) { update(pq, node, node.x + 1, node.y); }
if (node.y > 0) { update(pq, node, node.x, node.y - 1); }
if (node.y < N - 1) { update(pq, node, node.x, node.y + 1); }
//cout << "main_pq_size=" << pq.size() << endl;
}
if (nodes[N-1][N-1].dist<start_to_O){
cout << "YES" << endl;
}
else{
cout << "NO" << endl;
}
*/
diskstra(0, 0);
if (dist[N - 1][N - 1] < V){
cout << "YES" << endl;
return 0;
}
if (Oy == 0 && Ox == 0){
cout << "NO" << endl;
return 0;
}
ll start_to_O = (V - dist[Ox - 1][Oy - 1]) * 2;
diskstra(Ox - 1, Oy - 1);
if (start_to_O > dist[N - 1][N - 1]){
cout << "YES" << endl;
}
else{
cout << "NO" << endl;
}
return 0;
}
こる