蒟蒻求调,WA 50pts,样例都没过QwQ
查看原帖
蒟蒻求调,WA 50pts,样例都没过QwQ
521554
Wing_Din_Gaster楼主2025/2/2 19:31

rt,实在是调不出来了TwT

50 pts record, WA on #1,#3,#7,#8,#10

样例输出13而非12 qwq

#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
int n, m, sx, sy, ex, ey;
bool a[51][51];
char dir;
int dis[51][51][4];
const char directions[]{'E', 'S', 'W', 'N'};
const pair<int, int> dpoint[4][3]{
	{
		{1, 0},
		{2, 0},
		{3, 0},
	},
	{
		{0, 1},
		{0, 2},
		{0, 3},
	},
	{
		{-1, 0},
		{-2, 0},
		{-3, 0},
	},
	{
		{0, -1},
		{0, -2},
		{0, -3},
	},
};
int bfs(int x, int y, int dir)
{
	memset(dis, 0x3f, sizeof dis);
	queue<tuple<int, int, int>> q;
	auto push_into_queue = [&q](int x, int y, int dir)
	{
		if (x < 1 || x + 1 > m || y < 1 || y + 1 > n)
			return 1; // out of the map
		else if (a[x][y] || a[x][y + 1] || a[x + 1][y] || a[x + 1][y + 1])
			return 2; // blocked
		else if (dis[x][y][dir] != inf)
			return 3; // visited
		q.push({x, y, dir});
		return 0;
	};
	push_into_queue(x, y, dir);
	dis[x][y][dir] = 0;
	while (!q.empty())
	{
		auto now = q.front();
		int x = get<0>(now), y = get<1>(now), dir = get<2>(now);
		q.pop();
		cerr << "now x = " << x << ", y = " << y << ", direct = " << directions[dir] << ", dis = " << dis[x][y][dir];
		if (x == ex && y == ey)
			return dis[x][y][dir];
		for (int i = 0; i < 3; ++i)
		//	i = 0: Creep
		//	i = 1: Walk
		//	i = 2: Run
		{
			int nx = x + dpoint[dir][i].first, ny = y + dpoint[dir][i].second;
			if (dis[nx][ny][dir] > dis[x][y][dir] + 1)
			{
				int rt = push_into_queue(nx, ny, dir);
				if (rt == 1 || rt == 2)
					break;
				dis[nx][ny][dir] = dis[x][y][dir] + 1;
			}
		}
		int nxtdir = (dir + 1) % 4; // Right
		if (dis[x][y][nxtdir] > dis[x][y][dir] + 1)
			if (!push_into_queue(x, y, nxtdir))
				dis[x][y][nxtdir] = dis[x][y][dir] + 1;
		nxtdir = (dir + 3) % 4; // Left
		if (dis[x][y][nxtdir] > dis[x][y][dir] + 1)
			if (!push_into_queue(x, y, nxtdir))
				dis[x][y][nxtdir] = dis[x][y][dir] + 1;
		cerr << ", ok\n";
	}
	return -1;
}

int main()
{
	cin >> n >> m;
	for (int i = 1; i <= n; ++i)
		for (int j = 1; j <= m; ++j)
			cin >> a[i][j];
	cin >> sy >> sx >> ey >> ex >> dir;
	int direct = dir;
	if (dir == 'E')
		direct = 0;
	else if (dir == 'S')
		direct = 1;
	else if (dir == 'W')
		direct = 2;
	else if (dir == 'N')
		direct = 3;
	cout << bfs(sx, sy, direct);
	return 0;
}

/*
		 ^
		 |
		 3
	<-2- X -0->
		 1
		 |
		 V
(0, 0)---(1, 0)---(2, 0)---(3, 0)
  | (1, 1) | (2, 1) | (3, 1) |
(0, 1)---(1, 1)---(2, 1)---(3, 1)
  | (1, 2) | (2, 2) | (3, 2) |
(0, 2)---(1, 2)---(2, 2)---(3, 2)
  | (1, 3) | (2, 3) | (3, 3) |
(0, 3)---(1, 3)---(2, 3)---(3, 3)
*/
2025/2/2 19:31
加载中...