結果

問題 No.20 砂漠のオアシス
ユーザー snrnsidy
提出日時 2021-04-23 13:27:11
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
RE  
実行時間 -
コード長 1,671 bytes
コンパイル時間 1,355 ms
コンパイル使用メモリ 130,848 KB
最終ジャッジ日時 2025-01-20 23:12:31
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 10 WA * 6 RE * 5
権限があれば一括ダウンロードができます

ソースコード

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];
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 >> oy >> ox;
	oy -= 1;
	ox -= 1;
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < n; j++)
		{
			cin >> board[i][j];
		}
	}

	memset(visited, false, sizeof(visited));

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

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

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

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

		//cout << y << ' ' << x << ' ' << S << '\n';
		if (y == n - 1 && x == n - 1)
		{
			cout << "YES" << '\n';
			return 0;
		}
		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 (ny == oy && nx == ox)
				{
					X = 2 * X;
				}
				if (visited[ny][nx][X] == false)
				{
					visited[ny][nx][X] = true;
					que.push(make_pair(make_pair(ny, nx), X));
				}
			}
		}
	}

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