QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#72225 | #4788. Gravity | lmeowdn | RE | 3ms | 7604kb | C++20 | 1.6kb | 2023-01-15 10:21:53 | 2023-01-15 10:21:54 |
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],tot,vst[N];
vp e[N];
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]=='#') {
if(id[lst][j]!=id[i][j]) {
e[id[lst][j]].eb(pii(id[i][j],lst-i-1));
}
lst=i;
}
}
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: 3ms
memory: 7604kb
input:
10 10 .......... ..######.. ..#....#.. ..#.#..#.. ..#..#.#.. ..#....#.. ..######.. .......... ..#....#.. .......#..
output:
.......... .......... ..######.. ..#....#.. ..#....#.. ..#....#.. ..#.##.#.. ..######.. .......#.. ..#....#..
result:
ok 10 lines
Test #2:
score: -100
Runtime Error
input:
1583 1799 #..###..##..#.####.##.##.###..#.....##..#.#.#.#......#.....##..#.##...#.#....#..##.###...#...##.###.#.....#.##.###...#..##.#...###..#.###.#...###..#.......#...#....#.#..#...##........#.#..#..##.....###...#..#.####..####...#..##......#........#..#.##.##..#..#....##.##.##..#..##.....###....#...