結果
| 問題 |
No.20 砂漠のオアシス
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2015-08-19 16:51:08 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 20 ms / 5,000 ms |
| コード長 | 1,569 bytes |
| コンパイル時間 | 1,551 ms |
| コンパイル使用メモリ | 171,260 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-10-13 05:24:57 |
| 合計ジャッジ時間 | 2,321 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 21 |
ソースコード
#include <bits/stdc++.h>
#define rep(i, a) for (int i = 0; i < (a); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); i++)
#define repr(i, a) for (int i = (a) - 1; i >= 0; i--)
#define repr2(i, a, b) for (int i = (b) - 1; i >= (a); i--)
using namespace std;
typedef long long ll;
const ll inf = 1e9;
const ll mod = 1e9 + 7;
int N, V, Ox, Oy;
int L[200][200];
int dp[200][200][2]; // y, x, oasis
typedef tuple<int, bool, int, int> P; // life, oasis, y, x
int main() {
cin >> N >> V >> Oy >> Ox;
Ox--; Oy--;
rep (j, N) rep (i, N) cin >> L[i][j];
priority_queue<P> q;
q.emplace(V, false, 0, 0);
memset(dp, -1, sizeof(dp));
dp[0][0][0] = V;
while (!q.empty()) {
P p = q.top(); q.pop();
int y = get<2>(p);
int x = get<3>(p);
bool oasis = get<1>(p);
int dy[] = {0, 1, 0, -1};
int dx[] = {1, 0, -1, 0};
rep (k, 4) {
int ny = y + dy[k];
int nx = x + dx[k];
if (ny < 0 || ny >= N || nx < 0 || nx >= N) continue;
if (ny == Oy && nx == Ox && !oasis) {
if (dp[y][x][0] - L[ny][nx] > 0) {
if (dp[ny][nx][1] < (dp[y][x][0] - L[ny][nx]) * 2) {
dp[ny][nx][1] = (dp[y][x][0] - L[ny][nx]) * 2;
q.emplace(dp[ny][nx][1], true, ny, nx);
}
}
}
if (dp[y][x][oasis] - L[ny][nx] > 0) {
if (dp[ny][nx][oasis] < dp[y][x][oasis] - L[ny][nx]) {
dp[ny][nx][oasis] = dp[y][x][oasis] - L[ny][nx];
q.emplace(dp[ny][nx][oasis], oasis, ny, nx);
}
}
}
}
if (dp[N - 1][N - 1][0] > 0 || dp[N - 1][N - 1][1] > 0) {
cout << "YES" << endl;
} else {
cout << "NO" << endl;
}
return 0;
}