結果

問題 No.20 砂漠のオアシス
ユーザー tkmst201tkmst201
提出日時 2017-05-18 20:03:16
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,545 bytes
コンパイル時間 1,599 ms
コンパイル使用メモリ 151,708 KB
実行使用メモリ 4,692 KB
最終ジャッジ日時 2023-08-03 08:15:14
合計ジャッジ時間 2,814 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,384 KB
testcase_01 AC 2 ms
4,384 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 63 ms
4,692 KB
testcase_06 WA -
testcase_07 AC 53 ms
4,388 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 2 ms
4,384 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 7 ms
4,380 KB
testcase_15 AC 6 ms
4,384 KB
testcase_16 AC 12 ms
4,380 KB
testcase_17 WA -
testcase_18 AC 10 ms
4,384 KB
testcase_19 WA -
testcase_20 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<pii, pii> P;

const ll INF = 1ll<<29;
const ll MOD = 1000000007;
const double EPS  = 1e-10;

int n, v, ox, oy;
int l[200][200];
int dp[200][200][2];

int main() {
	cin >> n >> v >> ox >> oy;
	REP(i, n) REP(j, n) scanf("%d", &l[i][j]);
	ox--; oy--;
	
	memset(dp, -1, sizeof(dp));
	
	priority_queue<P> pq;
	pq.push(P(pii(v, 1), pii(0, 0)));
	if (ox == 0 && oy == 0) pq.push(P(pii(v * 2, 0), pii(0, 0)));
	
	while (!pq.empty()) {
		P now = pq.top(); pq.pop();
		
		int h = now.first.first;
		int f = now.first.second;
		
		int x = now.second.first;
		int y = now.second.second;
		
		if (!chmax(dp[y][x][f], h)) continue;
		
		static int dx[4] = {1,0,-1,0}, dy[4] = {0,1,0,-1};
		
		REP(i, 4) {
			int nx = x + dx[i];
			int ny = y + dy[i];
			
			if (!(nx >= 0 && nx < n && ny >= 0 && ny < n)) continue;
			
			pq.push(P(pii(h - l[ny][nx], f), pii(nx, ny)));
			if (f && nx == ox && ny == oy) pq.push(P(pii((h - l[ny][nx]) * 2, 0), pii(nx, ny)));
		}
	}
	
	if (dp[n - 1][n - 1][0] <= 0 || dp[n - 1][n - 1][1] <= 0) puts("YES");
	else puts("NO");
	
	return 0;
}
0