QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#68343#4788. Gravity275307894aWA 3ms11636kbC++142.0kb2022-12-15 21:01:332022-12-15 21:01:35

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 21:01:35]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:11636kb
  • [2022-12-15 21:01:33]
  • 提交

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=2e6+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,col[N][N];char s[N][N];short d[M];
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 yyy{int to;short w;int z;};struct ljb{int head,h[M];yyy f[M];void add(int x,int y,int z){f[++head]=(yyy){y,z,h[x]};h[x]=head;}}S;
struct yy{int to,z;};struct ljc{int head,h[N];yy f[M];void add(int x,int y){f[++head]=(yy){y,h[x]};h[x]=head;}}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.add(La,col[j][i],Ls-j-1),0),Ls=j,La=col[j][i];
	}Me(d,0x3f);Q.add(0,d[0]=0);for(i=0;i<=n;i++){
		yy tmp;for(int j=Q.h[i];j;j=tmp.z){
			tmp=Q.f[j];if(d[tmp.to]^i) continue;yyy Tmp;
			for(int h=S.h[tmp.to];h;h=Tmp.z){
				Tmp=S.f[h];if(d[tmp.to]+Tmp.w<d[Tmp.to]){
					d[Tmp.to]=d[tmp.to]+Tmp.w;if(d[Tmp.to]>i) Q.add(d[Tmp.to],Tmp.to);
				}
			}
		}
	}
	/*
	while(!Q.empty()){
		Node x=Q.top();Q.pop();if(x.w^d[x.x]) continue;yyy tmp;for(int i=S.h[x.x];i;i=tmp.z) tmp=S.f[i],d[x.x]+tmp.w<d[tmp.to]&&(Q.push((Node){tmp.to,d[tmp.to]=d[x.x]+tmp.w}),0);
	}*/for(i=n;i;i--) for(j=1;j<=m;j++) if(s[i][j]&&d[col[i][j]]) s[i+d[col[i][j]]][j]=1,s[i][j]=0;
	for(i=1;i<=n;Pc('\n'),i++) for(j=1;j<=m;j++) Pc(s[i][j]?'#':'.');
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 3ms
memory: 11636kb

input:

10 10
..........
..######..
..#....#..
..#.#..#..
..#..#.#..
..#....#..
..######..
..........
..#....#..
.......#..


output:

..........
..........
..........
..######..
..#....#..
..#....#..
..#....#..
..#.##.#..
..######..
..#....#..

result:

wrong answer 3rd lines differ - expected: '..######..', found: '..........'