結果
| 問題 |
No.20 砂漠のオアシス
|
| コンテスト | |
| ユーザー |
srjywrdnprkt
|
| 提出日時 | 2022-12-19 12:13:27 |
| 言語 | C++17(clang) (17.0.6 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,299 bytes |
| コンパイル時間 | 1,134 ms |
| コンパイル使用メモリ | 141,680 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-11-18 00:49:59 |
| 合計ジャッジ時間 | 1,819 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 19 WA * 2 |
ソースコード
#include <iostream>
#include <vector>
#include <cmath>
#include <map>
#include <set>
#include <iomanip>
#include <queue>
using namespace std;
template<typename T> using pq = priority_queue<T, vector<T>, greater<T>>;
int main(){
bool ok=0;
int N, V, h, w, oh, ow, alt, d, nh, nw;
cin >> N >> V >> oh >> ow;
oh--; ow--;
swap(oh, ow);
pq<tuple<int, int, int>> que;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
vector<vector<int>> dist(N, vector<int>(N, 1e9));
vector<vector<bool>> visit(N, vector<bool>(N));
vector<vector<int>> field(N, vector<int>(N));
for (int i=0; i < N; i++){
for (int j=0; j<N; j++) cin >> field[i][j];
}
dist[0][0] = field[0][0];
que.push({field[0][0], 0, 0});
while(!que.empty()){
tie(d, h, w) = que.top();
que.pop();
if (visit[h][w]) continue;
visit[h][w] = 1;
for (int dir=0; dir < 4; dir++){
nh = h + dx[dir];
nw = w + dy[dir];
if (nh < 0 || nh >= N || nw < 0 || nw >= N) continue;
alt = dist[h][w] + field[nh][nw];
if (alt < dist[nh][nw]){
dist[nh][nw] = alt;
que.push({dist[nh][nw], nh, nw});
}
}
}
if (dist[N-1][N-1] < V) ok = 1;
for (int i=0; i<N; i++){
for (int j=0; j<N; j++){
dist[i][j] = 1e9; visit[i][j] = 0;
}
}
if (oh >= 0 && oh < N && ow >= 0 && ow < N){
dist[oh][ow] = field[oh][ow];
que.push({field[oh][ow], oh, ow});
while(!que.empty()){
tie(d, h, w) = que.top();
que.pop();
if (visit[h][w]) continue;
visit[h][w] = 1;
for (int dir=0; dir < 4; dir++){
nh = h + dx[dir];
nw = w + dy[dir];
if (nh < 0 || nh >= N || nw < 0 || nw >= N) continue;
alt = dist[h][w] + field[nh][nw];
if (alt < dist[nh][nw]){
dist[nh][nw] = alt;
que.push({dist[nh][nw], nh, nw});
}
}
}
if (dist[0][0] < V && dist[N-1][N-1]-field[oh][ow] < (V-dist[0][0]) * 2) ok = 1;
}
cout << (ok ? "YES" : "NO") << endl;
return 0;
}
srjywrdnprkt