結果
| 問題 |
No.20 砂漠のオアシス
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2015-04-25 23:34:14 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,372 bytes |
| コンパイル時間 | 1,243 ms |
| コンパイル使用メモリ | 163,304 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-10-13 05:07:39 |
| 合計ジャッジ時間 | 1,992 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 17 WA * 4 |
ソースコード
#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;
int y;
int v;
int o;
int& ref() {
return memo[x][y][o];
}
bool operator<(const S& o) const {
return v < o.v;
}
};
int dx[] = { 0, 1, 0, -1 };
int dy[] = { 1, 0, -1, 0 };
int main() {
int V;
cin >> N >> V;
cin >> ox >> oy;
ox--;
oy--;
REP(i, N) REP(j, N) cin >> L[i][j];
bool ok = false;
priority_queue<S> pq;
S start;
V -= L[0][0];
start.x = 0;
start.y = 0;
start.v = V;
start.o = 0;
start.ref() = V;
pq.push(start);
while (!pq.empty()) {
S cur = pq.top(); pq.pop();
if (cur.v <= 0) continue;
if (cur.x == N-1 && cur.y == N-1) {
ok = true;
break;
}
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 (next.x == ox && next.y == oy && next.o == 0) {
next.v *= 2;
next.o = 1;
if (next.v > next.ref()) {
next.ref() = next.v;
pq.push(next);
}
}
else {
if (next.v > next.ref()) {
next.ref() = next.v;
pq.push(next);
}
}
}
}
}
cout << (ok ? "YES" : "NO") << endl;
}