QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#95571#5470. Hasty Santa ClausPetroTarnavskyi#TL 0ms0kbC++172.3kb2023-04-10 15:50:222023-04-10 15:50:27

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-04-10 15:50:27]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:0kb
  • [2023-04-10 15:50:22]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define FOR(i, a, b) for (int i = (a); i<(b); ++i)
#define RFOR(i, b, a) for (int i = (b)-1; i>=(a); --i)
#define MP make_pair
#define PB push_back
#define F first
#define S second

typedef long long LL;
typedef pair<int, int> PII;
typedef vector<int> VI;

const int N = 1047;
vector<string> g;
int dis[N][N];
PII from[N][N];
int h, w;
bool super[N][N];
PII ls[N][N];

PII dir[4] = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};

bool ok(int x, int y)
{
	return 0 <= x && x < 2 * h + 1 && 0 <= y && y < 2 * w + 1;
}

void dfs(int x, int y, int d, int px = -1, int py = -1)
{
	from[x][y] = {px, py};
	dis[x][y] = d;
	for (int i = 0; i < 4; i++)
	{
		int nx = x + dir[i].first * 2;
		int ny = y + dir[i].second * 2;
		if (nx == px && ny == py) continue;
		if (ok(nx, ny) && g[x + dir[i].first][y + dir[i].second] == '.')
			dfs(nx, ny, d + 1, x, y);
	}
}

void sup()
{
	int x = 2 * h;
	int y = 2 * w;
	while (x != -1)
	{
		super[x][y] = 1;
		int x2 = from[x][y].first;
		y = from[x][y].second;
		x = x2;
	}
}

void dfs2(int x, int y, int sx = -1, int sy = -1, int px = -1, int py = -1)
{
	if (super[x][y]) sx = x, sy = y;
	ls[x][y] = {sx, sy};
	for (int i = 0; i < 4; i++)
	{
		int nx = x + dir[i].first * 2;
		int ny = y + dir[i].second * 2;
		if (nx == px && ny == py) continue;
		if (ok(nx, ny) && g[x + dir[i].first][y + dir[i].second] == '.')
			dfs2(nx, ny, sx, sy, x, y);
	}
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	cin >> h >> w;
	g.resize(2 * h + 1);
	FOR(i, 0, 2 * h + 1)
	{
		cin >> g[i];
	}
	dfs(1, 1, 0);
	sup();
	dfs2(1, 1);
	int ans = dis[2 * h][2 * w];
	FOR(x, 0, h)
	{
		FOR(y, 0, w)
		{
			FOR(k, 0, 4)
			{
				int nx = x + dir[k].first * 2;
				int ny = y + dir[k].second * 2;
				if (ok(nx, ny) && g[x + dir[k].first][y + dir[k].second] != '.')
				{
					PII s1 = ls[x][y];
					PII s2 = ls[nx][ny];
					if (dis[s1.first][s1.second] >= dis[s2.first][s2.second])
						continue;
					int d1 = dis[x][y] + 1;
					int d2 = dis[nx][ny] - dis[s2.first][s2.second];
					int d3 = dis[2 * h][2 * w] - dis[s2.first][s2.second] + 1;
					ans = max(ans, d1 + d2 + d3);
				}
			}
		}
	}
	cout << ans << '\n';
	
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Time Limit Exceeded

input:

5 1
23 25
23 27
24 25
25 25
25 26

output:


result: