QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#446379#4788. GravityC1942huangjiaxuRE 4ms54516kbC++141.6kb2024-06-17 09:21:392024-06-17 09:21:40

Judging History

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

  • [2024-06-17 09:21:40]
  • 评测
  • 测评结果:RE
  • 用时:4ms
  • 内存:54516kb
  • [2024-06-17 09:21:39]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int N=1e6+5;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1},dw[N],dwp[N];
int n,m,id[N],ci,mx[N],d[N];
bool vis[N];
vector<pair<int,int> >e[N];
char *s[N],t[N];
vector<pair<int,int> >nd[N];
deque<int>q;
#define h(x,y) ((x)*m-m+(y))
void dfs(int x,int y){
	id[h(x,y)]=ci;
	nd[ci].emplace_back(x,y);
	mx[ci]=max(mx[ci],x);
	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[h(X,Y)])dfs(X,Y);
	}
}
int main(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;++i){
		s[i]=new char[m+3];
		scanf("%s",s[i]+1);
	}
	for(int i=1;i<=n;++i)for(int j=1;j<=m;++j)if(s[i][j]=='#'&&!id[h(i,j)])++ci,dfs(i,j);
	mx[0]=n+1;
	for(int i=1;i<=m;++i)dwp[h(n,i)]=n+1;
	for(int i=n-1;i;--i){
		for(int j=1;j<=m;++j){
			if(s[i+1][j]=='#')dw[h(i,j)]=id[h(i+1,j)],dwp[h(i,j)]=i+1;
			else dw[h(i,j)]=dw[h(i+1,j)],dwp[h(i,j)]=dwp[h(i+1,j)];
		}
	}
	for(int i=1;i<=n;++i)for(int j=1;j<=m;++j)if(id[h(i,j)]&&dw[h(i,j)]!=id[h(i,j)]){
		int u=id[h(i,j)],v=dw[h(i,j)];
		e[v].emplace_back(u,-(mx[v]-dwp[h(i,j)])-1+mx[u]-i);
	}
	memset(d,0x3f,sizeof(d));
	d[0]=n+1,q.push_front(0);
	while(!q.empty()){
		int u=q.front();
		q.pop_front(),vis[u]=false;
		for(auto [x,v]:e[u])if(d[x]>d[u]+v){
			d[x]=d[u]+v;
			if(!vis[x]){
				if(v<0)q.push_front(x);
				else q.push_back(x);
				vis[x]=true;
			}
		}
	}
	for(int i=1;i<=n*m;++i)t[i]='.';
	for(int i=1;i<=ci;++i)for(auto [x,y]:nd[i])t[h(d[i]-(mx[i]-x),y)]='#';
	for(int i=1;i<=n;++i){
		for(int j=1;j<=m;++j)putchar(t[h(i,j)]);
		putchar(10);
	}
	return 0;
}

详细

Test #1:

score: 100
Accepted
time: 4ms
memory: 54516kb

input:

10 10
..........
..######..
..#....#..
..#.#..#..
..#..#.#..
..#....#..
..######..
..........
..#....#..
.......#..


output:

..........
..........
..######..
..#....#..
..#....#..
..#....#..
..#.##.#..
..######..
.......#..
..#....#..

result:

ok 10 lines

Test #2:

score: -100
Runtime Error

input:

1583 1799
#..###..##..#.####.##.##.###..#.....##..#.#.#.#......#.....##..#.##...#.#....#..##.###...#...##.###.#.....#.##.###...#..##.#...###..#.###.#...###..#.......#...#....#.#..#...##........#.#..#..##.....###...#..#.####..####...#..##......#........#..#.##.##..#..#....##.##.##..#..##.....###....#...

output:


result: