답안 #1085511

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1085511 2024-09-08T11:05:33 Z I_am_Polish_Girl Maze (JOI23_ho_t3) C++14
0 / 100
0 ms 348 KB
#pragma target("arch=icelake-server")

#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <stack> 
#include <queue>
#include <cmath>
#include <random>
#include <chrono>
#include <iomanip>
#include <bitset>

using namespace std;

#define int long long

typedef long long ll;
typedef long double ld;

int log_ = 21;
int inf = 4000000007000000007;

long long mod = 998244353;

int p = 499;

int NADIYA = 39;

signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);

	int n, m, k;
	cin >> n >> m >> k;

	int i_st, j_st;
	cin >> i_st >> j_st;

	i_st--;
	j_st--;

	int i_f, j_f;
	cin >> i_f >> j_f;

	i_f--;
	j_f--;


	vector <vector <int>> deep(n);
	vector <vector <int>> t(n);

	for (int i = 0; i < n; i++)
	{
		deep[i].resize(m , inf);
		t[i].resize(m, false);
	}

	vector <string> vs(n);
	for (int i = 0; i < n; i++)
		cin >> vs[i];
	

	vector <vector < pair <int, int>>> q(n*m+2);

	q[0].push_back({i_st , j_st});
	deep[i_st][j_st] = 0;

	vector <pair <int, int>> go;

	go.push_back({ 1 , 0 });
	go.push_back({ -1 , 0 });
	go.push_back({ 0 , 1 });
	go.push_back({ 0 , -1 });


	vector <pair <int, int>> go2;

	for (int i = -n; i <= n; i++)
	{
		for (int j = -n; j <= n; j++)
		{
			go2.push_back({ i , j });
		}
	}
	


	for (int d = 0 ; d < n*m+1  ; d++)
	{
		if (q[d].size() == 0)
			break;

		for (int ind = 0; ind < q[d].size(); ind++)
		{
			int i_ = q[d][ind].first;
			int j_ = q[d][ind].second;


			for (int i = 0; i < 4; i++)
			{
				int i__ = i_ + go[i].first;
				int j__ = j_ + go[i].second;

				if ((i__ >= 0) and (i__ < n))
				{
					if ((j__ >= 0) and (j__ < m))
					{
						if (deep[i__][j__] > d)
						{
							if (vs[i__][j__] == '.')
							{
								deep[i__][j__] = d;
								q[d].push_back({i__ , j__});
							}
						}
					}
				}
			}
		}

		for (int ind = 0; ind < q[d].size(); ind++)
		{
			int i_ = q[d][ind].first;
			int j_ = q[d][ind].second;

			for (int i = -k-1; i <= k+1; i++)
			{
				for (int j = -k; j <= k; j += 2*k)
				{
					if (abs(i) + abs(j) == 2 * k)
						continue;

					int i__ = i_ + i;
					int j__ = j_ + j;

					if ((i__ >= 0) and (i__ < n))
					{
						if ((j__ >= 0) and (j__ < m))
						{
							if (deep[i__][j__] == inf)
							{
								deep[i__][j__] = d + 1;
								q[d+1].push_back({i__ , j__});
							}
						}
					}
				}
			}


			for (int i = -k ; i <= k ; i += k)
			{
				for (int j = -k; j <= k; j ++)
				{
					if (abs(i) + abs(j) == 2 * k)
						continue;

					int i__ = i_ + i;
					int j__ = j_ + j;

					if ((i__ >= 0) and (i__ < n))
					{
						if ((j__ >= 0) and (j__ < m))
						{
							if (deep[i__][j__] == inf)
							{
								deep[i__][j__] = d + 1;
								q[d + 1].push_back({ i__ , j__ });
							}
						}
					}
				}
			}
		}	
	}

	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < m; j++)
		{
			if (abs(i - i_f) <= k)
			{
				if (abs(j - j_f) <= k)
				{
					if ((abs(i - i_f) + abs(j - j_f)) != 2 * k)
					{
						deep[i_f][j_f] = min(deep[i_f][j_f], deep[i][j] + 1);
					}
				}
			}
		}
	}

	cout << deep[i_f][j_f];
}

/*5
1 2 1
2 3 1
2 4 1
1 5 4
*/

Compilation message

Main.cpp:1: warning: ignoring '#pragma target ' [-Wunknown-pragmas]
    1 | #pragma target("arch=icelake-server")
      | 
Main.cpp: In function 'int main()':
Main.cpp:100:25: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  100 |   for (int ind = 0; ind < q[d].size(); ind++)
      |                     ~~~~^~~~~~~~~~~~~
Main.cpp:128:25: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  128 |   for (int ind = 0; ind < q[d].size(); ind++)
      |                     ~~~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -