QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#455817#4376. Dragon slayerhorzward#WA 434ms3532kbC++172.0kb2024-06-26 20:41:432024-06-26 20:41:43

Judging History

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

  • [2024-06-26 20:41:43]
  • 评测
  • 测评结果:WA
  • 用时:434ms
  • 内存:3532kb
  • [2024-06-26 20:41:43]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;

struct wall
{
	int id, st, fi;
};

int n, m, k, start, finish;
queue<int> q;
wall hor[20], ver[20];
bool vis[15 * 15 + 5];

vector<int> g[15 * 15+5];

void mk(int x)
{
	bool hwall[20] = {};
	for(int i=0; i<n; i++)
	{
		for(int j=0; j<m; j++)
			hwall[j] = 0;
		for(int j=0; j<k; j++)
		{
			if(!((x>>j) & 1))
				continue;
			if(ver[j].id == -1)
				continue;
			if(ver[j].st <= i && i < ver[j].fi)
				hwall[ver[j].id] = 1;
		}
		for(int j=1; j<m; j++)
		{
			if(hwall[j])
				continue;
			int one = i * m + (j-1), two = i * m + j;
			g[one].push_back(two), g[two].push_back(one);
		}
	}

	for(int j=0; j<m; j++)
	{
		for(int i=0; i<n; i++)
			hwall[i] = 0;
		for(int i=0; i<k; i++)
		{
			if(!((x >> i) & 1))
				continue;
			if(hor[i].id == -1)
				continue;
			if(hor[i].st <= j && j < hor[i].fi)
				hwall[i] = 1;
		}
		for(int i=1; i<n; i++)
		{
			if(hwall[i])
				continue;
			int one = (i-1)*m + j, two = i*m + j;
			g[one].push_back(two), g[two].push_back(one);
		}
	}
}

bool bfs(int rm)
{
	memset(vis, 0, sizeof(vis));
	fill(g, g+n*m, vector<int>());

	mk(rm);
	q.push(start);
	vis[start] = 1;

	while(q.size())
	{
		int now = q.front();
		q.pop();
		for(int i: g[now])
		{
			if(!vis[i])
			{
				vis[i] = 1;
				q.push(i);
			}
		}
	}

	return vis[finish];
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);

	int t;
	cin >> t;
	while(t--)
	{
		cin >> n >> m >> k;
		int w, x, y, z;
		cin >> w >> x >> y >> z;
		start = w * m + x, finish = y * m + z;
		for(int i=0; i<k; i++)
		{
			cin >> w >> x >> y >> z;
			if(w == y)
			{
				hor[i] = {w, x, z};
				ver[i] = {-1, -1, -1};
			}
			else
			{
				ver[i] = {x, w, y};
				hor[i] = {-1, -1, -1};
			}
		}

		int ans = k;
		for(int i=0; i<(1<<k); i++)
		{
			bool now = bfs(i);
			if(now)
				ans = min(ans, k - __builtin_popcount(i));
		}
		cout << ans << "\n";
	}
}

詳細信息

Test #1:

score: 0
Wrong Answer
time: 434ms
memory: 3532kb

input:

10
4 4 4 0 2 3 3
0 2 4 2
1 3 1 0
2 4 2 1
3 1 3 4
3 2 2 0 0 2 1
0 1 3 1
1 0 1 2
3 2 2 0 0 2 1
2 1 2 2
1 0 1 1
15 15 15 3 12 4 1
8 0 8 15
1 11 15 11
1 1 1 15
3 1 3 15
0 10 14 10
14 1 14 14
8 1 8 15
1 5 14 5
0 15 14 15
0 4 14 4
0 2 15 2
11 0 11 15
4 1 4 15
1 11 15 11
1 12 14 12
15 15 15 8 5 14 0
0 12 1...

output:

1
2
0
5
2
6
3
3
1
0

result:

wrong answer 5th lines differ - expected: '3', found: '2'