QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#259622 | #2662. Bomberman | mikefeng | 0 | 1ms | 5940kb | C++14 | 4.2kb | 2023-11-21 08:12:46 | 2023-11-21 08:12:47 |
answer
bool M1;
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<climits>
#include<iomanip>
#include<cassert>
#include<random>
#include<cstdio>
#include<vector>
#include<bitset>
#include<stack>
#include<queue>
#include<deque>
#include<cmath>
#include<ctime>
#include<map>
#include<set>
//#include<ext/pb_ds/assoc_container.hpp>
//#include<ext/pb_ds/hash_policy.hpp>
//#include<ext/pb_ds/priority_queue.hpp>
#define fi first
#define se second
#define ll long long
#define Vector Point
#define I128 __int128
#define LD long double
#define ull unsigned ll
#define pii pair<ll,int>
#define pb(x) push_back(x)
#define syt cerr<<"sytakioi\n"
#define F(i,a,b) for(int i=a,i##end=b;i<=i##end;++i)
#define UF(i,a,b) for(int i=a,i##end=b;i>=i##end;--i)
#define look_memory cerr<<abs(&M2-&M1)/1024.0/1024<<'\n'
#define rd_i(l,r) uniform_int_distribution<int>(l,r)(rd)
#define rd_r(l,r) uniform_real_distribution<double>(l,r)(rd)
#define look_time cerr<<(clock()-Time)*1.0/CLOCKS_PER_SEC<<'\n'
using namespace std;
//using namespace __gnu_cxx;
mt19937 rd(time(0));
const int N=1005;
int fx[4]={0,1,0,-1};
int fy[4]={1,0,-1,0};
int n,sx,sy,tx,ty,ans;
int hx,hy,lx,ly,f;
char c[N][N];
int dis1[N][N],dis2[N][N];
pii lst1[N][N],lst2[N][N];
inline void solve(int x,int y,int dis[][N],pii lst[][N]){
F(i,1,n) F(j,1,n) dis[i][j]=0x3f3f3f3f;
queue<pii> q;
dis[x][y]=0;
q.emplace(x,y);
while(!q.empty()){
pii tmp=q.front();q.pop();
int x=tmp.fi,y=tmp.se;
F(i,0,3){
int tx=x+fx[i],ty=y+fy[i];
if(!tx||!ty||tx>n||ty>n||c[tx][ty]=='X'||dis[tx][ty]<=dis[x][y]+1) continue;
dis[tx][ty]=dis[x][y]+1;
lst[tx][ty]={x,y};
if(c[tx][ty]!='#') q.emplace(tx,ty);
}
}
F(i,1,n){F(j,1,n) cout<<dis[i][j]<<' ';cout<<'\n';}cout<<'\n';
}
vector<pii> res;
inline void out(pii x,pii y){
if(x.se+1==y.se) cout<<"P";
if(x.se==y.se+1) cout<<"L";
if(x.fi+1==y.fi) cout<<"D";
if(x.fi==y.fi+1) cout<<"G";
}
inline void out1(pii x){
if(!x.fi||!x.se) return;
out1(lst1[x.fi][x.se]);
res.emplace_back(x);
}
inline void out2(pii x){
if(!x.fi||!x.se) return;
res.emplace_back(x);
out2(lst2[x.fi][x.se]);
}
bool M2;
signed main(){
int Time=clock();
look_memory;
cin.tie(nullptr)->sync_with_stdio(false);
cin>>n;
ans=n*n+1;
F(i,1,n) cin>>(c[i]+1);
F(i,1,n) F(j,1,n){
if(c[i][j]=='P') sx=i,sy=j;
if(c[i][j]=='K') tx=i,ty=j;
}
solve(sx,sy,dis1,lst1);
solve(tx,ty,dis2,lst2);
F(i,1,n){
F(j,1,n) if(c[i][j]!='X'){
int l=i,r=i;
while(l&&c[l][j]!='X') --l;++l;
while(r<=n&&c[r][j]!='X') ++r;--r;
int L=j,R=j;
while(L&&c[i][L]!='X') --L;++L;
while(R<=n&&c[i][R]!='X') ++R;--R;
pii mn1={1e9,0},mn2={1e9,0};
F(k,L,R) mn1=min(mn1,{dis2[i][k]+abs(k-j),k});
F(k,l,r) mn2=min(mn2,{dis1[k][j]+abs(k-i),k});
// if(i==2&&j==3) cout<<mn1.fi<<' '<<mn1.se<<'\n'<<mn2.fi<<' '<<mn2.se<<'\n';
if(mn1.fi+mn2.fi<ans){
ans=mn1.fi+mn2.fi;
hx=i;hy=mn1.se;
lx=mn2.se;ly=j;
f=0;
}
}
}
F(i,1,n){
F(j,1,n) if(c[i][j]!='X'){
int l=i,r=i;
while(l&&c[l][j]!='X') --l;++l;
while(r<=n&&c[r][j]!='X') ++r;--r;
int L=j,R=j;
while(L&&c[i][L]!='X') --L;++L;
while(R<=n&&c[i][R]!='X') ++R;--R;
pii mn1={1e9,0},mn2={1e9,0};
F(k,L,R) mn1=min(mn1,{dis1[i][k]+abs(k-j),k});
F(k,l,r) mn2=min(mn2,{dis2[k][j]+abs(k-i),k});
if(mn1.fi+mn2.fi<ans){
ans=mn1.fi+mn2.fi;
hx=i;hy=mn1.se;
lx=mn2.se;ly=j;
f=1;
}
}
}
if(ans==n*n+1) cout<<"NIE\n";
else if(f){
cout<<ans<<'\n'<<hx<<' '<<ly<<'\n';
out1(lst1[hx][hy]);
if(hy>ly) UF(i,hy,ly) res.emplace_back(hx,i);
else F(i,hy,ly) res.emplace_back(hx,i);
if(hx>lx) UF(i,hx-1,lx) res.emplace_back(i,ly);
else F(i,hx+1,lx) res.emplace_back(i,ly);
out2(lst2[lx][ly]);
F(i,1,int(res.size())-1) out(res[i-1],res[i]);
}else{
cout<<ans<<'\n'<<hx<<' '<<ly<<'\n';
out1(lst1[lx][ly]);
if(lx>hx) UF(i,lx,hx) res.emplace_back(i,ly);
else F(i,lx,hx) res.emplace_back(i,ly);
if(ly>hy) UF(i,ly-1,hy) res.emplace_back(hx,i);
else F(i,ly+1,hy) res.emplace_back(hx,i);
out2(lst2[hx][hy]);
for(pii x:res) cout<<x.fi<<' '<<x.se<<'\n';
F(i,1,int(res.size())-1) out(res[i-1],res[i]);
}
look_time;
return 0;
}
詳細信息
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 5940kb
input:
5 P..X. X.... ..X.. ....X .X..K
output:
0 1 2 1061109567 6 1061109567 2 3 4 5 4 3 1061109567 5 6 5 4 5 6 1061109567 6 1061109567 6 7 8 8 7 6 1061109567 6 1061109567 6 5 4 5 6 5 1061109567 3 4 5 4 3 2 1061109567 6 1061109567 2 1 0 8 1 1 1 1 1 2 2 2 3 2 4 2 4 3 5 3 5 4 5 5 PDDDPDPP
result:
wrong answer
Subtask #2:
score: 0
Wrong Answer
Test #28:
score: 0
Wrong Answer
time: 1ms
memory: 5932kb
input:
10 .......... .########. .#......#. .#X##X#.#. .#X#P.#X#. .#X#..#X#. .#X####X#. .#XXXXX.#. .#X####X#. ..X..K....
output:
1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1061109567 1...
result:
wrong answer
Subtask #3:
score: 0
Skipped
Dependency #2:
0%
Subtask #4:
score: 0
Skipped
Dependency #1:
0%