結果

問題 No.20 砂漠のオアシス
ユーザー たこしたこし
提出日時 2014-11-05 15:18:35
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 2,109 bytes
コンパイル時間 987 ms
コンパイル使用メモリ 102,156 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-21 06:18:09
合計ジャッジ時間 2,679 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <queue>

#define INF 100000000
#define EPS 1e-9

using namespace std;

typedef pair<int, int> P;
typedef long long ll;

#define MAX_N 200

int N, V, Ox, Oy;
int L[MAX_N][MAX_N];

int dx[] = { 1, -1, 0, 0 };
int dy[] = { 0, 0, 1, -1 };

int dp[MAX_N][MAX_N];

void solve(){
	
	queue<P> que;
	queue<int> l;
	queue<bool> oasis;
	que.push(P(0, 0));
	l.push(V);
	oasis.push(true);

	dp[0][0] = V;

	while (que.size()){
		P p = que.front();
		int life = l.front();
		bool flag = oasis.front();

		que.pop();
		l.pop();
		oasis.pop();

		int x = p.first;
		int y = p.second;

		if (x == N - 1 && y == N - 1 && dp[y][x] > 0)
			break;

		for (int i = 0; i < 4; i++){
			int nx = x + dx[i];
			int ny = y + dy[i];
			if (nx >= 0 && nx < N && ny >= 0 && ny < N){
				if (nx == Ox-1 && ny == Oy-1 && Ox != 0 && Oy != 0 && flag){
					if (dp[ny][nx] < (life - L[ny][nx]) * 2){
						dp[ny][nx] = (life - L[ny][nx]) * 2;
						que.push(P(nx, ny));
						l.push((life - L[ny][nx]) * 2);
						oasis.push(false);
					}
				}
				else{
					if (dp[ny][nx] < life - L[ny][nx]){
						dp[ny][nx] = life - L[ny][nx];
						que.push(P(nx, ny));
						l.push(life - L[ny][nx]);
						oasis.push(flag);
					}
				}
			}
		}

	}

}

int main() {

	cin >> N >> V >> Ox >> Oy;
	for (int i = 0; i < N; i++){
		for (int j = 0; j < N; j++){
			cin >> L[i][j];
		}
	}

	solve();

	cout << endl;

	for (int i = 0; i < N; i++){
		for (int j = 0; j < N; j++){
			cout << dp[i][j] << " ";
		}
		cout << endl;
	}

	if (dp[N - 1][N - 1] > 0)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;

	return 0;
}
0