QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#368593#6424. GoC1942huangjiaxuWA 3ms72184kbC++142.2kb2024-03-27 13:42:062024-03-27 13:42:07

Judging History

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

  • [2024-03-27 13:42:07]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:72184kb
  • [2024-03-27 13:42:06]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int N=1005,M=1e6+5,B=1e6+7,P=1e9+7;
int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
int T,n,id[N][N],cnt,px[M],py[M],ans,va[M],Ans;
int dfn[M],low[M],co[M],tot,cl[M],Cl[M],sz[M],Sz[M];
bool ch[M],cut[M];
vector<int>e[M],g[M];
char s[N][N];
bool onb(int x,int y){
	return x>0&&x<=n&&y>0&&y<=n;
}
bool lf(int x,int y){
	for(int k=0;k<4;++k){
		int i=x+dx[k],j=y+dy[k];
		if(onb(i,j)&&s[i][j]=='.')return true;
	}
	return false;
}
void tarjan(int x){
	dfn[x]=low[x]=++dfn[0],co[x]=tot,cl[x]=ch[x],sz[x]=1;
	for(auto v:e[x]){
		if(!dfn[v]){
			g[x].push_back(v);
			tarjan(v);
			low[x]=min(low[x],low[v]);
			if(low[v]>=dfn[x])cut[x]=true;
			cl[x]+=cl[v],sz[x]+=sz[v];
		}else low[x]=min(low[x],dfn[x]);
	}
}
void calc(int x){
	if(!Cl[co[x]])va[x]-=Sz[co[x]];
	if(cut[x]){
		int Rs=Sz[co[x]]-1,Rc=Cl[co[x]]-ch[x];
		for(auto v:g[x])if(low[v]>=dfn[x]){
			if(!cl[v])va[x]+=sz[v];
			Rs-=sz[v],Rc-=cl[v];
		}
		if(!Rc)va[x]+=Rs;
	}else{
		if(Cl[co[x]]-ch[x]==0)va[x]+=Sz[co[x]]-1;
	}
	for(auto v:g[x])calc(v);
}
int rev(int i,int j){
	if(s[i][j]=='o')return va[id[i][j]];
	int res=0,Rs=1,Rc=lf(i,j);
	set<int>S;
	for(int k=0;k<4;++k){
		int x=i+dx[k],y=j+dy[k];
		if(onb(x,y)&&s[x][y]=='o')S.insert(co[id[x][y]]);
	}
	for(auto v:S){
		if(!Cl[v])res-=Sz[v];
		Rs+=Sz[v],Rc+=Cl[v];
	}
	if(!Rc)res+=Rs;
	return res;
}
void solve(){
	scanf("%d",&n);
	for(int i=1;i<=cnt;++i)e[i].clear(),g[i].clear(),co[i]=va[i]=0;
	cnt=dfn[0]=tot=ans=Ans=0;
	for(int i=1;i<=n;++i)scanf("%s",s[i]+1);
	for(int i=1;i<=n;++i)
		for(int j=1;j<=n;++j)if(s[i][j]=='o'){
			id[i][j]=++cnt;
			ch[cnt]=lf(i,j);
			px[cnt]=i,py[cnt]=j;
		}
	for(int i=1;i<=cnt;++i)
		for(int j=0;j<4;++j){
			int x=px[i]+dx[j],y=py[i]+dy[j];
			if(onb(x,y)&&s[x][y]=='o')e[i].push_back(id[x][y]);
		}
	for(int i=1;i<=cnt;++i)if(!co[i]){
		++tot;
		tarjan(i);
		Cl[tot]=cl[i],Sz[tot]=sz[i];
		if(g[i].size()>1)cut[i]=true;
		else cut[i]=false;
		if(!cl[i])ans+=Sz[tot];
		calc(i);
	}
	for(int i=1;i<=n;++i)for(int j=1;j<=n;++j)if(s[i][j]!='.'){
		int t=ans+rev(i,j);
		Ans=(1ll*Ans*B+t)%P;
	}
	printf("%d\n",Ans);
}
int main(){
	scanf("%d",&T);
	while(T--)solve();
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 3ms
memory: 72184kb

input:

3
2
.o
..
3
.x.
xoo
ox.
2
oo
oo

output:

0
870527216
485539347

result:

ok 3 number(s): "0 870527216 485539347"

Test #2:

score: -100
Wrong Answer
time: 3ms
memory: 71456kb

input:

2
4
xoxx
oxo.
oo.o
oo.x
6
.o.xox
oox..x
o.xxxo
o..xxo
xxo.o.
xo...o

output:

248401442
250916587

result:

wrong answer 1st numbers differ - expected: '409509910', found: '248401442'