QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#740872#2662. BombermanreverSilly0 8ms56260kbC++233.6kb2024-11-13 11:58:292024-11-13 11:58:29

Judging History

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

  • [2024-11-13 11:58:29]
  • 评测
  • 测评结果:0
  • 用时:8ms
  • 内存:56260kb
  • [2024-11-13 11:58:29]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
constexpr int mxn{1005},mxp{mxn*mxn*6};
forward_list<int>graph[mxp];
int dis[mxp],pre[mxp],n,s,t;
char mp[mxn][mxn];
void bfs(int s)
{
	fill_n(dis,n*n*6,1e9);
	fill_n(pre,n*n*6,-1);
	list<int>Q;
	dis[s]=0;
	Q.push_back(s);
	while(!Q.empty())
	{
		int u=Q.front();Q.pop_front();
		for(int v:graph[u])
		{
			if(dis[v]==1e9)
			{
				if(v%(n*n)==u%(n*n))
				{
					dis[v]=dis[u];
					Q.push_front(v);
				}
				else
				{
					dis[v]=dis[u]+1;
					Q.push_back(v);
				}
				pre[v]=u;
			}
		}
	}
}
int point(int x,int y,int layer)
{
	return n*n*layer+x*n+y;
}
bool canpass(char ch)
{
	return ch=='P'||ch=='K'||ch=='.';
}
void addedge(int u,int v)
{
	graph[u].push_front(v);
}
void addedge2(int u,int v)
{
	// cerr<<u<<' '<<v<<'\n';
	addedge(u,v);
	addedge(v,u);
}
forward_list<int>getpath(int t)
{
	forward_list<int>res;
	for(;t!=-1;t=pre[t])
		res.push_front(t);
	return res;
}
void print(forward_list<int>const&p)
{
	for(auto it=p.begin(),jt=next(it);jt!=p.end();++it,++jt)
	{
		if(*it<3*n*n&&*jt>=3*n*n&&*it%(n*n)==*jt%(n*n))
		{
			int p=*it%(n*n);
			cout<<p/n+1<<' '<<p%n+1<<'\n';
			return;
		}
	}
	for(int i=0;i<n;++i)
	{
		for(int j=0;j<n;++j)
		{
			if(canpass(mp[i][j]))
			{
				cout<<i+1<<' '<<j+1<<'\n';
				return;
			}
		}
	}
}
int main()
{
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cin>>n;
	for(int i=0;i<n;++i)
		for(int j=0;j<n;++j)
			cin>>mp[i][j];
	for(int i=0;i<n;++i)
	{
		for(int j=0;j<n;++j)
		{
			if(i&&canpass(mp[i][j])&&canpass(mp[i-1][j]))
				for(int l:{0,5})
					addedge2(point(i,j,l),point(i-1,j,l));
			if(j&&canpass(mp[i][j])&&canpass(mp[i][j-1]))
				for(int l:{0,5})
					addedge2(point(i,j,l),point(i,j-1,l));
			auto conn=[i,j](int lu,int lv){
				addedge(point(i,j,lu),point(i,j,lv));
			};
			auto conn2=[i,j](int di,int dj){
				int x=i+di,y=j+dj;
				if(0<=x&&x<n)
				{
					if(0<=y&&y<n)
					{
						addedge(point(i,j,3),point(x,y,5));
						addedge(point(i,j,4),point(x,y,5));
					}
				}
			};
			if(mp[i][j]!='X')
			{
				// conn(0,1);conn(0,2);
				conn(1,4);conn(2,3);
				// conn(3,5);conn(4,5);
				conn2(0,1);conn2(0,-1);
				conn2(1,0);conn2(-1,0);
				if(mp[i][j]=='P')
					s=point(i,j,0);
				if(mp[i][j]=='K')
					t=point(i,j,5);
			}
		}
	}
	for(int i=0;i<n;++i)
	{
		for(int j=0;j<n;++j)
		{
			if(mp[i][j]!='X')
			{
				if(i&&mp[i-1][j]!='X')
				{
					for(int l:{1,3})
						addedge2(point(i,j,l),point(i-1,j,l));
					addedge(point(i,j,0),point(i-1,j,2));
					addedge(point(i-1,j,0),point(i,j,2));
				}
				if(j&&mp[i][j-1]!='X')
				{
					for(int l:{2,4})
						addedge2(point(i,j,l),point(i,j-1,l));
					addedge(point(i,j,0),point(i,j-1,1));
					addedge(point(i,j-1,0),point(i,j,1));
				}
			}
			
		}
	}
	bfs(s);
	if(dis[t]==1e9)
	{
		cout<<"NIE\n";
	}
	else
	{
		cout<<dis[t]<<'\n';
		auto p=getpath(t);
		print(p);
		int last=s;
		for(int i:p)
		{
			i%=n*n;
			if(i!=last)
			{
				if(i==last+1)
					cout<<'P';
				if(i==last-1)
					cout<<'L';
				if(i==last+n)
					cout<<'D';
				if(i==last-n)
					cout<<'G';
				last=i;
			}
		}
	}
	// for(int i:getpath(t))
	// 	cerr<<i<<' ';
	// for(int u,v;cin>>u>>v;)
	// {
	// 	if(v==-1)
	// 	{

	// 	}
	// 	cerr<<count(graph[u].begin(),graph[u].end(),v)<<'\n';
	// }
	return 0;
}
// 11
// K..........
// XXXXXXXXXX.
// #..........
// .XXXXXXXXXX
// #.........#
// XXXXXXXXXX.
// ...........
// .XXXXXXXXXX
// ...........
// XXXXXXXXXX.
// P..........
// ans:
// 70
// 5 1

詳細信息

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 10
Accepted
time: 8ms
memory: 56260kb

input:

5
P..X.
X....
..X..
....X
.X..K

output:

8
4 2
PDDDPPDP

result:

ok 

Test #2:

score: 10
Accepted
time: 7ms
memory: 54528kb

input:

5
....P
.XXXX
.....
XXXX.
K....

output:

16
1 4
LLLLDDPPPPDDLLLL

result:

ok 

Test #3:

score: 10
Accepted
time: 3ms
memory: 55088kb

input:

2
PX
.K

output:

2
2 1
DP

result:

ok 

Test #4:

score: 0
Wrong Answer
time: 3ms
memory: 54716kb

input:

2
P.
K.

output:

3
2 2
DPL

result:

wrong answer 

Subtask #2:

score: 0
Wrong Answer

Test #28:

score: 20
Accepted
time: 7ms
memory: 55344kb

input:

10
..........
.########.
.#......#.
.#X##X#.#.
.#X#P.#X#.
.#X#..#X#.
.#X####X#.
.#XXXXX.#.
.#X####X#.
..X..K....

output:

16
4 7
PPGPPPDDDDDDLLLL

result:

ok 

Test #29:

score: 0
Wrong Answer
time: 3ms
memory: 54752kb

input:

2
PK
X#

output:

3
2 2
PDG

result:

wrong answer 

Subtask #3:

score: 0
Skipped

Dependency #2:

0%

Subtask #4:

score: 0
Skipped

Dependency #1:

0%