QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#68325#4788. Gravity275307894aRE 1ms22968kbC++141.4kb2022-12-15 19:54:372022-12-15 19:54:41

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-12-15 19:54:41]
  • 评测
  • 测评结果:RE
  • 用时:1ms
  • 内存:22968kb
  • [2022-12-15 19:54:37]
  • 提交

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]?'#':'.');
}

Details

Tip: Click on the bar to expand more detailed information

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
#..###..##..#.####.##.##.###..#.....##..#.#.#.#......#.....##..#.##...#.#....#..##.###...#...##.###.#.....#.##.###...#..##.#...###..#.###.#...###..#.......#...#....#.#..#...##........#.#..#..##.....###...#..#.####..####...#..##......#........#..#.##.##..#..#....##.##.##..#..##.....###....#...

output:


result: