QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#740812 | #2662. Bomberman | reverSilly | 0 | 13ms | 57216kb | C++23 | 3.0kb | 2024-11-13 11:39:10 | 2024-11-13 11:39:10 |
Judging History
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));
};
if(mp[i][j]!='X')
{
// conn(0,1);conn(0,2);
conn(1,4);conn(2,3);
conn(3,5);conn(4,5);
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";
return 0;
}
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;)
// {
// cerr<<count(graph[u].begin(),graph[u].end(),v)<<'\n';
// }
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Memory Limit Exceeded
Test #1:
score: 10
Accepted
time: 4ms
memory: 53472kb
input:
5 P..X. X.... ..X.. ....X .X..K
output:
8 1 2 PDDDPDPP
result:
ok
Test #2:
score: 10
Accepted
time: 3ms
memory: 56256kb
input:
5 ....P .XXXX ..... XXXX. K....
output:
16 1 4 LLLLDDPPPPDDLLLL
result:
ok
Test #3:
score: 10
Accepted
time: 9ms
memory: 54728kb
input:
2 PX .K
output:
2 2 1 DP
result:
ok
Test #4:
score: 10
Accepted
time: 8ms
memory: 55816kb
input:
2 P. K.
output:
1 2 1 D
result:
ok
Test #5:
score: 10
Accepted
time: 3ms
memory: 55192kb
input:
2 P. .K
output:
2 2 1 DP
result:
ok
Test #6:
score: 10
Accepted
time: 9ms
memory: 56240kb
input:
2 PX XK
output:
NIE
result:
ok NIE
Test #7:
score: 10
Accepted
time: 13ms
memory: 55404kb
input:
3 P.X ... X.K
output:
4 2 1 DPDP
result:
ok
Test #8:
score: 10
Accepted
time: 6ms
memory: 55660kb
input:
10 XXXX...X.. X.KX.X.... X.....XX.. X.XXX..X.. X.X...X.X. X....X..X. XXXX..X... ......X.XX .XXXXXP... ........X.
output:
21 9 8 PGGPPGGGLGGLLGLLDDLLG
result:
ok
Test #9:
score: 10
Accepted
time: 6ms
memory: 55028kb
input:
10 ......X... .PX...X... .XX.....X. ....X...X. .XXXX..X.. X.....XX.X .......... .X.....XX. .......XK. ..........
output:
18 1 2 GPPDDPPDDDDDDDPPPG
result:
ok
Test #10:
score: 10
Accepted
time: 6ms
memory: 55676kb
input:
9 ....X.... ...X..X.. ..X..X..X .X..X..X. X..X..X.. ..X..X... .XP.X..X. ..XX..XK. .....X...
output:
40 7 4 PGPGPGPGPGGLLDLDLDLDLDLDDDPPPPGPGPGPPDDL
result:
ok
Test #11:
score: 0
Memory Limit Exceeded
input:
1000 .......X...X.....X..........X.X...XX......XXX...XX.............X...X.................X.X......X....XX..XX...........X...XX..XXXXX.XXXX....X.XXXX.....X...X...X......X.......X..XX........X....XX...X.....X.XX.X.XX.X...X.........X.X...X...............X.....XX..X...X.......X.XXXX....X.XX.X......X......
output:
1097 366 683 DDLLDDDLDDDLDDDDDDDDLDDLLDDDLDLLLLDDDDDDLLLLDDDDLLDLLLLDDLDDDLLLLLLLLLDDDDDDDDDDDDDDDDDDLDDLDLDDDDLLLLLLDDLLLDDLDDDDDLDLDDLDDDLDDDLDDDLLDLDLDDDDLDDDLLDDDLLDDLDLDDLLDDLLLLDLDLDDDDDDLDLDDLLDLLDLLDDLLDLDDDLDDDDDDLLLDDDDDLLLDDDDDDDDDDDDDDLDDLLLDLDDDDDDDLDDDLDDDDLDDDDDDDDDDDDLLLDDDDDDDDDDDDD...
result:
Subtask #2:
score: 0
Wrong Answer
Test #28:
score: 20
Accepted
time: 10ms
memory: 56152kb
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: 20
Accepted
time: 6ms
memory: 53128kb
input:
2 PK X#
output:
1 1 2 P
result:
ok
Test #30:
score: 20
Accepted
time: 10ms
memory: 54428kb
input:
2 #K P#
output:
2 1 2 PG
result:
ok
Test #31:
score: 20
Accepted
time: 7ms
memory: 57216kb
input:
50 .................................................. .#..............................................X. ..############################################..X. #.............................................##X. .############################################...X. .............................................
output:
285 37 28 DDDDDDDDLLDDPPDDDDDDDDDDDDDDDDLLGGGGGGGGGGGLLDDDDDDDDDDDLLLLLLLLLLGGGGGGGGLLDDDLLLLLLLLLLLDDDDDLLGGGGGGGGGGGGGPPPPPPPGGGGGGGGLLGGGGGGGLLLLLLLLDDDLLLLLLLLLLLLLLLLLDDPPPPPPPPPPPPPPPPPDDLLLLLLLLLLLLLLLLLDDPPPPPPPPPPPPPPPPPDDLLLLLLLLLLLLLLLLLDDPPPPPPPPPPPPPPPPPDDDDDDDDDDDDDDDLLLLLLLLLLLLL
result:
ok
Test #32:
score: 20
Accepted
time: 8ms
memory: 55804kb
input:
50 K......#####X##################################### ###..#.....#X##################################### ......####.#X##################################### ...###.###.#X##################################### ......#.....X##################################### #####.#..###X#########.................###...
output:
64 12 27 DDDDPPGGGGGGGGGGGGGGGGGLLLLLLLLLLLLLLGGGLGLGLLGGPPGGGLLLLGLLLLLL
result:
ok
Test #33:
score: 20
Accepted
time: 3ms
memory: 54316kb
input:
10 P########X ########## ########## ########## ########## ########## ########## ########## ########## X########K
output:
18 2 10 DPPPPPPPPPDDDDDDDD
result:
ok
Test #34:
score: 0
Wrong Answer
time: 6ms
memory: 55068kb
input:
11 K.......... XXXXXXXXXX. #.......... .XXXXXXXXXX #.........# XXXXXXXXXX. ........... .XXXXXXXXXX ........... XXXXXXXXXX. P..........
output:
NIE
result:
wrong answer
Subtask #3:
score: 0
Skipped
Dependency #2:
0%
Subtask #4:
score: 0
Skipped
Dependency #1:
0%