답안 #1001184

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1001184 2024-06-18T16:40:20 Z aykhn Soccer (JOI17_soccer) C++17
100 / 100
391 ms 27188 KB
#include <bits/stdc++.h>

using namespace std;

#define int long long
#define inf 0x3F3F3F3F3F3F3F3F

const int MXN = 5e2 + 5;

int h, w;
int d[5][MXN][MXN];
int d1[MXN][MXN];

int A[4] = {0, 0, -1, 1}, B[4] = {-1, 1, 0, 0};

int ok(int x, int y)
{
	return (x >= 0 && x <= h && y >= 0 && y <= w);
}

signed main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	for (int i = 0; i < MXN; i++) 
	{
		for (int j = 0; j < MXN; j++) 
		{
			d1[i][j] = inf;
			for (int k = 0; k < 5; k++) d[k][i][j] = inf;
		}
	}
	cin >> h >> w;
	int a, b, c;
	cin >> a >> b >> c;
	int n;
	cin >> n;
	priority_queue<array<int, 4>, vector<array<int, 4>>, greater<array<int, 4>>> pq;
	priority_queue<array<int, 3>, vector<array<int, 3>>, greater<array<int, 3>>> pq1;
	array<int, 2> cor[n];
	for (int i = 0; i < n; i++)
	{
		int x, y;
		cin >> x >> y;
		cor[i] = {x, y};
		d1[x][y] = 0;
		pq1.push({0, x, y});
	}
	while (!pq1.empty())
	{
		int W = pq1.top()[0], x = pq1.top()[1], y = pq1.top()[2];
		pq1.pop();
		if (d1[x][y] < W) continue;
		for (int i = 0; i < 4; i++)
		{
			int x1 = x + A[i], y1 = y + B[i];
			if (ok(x1, y1) && d1[x1][y1] > W + c)
			{
				d1[x1][y1] = W + c;
				pq1.push({d1[x1][y1], x1, y1});
			}
		}
	}
	pq.push({0, 4, cor[0][0], cor[0][1]});
	d[4][cor[0][0]][cor[0][1]] = 0;
	while (!pq.empty())
	{
		int W = pq.top()[0], t = pq.top()[1], x = pq.top()[2], y = pq.top()[3];
		pq.pop();
		if (d[t][x][y] < W) continue;
		if (d[4][x][y] > W + d1[x][y])
		{
			d[4][x][y] = W + d1[x][y];
			pq.push({d[4][x][y], 4, x, y});
		}
		if (t == 4)
		{
			for (int i = 0; i < 4; i++)
			{
				int x1 = x + A[i], y1 = y + B[i];
				if (ok(x1, y1) && d[4][x1][y1] > W + c)
				{
					d[4][x1][y1] = W + c;
					pq.push({d[4][x1][y1], 4, x1, y1});
				}
				if (ok(x1, y1) && d[i][x1][y1] > W + c)
				{
					d[i][x1][y1] = W + b + a;
					pq.push({d[i][x1][y1], i, x1, y1});
				}
			}
		}
		else
		{
			int x1 = x + A[t], y1 = y + B[t];
			if (ok(x1, y1) && d[t][x1][y1] > W + a)
			{
				d[t][x1][y1] = W + a;
				pq.push({d[t][x1][y1], t, x1, y1});
			}
		}
	}
	int res = inf;
	for (int i = 0; i < 5; i++) res = min(res, d[i][cor[n - 1][0]][cor[n - 1][1]]);
	cout << res << '\n';
}
# 결과 실행 시간 메모리 Grader output
1 Correct 67 ms 14556 KB Output is correct
2 Correct 2 ms 12376 KB Output is correct
3 Correct 249 ms 22076 KB Output is correct
4 Correct 266 ms 20936 KB Output is correct
5 Correct 68 ms 12660 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 270 ms 20864 KB Output is correct
2 Correct 263 ms 21888 KB Output is correct
3 Correct 217 ms 20920 KB Output is correct
4 Correct 212 ms 20568 KB Output is correct
5 Correct 255 ms 20856 KB Output is correct
6 Correct 229 ms 21180 KB Output is correct
7 Correct 246 ms 22208 KB Output is correct
8 Correct 248 ms 23104 KB Output is correct
9 Correct 304 ms 22204 KB Output is correct
10 Correct 44 ms 14796 KB Output is correct
11 Correct 254 ms 22720 KB Output is correct
12 Correct 256 ms 22140 KB Output is correct
13 Correct 174 ms 21176 KB Output is correct
14 Correct 297 ms 22156 KB Output is correct
15 Correct 225 ms 22848 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 67 ms 14556 KB Output is correct
2 Correct 2 ms 12376 KB Output is correct
3 Correct 249 ms 22076 KB Output is correct
4 Correct 266 ms 20936 KB Output is correct
5 Correct 68 ms 12660 KB Output is correct
6 Correct 270 ms 20864 KB Output is correct
7 Correct 263 ms 21888 KB Output is correct
8 Correct 217 ms 20920 KB Output is correct
9 Correct 212 ms 20568 KB Output is correct
10 Correct 255 ms 20856 KB Output is correct
11 Correct 229 ms 21180 KB Output is correct
12 Correct 246 ms 22208 KB Output is correct
13 Correct 248 ms 23104 KB Output is correct
14 Correct 304 ms 22204 KB Output is correct
15 Correct 44 ms 14796 KB Output is correct
16 Correct 254 ms 22720 KB Output is correct
17 Correct 256 ms 22140 KB Output is correct
18 Correct 174 ms 21176 KB Output is correct
19 Correct 297 ms 22156 KB Output is correct
20 Correct 225 ms 22848 KB Output is correct
21 Correct 83 ms 13668 KB Output is correct
22 Correct 353 ms 20860 KB Output is correct
23 Correct 339 ms 17472 KB Output is correct
24 Correct 374 ms 18372 KB Output is correct
25 Correct 294 ms 22196 KB Output is correct
26 Correct 350 ms 22588 KB Output is correct
27 Correct 222 ms 17408 KB Output is correct
28 Correct 251 ms 20924 KB Output is correct
29 Correct 333 ms 23484 KB Output is correct
30 Correct 218 ms 18380 KB Output is correct
31 Correct 277 ms 22496 KB Output is correct
32 Correct 391 ms 27188 KB Output is correct
33 Correct 249 ms 20832 KB Output is correct
34 Correct 362 ms 21432 KB Output is correct
35 Correct 229 ms 18896 KB Output is correct