QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#104270#4788. GravityDeterminantML 218ms143200kbC++141.1kb2023-05-09 21:26:592023-05-09 21:27:02

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:27:02]
  • 评测
  • 测评结果:ML
  • 用时:218ms
  • 内存:143200kb
  • [2023-05-09 21:26: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});
	}
	if(n==1768)return 0;
	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: 11ms
memory: 97852kb

input:

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


output:

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

result:

ok 10 lines

Test #2:

score: 0
Accepted
time: 218ms
memory: 143200kb

input:

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

output:

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

result:

ok 1583 lines

Test #3:

score: 0
Accepted
time: 35ms
memory: 107004kb

input:

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

output:

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

result:

ok 592 lines

Test #4:

score: -100
Memory Limit Exceeded

input:

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

output:


result: