結果
| 問題 |
No.20 砂漠のオアシス
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-10-22 17:03:14 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 26 ms / 5,000 ms |
| コード長 | 1,160 bytes |
| コンパイル時間 | 2,415 ms |
| コンパイル使用メモリ | 205,892 KB |
| 最終ジャッジ日時 | 2025-02-24 22:18:08 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 21 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
int dp[200][200][2];
int main(){
cin.tie(nullptr)->sync_with_stdio(false);
int N, V, Ox, Oy;
cin >> N >> V >> Ox >> Oy;
--Ox, --Oy;
vector L(N, vector(N, 0));
for(int i = 0; i < N; ++i){
for(int j = 0; j < N; ++j){
cin >> L[i][j];
}
}
queue<tuple<int, int, int, int>> que;
que.emplace(0, 0, 1, V);
dp[0][0][1] = V;
const int dirs[] = {0, 1, 0, -1, 0};
while(!que.empty()){
auto [y, x, has, vital] = que.front();
que.pop();
if(dp[y][x][has] > vital) continue;
for(int k = 0; k < 4; ++k){
int y2 = y + dirs[k + 1];
int x2 = x + dirs[k];
if(x2 < 0 || x2 >= N || y2 < 0 || y2 >= N) continue;
if(vital <= L[y2][x2]) continue;
int vital2 = vital - L[y2][x2];
int has2 = has;
if(has2 && y2 == Oy && x2 == Ox){
vital2 *= 2;
has2 = 0;
}
if(vital2 > dp[y2][x2][has2]){
dp[y2][x2][has2] = vital2;
que.emplace(y2, x2, has2, vital2);
}
}
}
if(dp[N - 1][N - 1][0] || dp[N - 1][N - 1][1]){
cout << "YES";
} else{
cout << "NO";
}
cout << endl;
return 0;
}