QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#361996#8507. Clever Cell Choicesucup-team2303#WA 16ms59308kbC++143.1kb2024-03-23 13:52:012024-03-23 13:52:01

Judging History

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

  • [2024-03-23 13:52:01]
  • 评测
  • 测评结果:WA
  • 用时:16ms
  • 内存:59308kb
  • [2024-03-23 13:52:01]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const long long mod=1e9+7;
long long T,a,b,c,d[1000001],v[1001][1001],o,h[1000001],fa[1000001],q,w,e,an,cn,fac[1000001],inv[1000001],st[1000001],u[1000001],dp[1000001][3],inf=1e16,id[101][101];
long long ff[1000001];
bool vv[3001][3001];
char s[1000001];
bool vi[1001][1001];
struct p{long long q,w;}l[1000001];
long long pow_(long long qq,long long ww){long long ee=1;while(ww){if(ww&1) ee*=qq,ee%=mod;qq*=qq,qq%=mod,ww>>=1;}return ee%mod;}
inline int read(){int x=0,f=1;char c=getchar();while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}while(c>='0'&&c<='9'){x=(x<<3)+(x<<1)+c-'0';c=getchar();}return x*f;}
void add1(long long qq,long long ww){l[++o].q=ww,l[o].w=h[qq],h[qq]=o;}
long long gcd(long long qq,long long ww){return !ww?qq:gcd(ww,qq%ww);}
long long find(long long qq){return qq==fa[qq]?qq:fa[qq]=find(fa[qq]);}
void merge(long long qq,long long ww){long long f1=find(qq),f2=find(ww);if(f1==f2) return;fa[f1]=f2;}
long long C(long long qq,long long ww){return fac[qq]*inv[ww]%mod*inv[qq-ww]%mod;}
vector<int> qu[1000001];
vector<p> tmp;
void dfs(long long qq,long long ww)
{
	tmp.push_back(p{qq,ww});
	vi[qq][ww]=1;
	if(qq>1&&!vi[qq-1][ww]) dfs(qq-1,ww);
	if(qq<a&&!vi[qq+1][ww]) dfs(qq+1,ww);
	if(ww>1&&!vi[qq][ww-1]) dfs(qq,ww-1);
	if(ww<b&&!vi[qq][ww+1]) dfs(qq,ww+1);
}
void add(long long qq,long long ww)
{
	if(ff[qq]) swap(qq,ww);
	add1(qq,ww);
}
void ins(long long qq,long long ww)
{
	if(qq>1&&id[qq-1][ww])
	{
		add(id[qq-1][ww],id[qq][ww]);
	}
	if(ww>1&&id[qq][ww-1])
	{
		add(id[qq][ww-1],id[qq][ww]);
	}
}
long long ma[100001],v1[100001],g[100001];
bool dfs1(long long qq,long long ww)
{
	if(v1[qq]==ww) return 0;
	v1[qq]=ww;
	for(int i=h[qq];i;i=l[i].w)
	{
		if(!ma[l[i].q]||dfs1(ma[l[i].q],ww))
		{
			ma[l[i].q]=qq;
			return 1;
		}
	}
	return 0;
}
int main()
{
//	freopen("1.in","r",stdin);
	srand((unsigned)(time(0)^(*new int)));
	fac[0]=1;for(int i=1;i<=1000000;i++) fac[i]=fac[i-1]*i%mod;
	inv[1000000]=pow_(fac[1000000],mod-2);for(int i=999999;i>=0;i--) inv[i]=inv[i+1]*(i+1)%mod;
	scanf("%lld%lld",&a,&b);
	for(int i=1;i<=a;i++)
	{
		scanf("%s",s+1);
		for(int j=1;j<=b;j++)
		{
			if(s[j]=='.') v[i][j]=0;
			else v[i][j]=1,vi[i][j]=1;
		}
	}
	for(int i=1;i<=a;i++)
	{
		for(int j=1;j<=b;j++)
		{
			if(!vi[i][j])
			{
				tmp.clear();
				dfs(i,j);cn=0;
				for(int k=0;k<tmp.size();k++) id[tmp[k].q][tmp[k].w]=++cn,ff[cn]=(tmp[k].q+tmp[k].w)%2;
				for(int k=0;k<tmp.size();k++)
				{
					ins(tmp[k].q,tmp[k].w);
				}
				for(int k=1;k<=cn;k++)
				{
					if(!ff[k])
					{
						dfs1(k,k);
					}
				}
				for(int k=1;k<=cn;k++)
				{
					if(ff[k])
					{
						if(ma[k]) g[ma[k]]=g[k]=1;
					}
				}
				long long cn1=0,cn2=0,Cn1=0,Cn2=0;
				for(int k=1;k<=cn;k++)
				{
					if(!ff[k])
					{
						if(!g[k]) ++cn1;
						++Cn1;
					}
					else
					{
						if(!g[k]) ++cn2;
						++Cn2;
					}
				}
				if(cn1) an+=Cn1;
				if(cn2) an+=Cn2;
				o=0;for(int k=1;k<=cn;k++) h[k]=v1[k]=g[k]=0;
			}
		}
	}
	printf("%lld",an);
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 16ms
memory: 57300kb

input:

3 3
#.#
...
#.#

output:

4

result:

ok 1 number(s): "4"

Test #2:

score: 0
Accepted
time: 12ms
memory: 57204kb

input:

3 3
..#
...
...

output:

0

result:

ok 1 number(s): "0"

Test #3:

score: 0
Accepted
time: 11ms
memory: 53208kb

input:

1 4
...#

output:

2

result:

ok 1 number(s): "2"

Test #4:

score: 0
Accepted
time: 15ms
memory: 57112kb

input:

1 5
####.

output:

1

result:

ok 1 number(s): "1"

Test #5:

score: 0
Accepted
time: 14ms
memory: 55128kb

input:

1 6
#..###

output:

0

result:

ok 1 number(s): "0"

Test #6:

score: 0
Accepted
time: 8ms
memory: 59168kb

input:

2 5
....#
###.#

output:

3

result:

ok 1 number(s): "3"

Test #7:

score: 0
Accepted
time: 4ms
memory: 59308kb

input:

2 6
...##.
.#.###

output:

4

result:

ok 1 number(s): "4"

Test #8:

score: 0
Accepted
time: 4ms
memory: 57300kb

input:

5 5
##...
##.#.
##.##
##.#.
.##..

output:

7

result:

ok 1 number(s): "7"

Test #9:

score: 0
Accepted
time: 7ms
memory: 55084kb

input:

6 6
...##.
#..#..
......
..#...
#...##
.#....

output:

1

result:

ok 1 number(s): "1"

Test #10:

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

input:

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

output:

21

result:

wrong answer 1st numbers differ - expected: '26', found: '21'