結果
| 問題 |
No.20 砂漠のオアシス
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2015-04-26 03:18:29 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 29 ms / 5,000 ms |
| コード長 | 1,268 bytes |
| コンパイル時間 | 1,286 ms |
| コンパイル使用メモリ | 164,248 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-10-13 05:07:44 |
| 合計ジャッジ時間 | 2,232 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 21 |
ソースコード
#include "bits/stdc++.h"
using namespace std;
typedef long long Int;
#define REP(i,n) for(int (i)=0;(i)<(int)(n);++(i))
int N;
int OX, OY;
int L[200][200];
int memo[200][200][2];
bool isin(int x, int y) {
return 0 <= x && x < N && 0 <= y && y < N;
}
struct S {
int x, y, v, o;
int& ref() {
return memo[x][y][o];
}
bool operator<(const S& o) const {
return v < o.v;
}
};
const int dx[] = { 0, 1, 0, -1 };
const int dy[] = { 1, 0, -1, 0 };
int main() {
int V;
cin >> N >> V;
cin >> OY >> OX;
OX--;
OY--;
REP(i, N) REP(j, N) cin >> L[i][j];
bool ok = false;
queue<S> pq;
S start;
start.x = 0;
start.y = 0;
start.v = V;
start.o = 0;
start.ref() = V;
pq.push(start);
while (!pq.empty()) {
S cur = pq.front(); pq.pop();
if (cur.v <= 0) continue;
if (cur.x == N-1 && cur.y == N-1) {
ok = true;
break;
}
if (cur.ref() != cur.v) continue;
REP(i, 4) {
int nx = cur.x + dx[i];
int ny = cur.y + dy[i];
if (isin(nx, ny)) {
S next = cur;
next.x = nx;
next.y = ny;
next.v -= L[nx][ny];
if (nx == OX && ny == OY && next.o == 0) {
next.v *= 2;
next.o = 1;
}
if (next.ref() < next.v) {
next.ref() = next.v;
pq.push(next);
}
}
}
}
cout << (ok ? "YES" : "NO") << endl;
}