QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#72239 | #4788. Gravity | lmeowdn | TL | 2ms | 5512kb | C++20 | 1.8kb | 2023-01-15 10:44:51 | 2023-01-15 10:44:54 |
Judging History
answer
#include<bits/stdc++.h>
#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=2002,inf=0x3f3f3f3f;
int n,m,id[N][N],tot;
vector<vector<pair<int,short>>> e;
vector<short> f;
char s[N][N];
set<pair<short,int> >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;
f.resize(tot+1); e.resize(tot+1);
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(make_pair(id[i][j],lst-i-1));
}
lst=i;
}
}
rep(i,1,tot-1) f[i]=n+1;
q.insert(make_pair(0,tot));
while(q.size()) {
int u=(*q.begin()).se; q.erase(q.begin());
for(auto ed:e[u]) {
int v=ed.fi, w=ed.se;
if(f[v]>f[u]+w) {
if(f[v]==n+1) q.insert(make_pair(-f[u]-w,v));
else q.erase(make_pair(-f[v],v)), q.insert(make_pair(-f[u]-w,v));
f[v]=f[u]+w;
}
}
}
per(i,n,1) rep(j,1,m) {
if(s[i][j]=='#') s[i][j]='.', s[i+f[id[i][j]]][j]='#';
}
rep(i,1,n) {
rep(j,1,m) putchar(s[i][j]);
puts("");
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 5512kb
input:
10 10 .......... ..######.. ..#....#.. ..#.#..#.. ..#..#.#.. ..#....#.. ..######.. .......... ..#....#.. .......#..
output:
.......... .......... ..######.. ..#....#.. ..#....#.. ..#....#.. ..#.##.#.. ..######.. .......#.. ..#....#..
result:
ok 10 lines
Test #2:
score: -100
Time Limit Exceeded
input:
1583 1799 #..###..##..#.####.##.##.###..#.....##..#.#.#.#......#.....##..#.##...#.#....#..##.###...#...##.###.#.....#.##.###...#..##.#...###..#.###.#...###..#.......#...#....#.#..#...##........#.#..#..##.....###...#..#.####..####...#..##......#........#..#.##.##..#..#....##.##.##..#..##.....###....#...