QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#446429 | #4788. Gravity | C1942huangjiaxu | WA | 2ms | 10012kb | C++17 | 1.4kb | 2024-06-17 10:21:27 | 2024-06-17 10:21:29 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int N=2003,M=2000001;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int n,m,id[N][N],ci;
short d[M],w[M];
bool vis[M];
int hd[M],to[M],nx[M],num;
void add(int x,int y,int z){
nx[++num]=hd[x],hd[x]=num,to[num]=y,w[num]=z;
}
char s[N][N];
vector<int>q[N];
void dfs(int x,int y){
id[x][y]=ci;
for(int i=0;i<4;++i){
int X=x+dx[i],Y=y+dy[i];
if(X<1||X>n||Y<1||Y>m||s[X][Y]=='.')continue;
if(!id[X][Y])dfs(X,Y);
}
}
int main(){
scanf("%d%d",&n,&m);
for(int i=1;i<=n;++i)scanf("%s",s[i]+1);
for(int i=1;i<=n;++i)for(int j=1;j<=m;++j)if(s[i][j]=='#'&&!id[i][j])++ci,dfs(i,j);
for(int i=1;i<=n;++i)for(int j=1;j<=m;++j)if(id[i][j]){
short o=i+1;
while(o<=n&&s[o][j]=='.')++o;
if(id[i][j]&&id[o][j]!=id[i][j])add(id[o][j],id[i][j],o-i-1);
}
for(int i=1;i<=ci;++i)d[i]=1e4;
d[0]=0;
for(int i=hd[0],v;v=to[i],i;i=nx[i])d[v]=min(d[v],w[i]);
for(int i=0;i<n;++i){
while(!q[i].empty()){
int u=q[i].back();
q[i].pop_back();
if(vis[u])continue;
vis[u]=true;
for(int i=hd[u],v;v=to[i],i;i=nx[i])if(d[v]>d[u]+w[i]){
d[v]=d[u]+w[i];
q[d[v]].emplace_back(v);
}
}
q[i].shrink_to_fit();
}
for(int i=1;i<=n;++i)for(int j=1;j<=m;++j)s[i][j]='.';
for(int i=1;i<=n;++i)for(int j=1;j<=m;++j)if(id[i][j])s[i+d[id[i][j]]][j]='#';
for(int i=1;i<=n;++i){
for(int j=1;j<=m;++j)putchar(s[i][j]);
putchar(10);
}
return 0;
}
详细
Test #1:
score: 0
Wrong Answer
time: 2ms
memory: 10012kb
input:
10 10 .......... ..######.. ..#....#.. ..#.#..#.. ..#..#.#.. ..#....#.. ..######.. .......... ..#....#.. .......#..
output:
.......... .......... .......... .......... ..######.. ..#....#.. ..#....#.. ..#....#.. ..#....#.. ..######..
result:
wrong answer 3rd lines differ - expected: '..######..', found: '..........'