QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#104269 | #4788. Gravity | Determinant | ML | 262ms | 143248kb | C++14 | 1.1kb | 2023-05-09 21:22:59 | 2023-05-09 21:23:03 |
Judging History
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);
}
Details
Tip: Click on the bar to expand more detailed information
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 ###.###.#######.###.#####.####.##########################.########.###################################.#########################################.#########################.####################.##############.###########################.#######################.################.####.#.#######...