結果

問題 No.20 砂漠のオアシス
ユーザー msm1993msm1993
提出日時 2019-04-16 13:19:12
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 20 ms / 5,000 ms
コード長 2,155 bytes
コンパイル時間 1,405 ms
コンパイル使用メモリ 167,332 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-22 07:02:12
合計ジャッジ時間 2,582 ms
ジャッジサーバーID
(参考情報)
judge12 / judge9
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
#include "bits/stdc++.h"
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <string>
#include <sstream>
#include <cmath>
#include <stack>
#include <queue>
#include <cctype>
#include <stdio.h>
#include <map>
#include <unordered_map>
#include <string.h>
#include <utility>

typedef long long ll;
const int INF = 1e8;

#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
using namespace std;

typedef pair<int, int> P;
typedef pair<int, P> cost_now;

int n, v, o1, o2;

int x_direction[4] = { 1, -1, 0, 0 };
int y_direction[4] = { 0, 0, 1, -1 };

int desert[201][201];
bool visited[201][201];

int desert_cost[201][201];

void inite() {
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			desert_cost[i][j] = INF;
		}
	}
}

void solve(int y, int x) {
	inite();
	desert_cost[y][x] = 0;

	priority_queue<cost_now, vector<cost_now>, greater<cost_now>> que;

	que.push(cost_now(0, P(y, x)));

	while (!que.empty()) {

		cost_now xyc = que.top();

		int cost = xyc.first;
		P p = xyc.second;

		que.pop();

		for (int i = 0; i < 4; i++) {
			int nx = p.second + x_direction[i];
			int ny = p.first + y_direction[i];

			if (0 <= nx && nx < n && 0 <= ny && ny < n) {
				if (desert_cost[ny][nx] > cost + desert[ny][nx]) {

					desert_cost[ny][nx] = cost + desert[ny][nx];

					que.push(cost_now(desert_cost[ny][nx], P(ny, nx)));
				}
			}
		}

	}
}

int main() {
	cin >> n >> v >> o1 >> o2;

	int tmp = 0;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			cin >> tmp;
			desert[i][j] = tmp;
		}
	}

	solve(0, 0);

/*		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				cout << desert_cost[i][j];
			}
			cout << endl;
		}*/

	if (v - desert_cost[n - 1][n - 1] > 0) {
		cout << "YES" << endl;
		return 0;
	}else if (o1 ==0 && o2 ==0) {
		cout<<"NO"<<endl;
		return 0;
	}

	int h = desert_cost[o2-1][o1-1];

	solve(o2-1,o1-1);

	if(2*(v-h) > desert_cost[n-1][n-1]){
		cout << "YES" << endl;
	}else {
		cout<<"NO"<<endl;
	}

/*
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			cout << desert_cost[i][j]<<" ";
		}
		cout << endl;
	}
*/

	return 0;
}
0