QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#72229 | #4788. Gravity | lmeowdn | ML | 654ms | 175440kb | C++20 | 1.8kb | 2023-01-15 10:27:22 | 2023-01-15 10:27:24 |
Judging History
answer
#include<bits/stdc++.h>
#define int long long
#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=2009,inf=0x3f3f3f3f;
int n,m,id[N][N],f[N*N],tot;
vp e[N*N];
map<pii,int>ed;
bitset<N*N>vst;
char s[N][N],ans[N][N];
priority_queue<pii>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;
rep(j,1,m) {
int lst=n+1;
per(i,n,1) if(s[i][j]=='#') {
int u=id[lst][j], v=id[i][j];
if(u!=v) {
if(!ed.count(pii(u,v))) ed[pii(u,v)]=lst-i-1;
else ed[pii(u,v)]=min(ed[pii(u,v)],lst-i-1);
}
lst=i;
}
}
for(auto p:ed) e[p.fi.fi].eb(pii(p.fi.se,p.se));
rep(i,1,tot-1) f[i]=inf;
q.push(pii(0,tot));
while(q.size()) {
int u=q.top().se; q.pop();
if(vst[u]) continue; vst[u]=1;
for(pii ed:e[u]) {
if(f[ed.fi]>f[u]+ed.se)
f[ed.fi]=f[u]+ed.se, q.push(pii(-f[ed.fi],ed.fi));
}
}
rep(i,1,n) rep(j,1,m) ans[i][j]='.';
rep(i,1,n) rep(j,1,m) if(s[i][j]=='#') ans[i+f[id[i][j]]][j]='#';
rep(i,1,n) {
rep(j,1,m) putchar(ans[i][j]);
puts("");
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 7ms
memory: 101888kb
input:
10 10 .......... ..######.. ..#....#.. ..#.#..#.. ..#..#.#.. ..#....#.. ..######.. .......... ..#....#.. .......#..
output:
.......... .......... ..######.. ..#....#.. ..#....#.. ..#....#.. ..#.##.#.. ..######.. .......#.. ..#....#..
result:
ok 10 lines
Test #2:
score: 0
Accepted
time: 654ms
memory: 175440kb
input:
1583 1799 #..###..##..#.####.##.##.###..#.....##..#.#.#.#......#.....##..#.##...#.#....#..##.###...#...##.###.#.....#.##.###...#..##.#...###..#.###.#...###..#.......#...#....#.#..#...##........#.#..#..##.....###...#..#.####..####...#..##......#........#..#.##.##..#..#....##.##.##..#..##.....###....#...
output:
...............................................................................................................................................................................................................................................................................................................
result:
ok 1583 lines
Test #3:
score: 0
Accepted
time: 66ms
memory: 120608kb
input:
592 750 .......#..#.#......#.............#...............###..#..#.........#.#.......##.............#.#.#................#..#...#...#......#...#.............#..##..#.#..#..........#..##.#.#..#..#.#...#....#......####.........#..#......#...........#......#............#.###.......##.#..#.#.#...#.#.##....
output:
...............................................................................................................................................................................................................................................................................................................
result:
ok 592 lines
Test #4:
score: -100
Memory Limit Exceeded
input:
1768 1394 ###.###.#######.###.#####.####.##########################.########.###################################.#########################################.#########################.####################.##############.###########################.#######################.################.####.#.#######...