結果
| 問題 |
No.20 砂漠のオアシス
|
| コンテスト | |
| ユーザー |
h_noson
|
| 提出日時 | 2016-05-18 13:38:01 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 18 ms / 5,000 ms |
| コード長 | 1,393 bytes |
| コンパイル時間 | 715 ms |
| コンパイル使用メモリ | 81,232 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-10-13 05:37:05 |
| 合計ジャッジ時間 | 1,545 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 21 |
ソースコード
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <iomanip>
using namespace std;
#define RREP(i,s,e) for (i = s; i >= e; i--)
#define rrep(i,n) RREP(i,(int)(n)-1,0)
#define REP(i,s,e) for (i = s; i <= e; i++)
#define rep(i,n) REP(i,0,(int)(n)-1)
#define INF 100000000
typedef long long ll;
int main() {
int i, j, n, v, ox, oy;
int l[201][201];
int hp[2][201][201] {};
priority_queue<tuple<int,int,int,bool>> q; // (hp,x,y,oasis)
cin >> n >> v >> ox >> oy;
REP (i,1,n) REP (j,1,n) cin >> l[i][j];
q.push(make_tuple(v,1,1,0));
hp[0][1][1] = v;
while (!q.empty()) {
int y = get<1>(q.top());
int x = get<2>(q.top());
bool oasis = get<3>(q.top());
q.pop();
int dxy[4] = {-1,0,1,0};
rep (i,4) {
int nx = x + dxy[i];
int ny = y + dxy[(i+1)%4];
if (nx < 1 || nx > n || ny < 1 || ny > n)
continue;
bool noasis = oasis || nx == ox && ny == oy;
int nhp = (hp[oasis][y][x] - l[ny][nx]) * (noasis != oasis ? 2 : 1);
if (hp[noasis][ny][nx] < nhp) {
hp[noasis][ny][nx] = nhp;
q.push(make_tuple(nhp,ny,nx,noasis));
}
}
}
if (hp[0][n][n] || hp[1][n][n])
cout << "YES" << endl;
else
cout << "NO" << endl;
return 0;
}
h_noson