QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#72228 | #4788. Gravity | lmeowdn | ML | 227ms | 150644kb | C++20 | 1.6kb | 2023-01-15 10:24:08 | 2023-01-15 10:24:11 |
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];
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]=='#') {
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;
}
详细
Test #1:
score: 100
Accepted
time: 16ms
memory: 101880kb
input:
10 10 .......... ..######.. ..#....#.. ..#.#..#.. ..#..#.#.. ..#....#.. ..######.. .......... ..#....#.. .......#..
output:
.......... .......... ..######.. ..#....#.. ..#....#.. ..#....#.. ..#.##.#.. ..######.. .......#.. ..#....#..
result:
ok 10 lines
Test #2:
score: 0
Accepted
time: 227ms
memory: 150644kb
input:
1583 1799 #..###..##..#.####.##.##.###..#.....##..#.#.#.#......#.....##..#.##...#.#....#..##.###...#...##.###.#.....#.##.###...#..##.#...###..#.###.#...###..#.......#...#....#.#..#...##........#.#..#..##.....###...#..#.####..####...#..##......#........#..#.##.##..#..#....##.##.##..#..##.....###....#...
output:
...............................................................................................................................................................................................................................................................................................................
result:
ok 1583 lines
Test #3:
score: 0
Accepted
time: 27ms
memory: 115984kb
input:
592 750 .......#..#.#......#.............#...............###..#..#.........#.#.......##.............#.#.#................#..#...#...#......#...#.............#..##..#.#..#..........#..##.#.#..#..#.#...#....#......####.........#..#......#...........#......#............#.###.......##.#..#.#.#...#.#.##....
output:
...............................................................................................................................................................................................................................................................................................................
result:
ok 592 lines
Test #4:
score: -100
Memory Limit Exceeded
input:
1768 1394 ###.###.#######.###.#####.####.##########################.########.###################################.#########################################.#########################.####################.##############.###########################.#######################.################.####.#.#######...