結果

問題 No.20 砂漠のオアシス
ユーザー snrnsidysnrnsidy
提出日時 2021-04-23 14:09:22
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 758 ms / 5,000 ms
コード長 2,002 bytes
コンパイル時間 1,251 ms
コンパイル使用メモリ 136,100 KB
実行使用メモリ 84,444 KB
最終ジャッジ日時 2023-09-17 11:04:24
合計ジャッジ時間 4,274 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 24 ms
82,396 KB
testcase_01 AC 23 ms
82,324 KB
testcase_02 AC 23 ms
82,360 KB
testcase_03 AC 25 ms
82,516 KB
testcase_04 AC 35 ms
82,568 KB
testcase_05 AC 29 ms
82,596 KB
testcase_06 AC 39 ms
82,644 KB
testcase_07 AC 758 ms
84,444 KB
testcase_08 AC 112 ms
82,896 KB
testcase_09 AC 424 ms
83,700 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 23 ms
82,396 KB
testcase_12 AC 31 ms
82,476 KB
testcase_13 AC 32 ms
82,512 KB
testcase_14 AC 67 ms
82,672 KB
testcase_15 AC 47 ms
82,724 KB
testcase_16 AC 107 ms
82,832 KB
testcase_17 AC 64 ms
82,744 KB
testcase_18 AC 92 ms
82,828 KB
testcase_19 AC 94 ms
82,820 KB
testcase_20 AC 26 ms
82,628 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <cstdlib>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional> 
#include <iomanip>
#include <unordered_map>
#include <memory.h>
#include <unordered_set>
#include <fstream>
#include <random>

using namespace std;

bool visited[201][201][1001][2];
int board[201][201];
int dy[4] = { -1,0,1,0 };
int dx[4] = { 0,1,0,-1 };

int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);

	int n, v, ox, oy;
	cin >> n >> v >> ox >> oy;
	oy -= 1;
	ox -= 1;
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < n; j++)
		{
			cin >> board[i][j];
		}
	}

	if(v<=board[0][0])
	{
		cout << "NO" << '\n';
		return 0;
	}
	memset(visited, false, sizeof(visited));

	visited[0][0][v][0] = true;

	queue <pair<pair<int, int>, pair<int, int>>> que;

	que.push(make_pair(make_pair(0, 0), make_pair(v, 0)));

	while (!que.empty())
	{
		int y = que.front().first.first;
		int x = que.front().first.second;
		int S = que.front().second.first;
		int f = que.front().second.second;
		que.pop();

		//cout << y << ' ' << x << ' ' << S << '\n';
		if (y == n - 1 && x == n - 1)
		{
			cout << "YES" << '\n';
			return 0;
		}
		if (y == oy && x == ox)
		{
			if (f == 0)
			{
				if (2*S<=1000 && visited[y][x][2*S][1] == false)
				{
					visited[y][x][2*S][1] = true;
					que.push(make_pair(make_pair(y, x), make_pair(2*S, 1)));
				}
			}
		}
		for (int k = 0; k < 4; k++)
		{
			int ny = y + dy[k];
			int nx = x + dx[k];
			if (ny < 0 || ny >= n || nx < 0 || nx >= n)
			{
				continue;
			}
			if (S > board[ny][nx])
			{
				int X = S - board[ny][nx];
				if (X <= 1000 && visited[ny][nx][X][f] == false)
				{
					visited[ny][nx][X][f] = true;
					que.push(make_pair(make_pair(ny, nx), make_pair(X, f)));
				}
			}
		}
	}

	cout << "NO" << '\n';
	return 0;
}
0