QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#104269#4788. GravityDeterminantML 262ms143248kbC++141.1kb2023-05-09 21:22:592023-05-09 21:23:03

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-05-09 21:23:03]
  • 评测
  • 测评结果:ML
  • 用时:262ms
  • 内存:143248kb
  • [2023-05-09 21:22:59]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;const int N=2007;typedef pair<int,int> p;
int n,m,k,d[N*N/2],col[N][N],dx[4]={0,0,1,-1},dy[4]={1,-1};char a[N][N];vector<p>v[N*N/2],G[N*N/2];
bool chk(int x,int y){return x&&x<=n&&y&&y<=m&&a[x][y]=='#';}
void dfs(int x,int y){
	a[x][y]='.';col[x][y]=k;v[k].push_back({x,y});
	for(int i=0;i<4;++i)if(chk(x+dx[i],y+dy[i]))dfs(x+dx[i],y+dy[i]);
}
int main(){
	scanf("%d%d",&n,&m);for(int i=n;i;--i)scanf("%s",a[i]+1);
	for(int i=1;i<=n;++i)for(int j=m;j;j--)if(a[i][j]=='#')d[++k]=1e9,dfs(i,j);
	for(int j=m;j;j--){
		int lst=0;for(int i=n;i;--i)if(col[i][j]){
			if(lst){
				int x=col[lst][j],y=col[i][j];
				if(x!=y)G[y].push_back({x,lst-1-i});
			}lst=i;
		}
		if(lst)G[0].push_back({col[lst][j],lst-1});
	}
	priority_queue<p,vector<p>,greater<p> >q;q.push({0,0});
	while(!q.empty()){
		int x=q.top().second,y=q.top().first;q.pop();if(d[x]!=y)continue;
		for(auto i:G[x]){
			int v=i.first,w=i.second+y;
			if(d[v]>w)q.push({d[v]=w,v});
		}
	}
	for(int i=1;i<=k;++i)for(auto j:v[i])a[j.first-d[i]][j.second]='#';
	for(int i=n;i;--i)puts(a[i]+1);
}

详细

Test #1:

score: 100
Accepted
time: 24ms
memory: 97916kb

input:

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


output:

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

result:

ok 10 lines

Test #2:

score: 0
Accepted
time: 262ms
memory: 143248kb

input:

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

output:

...............................................................................................................................................................................................................................................................................................................

result:

ok 1583 lines

Test #3:

score: 0
Accepted
time: 53ms
memory: 107076kb

input:

592 750
.......#..#.#......#.............#...............###..#..#.........#.#.......##.............#.#.#................#..#...#...#......#...#.............#..##..#.#..#..........#..##.#.#..#..#.#...#....#......####.........#..#......#...........#......#............#.###.......##.#..#.#.#...#.#.##....

output:

...............................................................................................................................................................................................................................................................................................................

result:

ok 592 lines

Test #4:

score: -100
Memory Limit Exceeded

input:

1768 1394
###.###.#######.###.#####.####.##########################.########.###################################.#########################################.#########################.####################.##############.###########################.#######################.################.####.#.#######...

output:


result: