QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#72244#4788. GravitylmeowdnRE 2ms5548kbC++201.8kb2023-01-15 11:00:502023-01-15 11:00:53

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-01-15 11:00:53]
  • 评测
  • 测评结果:RE
  • 用时:2ms
  • 内存:5548kb
  • [2023-01-15 11:00:50]
  • 提交

answer

#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define fi first
#define se second
#define eb emplace_back
#define bp __builtin_parity
#define y1 yyl
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pii> vp;
typedef bitset<1009> bset;

int read() {
	int x=0,w=1; char c=getchar();
	while(!isdigit(c)) {if(c=='-') w=-1; c=getchar();}
	while(isdigit(c)) {x=x*10+c-'0'; c=getchar();}
	return x*w;
}

const int N=2002,inf=0x3f3f3f3f;
int n,m,id[N][N],tot,hd[N],cnt;
struct edge {int to,nxt; short w;} e[N*N/2];
void add(int u,int v,int w) {e[++cnt]=(edge){v,hd[u],w}; hd[u]=cnt;}
vector<short> f;
bitset<N*N/2>vst;
char s[N][N];
priority_queue<pair<short,int> >q;

void dfs(int x,int y,int p) {
	if(!x||!y||x>n||y>m||s[x][y]!='#'||id[x][y]) return;
	id[x][y]=p;
	dfs(x+1,y,p), dfs(x,y+1,p), dfs(x-1,y,p), dfs(x,y-1,p);
}

signed main() {
	n=read(), m=read();
	rep(i,1,n) scanf("%s",s[i]+1);
	rep(i,1,n) rep(j,1,m) if(s[i][j]=='#'&&!id[i][j]) dfs(i,j,++tot);
	++tot;
	rep(j,1,m) id[n+1][j]=tot;
	f.resize(tot+1);
	rep(j,1,m) {
		int lst=n+1;
		per(i,n,1) if(s[i][j]=='#') {
			if(id[lst][j]!=id[i][j]) {
				add(id[lst][j],id[i][j],lst-i-1);
			}
			lst=i;
		}
	}
	rep(i,1,tot-1) f[i]=n+1;
	q.push(pii(0,tot));
	while(q.size()) {
		int u=q.top().se; q.pop(); 
		if(vst[u]) continue; vst[u]=1;
		for(int i=hd[u],v,w;i;i=e[i].nxt) {
			if(f[v=e[i].to]>f[u]+(w=e[i].w))
				f[v]=f[u]+w, q.push(pii(-f[v],v));
		}
	}
	per(i,n,1) rep(j,1,m) {
		if(s[i][j]=='#') s[i][j]='.', s[i+f[id[i][j]]][j]='#';
	}
	rep(i,1,n) {
		rep(j,1,m) putchar(s[i][j]);
		puts("");
	}
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 2ms
memory: 5548kb

input:

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


output:

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

result:

ok 10 lines

Test #2:

score: -100
Runtime Error

input:

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

output:


result: