QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#68325 | #4788. Gravity | 275307894a | RE | 1ms | 22968kb | C++14 | 1.4kb | 2022-12-15 19:54:37 | 2022-12-15 19:54:41 |
Judging History
answer
#include<bits/stdc++.h>
#define Gc() getchar()
#define Me(x,y) memset(x,y,sizeof(x))
#define Mc(x,y) memcpy(x,y,sizeof(x))
#define d(x,y) ((m)*(x-1)+(y))
#define R(n) (rnd()%(n)+1)
#define Pc(x) putchar(x)
#define LB lower_bound
#define UB upper_bound
#define PB push_back
using ll=long long;using db=double;using lb=long db;using ui=unsigned;using ull=unsigned ll;
using namespace std;const int N=2e3+5,M=3e5+5,K=1e5+5,mod=998244353,Mod=mod-1;const ll INF=1e18+7;const db eps=1e-5;mt19937 rnd(time(0));
int n,m,Ct,d[N*N],col[N][N];char s[N][N],A[N][N];
int xp[4]={1,0,-1,0},yp[4]={0,1,0,-1};
void dfs(int x,int y,int w){if(x<1||y<1||x>n||y>m||col[x][y]||!s[x][y]) return;col[x][y]=w;for(int i=0;i<4;i++) dfs(x+xp[i],y+yp[i],w);}
struct Edge{int to,w;};vector<Edge> S[N];queue<int> Q;
int main(){
int i,j;scanf("%d%d",&n,&m);for(i=1;i<=n;i++) for(scanf("%s",s[i]+1),j=1;j<=m;j++) s[i][j]=(s[i][j]=='#');
for(i=1;i<=n;i++) for(j=1;j<=m;j++) if(s[i][j]&&!col[i][j]) dfs(i,j,++Ct);
for(i=1;i<=m;i++){
int La=0,Ls=n+1;for(j=n;j;j--) if(s[j][i]) La^col[j][i]&&(S[La].PB((Edge){col[j][i],Ls-j-1}),0),Ls=j,La=col[j][i];
}Me(d,0x3f);d[0]=0;Q.push(0);while(!Q.empty()){
int x=Q.front();Q.pop();for(Edge i:S[x]) d[x]+i.w<d[i.to]&&(Q.push(i.to),d[i.to]=d[x]+i.w);
}for(i=1;i<=n;i++) for(j=1;j<=m;j++) if(s[i][j]) A[i+d[col[i][j]]][j]=1;
for(i=1;i<=n;Pc('\n'),i++) for(j=1;j<=m;j++) Pc(A[i][j]?'#':'.');
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 22968kb
input:
10 10 .......... ..######.. ..#....#.. ..#.#..#.. ..#..#.#.. ..#....#.. ..######.. .......... ..#....#.. .......#..
output:
.......... .......... ..######.. ..#....#.. ..#....#.. ..#....#.. ..#.##.#.. ..######.. .......#.. ..#....#..
result:
ok 10 lines
Test #2:
score: -100
Runtime Error
input:
1583 1799 #..###..##..#.####.##.##.###..#.....##..#.#.#.#......#.....##..#.##...#.#....#..##.###...#...##.###.#.....#.##.###...#..##.#...###..#.###.#...###..#.......#...#....#.#..#...##........#.#..#..##.....###...#..#.####..####...#..##......#........#..#.##.##..#..#....##.##.##..#..##.....###....#...