QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#747468#5810. Doubly-sorted Gridzhouyuxuan350130 ✓12091ms15352kbC++141.2kb2024-11-14 17:15:092024-11-14 17:15:09

Judging History

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

  • [2024-11-14 17:15:09]
  • 评测
  • 测评结果:30
  • 用时:12091ms
  • 内存:15352kb
  • [2024-11-14 17:15:09]
  • 提交

answer

#include<cstdio>
#include<algorithm>
#include<cstring>
#define M 10007
using namespace std;
const int Mn=1<<20;
char G[13][13];
int P[Mn],l[Mn],T,t,n,m,y[2][Mn],s,F,c[Mn],w[10],g,z[1024];
int C()
{
	int i,j,h,q;
	scanf("%d%d",&n,&m);
	for(i=0;i<n;i++)
	{
		scanf("%s",G[i]);
		for(j=0;j<m;j++)if(G[i][j]>='a'&&G[i][j]<='z')G[i][j]-='a';
	}
	s=0;
	for(i=0;i<(1<<(n+m));i++)if(P[i]==m)c[s++]=i;
	memset(y,0,sizeof y);
	y[1][(1<<m)-1]=1;
	for(h=0;h<26;h++)
	{
		memcpy(y[F],y[F^1],(1<<(n+m+2)));
		for(i=0;i<s;i++)
		{
			g=t=0;
			for(j=1;j<n+m;j++)
			{
				if((c[i]>>(j-1))&1)g++;
				if(((c[i]>>(j-1))&1)==0&&((c[i]>>j)&1))
				{
					if(G[j-g-1][m-g-1]!='.'&&G[j-g-1][m-g-1]!=h)continue;
					w[t++]=(1<<(j-1))|(1<<j);
				}
			}
			for(j=1;j<(1<<t);j++)
			{
				if(j==(-j&j))z[j]=w[l[j]];
				else z[j]=z[j&(j-1)]^z[-j&j];
				q=y[F][c[i]^z[j]];
				y[F][c[i]]+=(P[j]&1)?q:M-q;
			}
			y[F][c[i]]%=M;
			memset(w,0,sizeof w);
		}
		F^=1;
	}
	return y[F^1][((1<<m)-1)<<n];
}
int main()
{
	int i;
	for(i=1;i<Mn;i++)P[i]=P[i&(i-1)]+1;
	for(i=2;i<1024;i++)l[i]=l[i>>1]+1;
	scanf("%d",&T);
	for(i=1;i<=T;i++)
		printf("Case #%d: %d\n",i,C());
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 10
Accepted

Test #1:

score: 10
Accepted
time: 16ms
memory: 15116kb

input:

40
4 4
....
....
....
....
4 4
abcd
bcde
cdef
defg
4 4
bbcc
ccde
cdef
deef
4 4
....
....
.r..
..e.
3 4
....
....
...g
1 3
f..
2 2
.b
bb
2 3
...
..f
4 4
....
....
..t.
..d.
3 3
.gn
...
...
4 4
...a
...b
...c
...d
4 4
...b
..bb
.bbb
bbbb
4 4
a...
.b..
..c.
...d
3 3
c..
glw
..w
1 4
....
1 3
d.v
4 2
..
...

output:

Case #1: 7285
Case #2: 1
Case #3: 1
Case #4: 0
Case #5: 718
Case #6: 231
Case #7: 2
Case #8: 686
Case #9: 0
Case #10: 3500
Case #11: 330
Case #12: 14
Case #13: 4096
Case #14: 2756
Case #15: 3737
Case #16: 19
Case #17: 8175
Case #18: 3737
Case #19: 7279
Case #20: 256
Case #21: 23
Case #22: 7569
Case ...

result:

ok 40 lines

Subtask #2:

score: 20
Accepted

Test #2:

score: 20
Accepted
time: 12091ms
memory: 15352kb

input:

40
5 10
..........
..........
..........
..........
..........
10 10
....a.....
....c.....
....g.....
....j.....
....l.....
....m.....
....n.....
....q.....
....t.....
....v.....
10 10
..........
..........
..........
..........
..........
..........
..........
..........
...ok.....
..........
9 10
...

output:

Case #1: 8791
Case #2: 7220
Case #3: 0
Case #4: 2510
Case #5: 4299
Case #6: 1663
Case #7: 981
Case #8: 1430
Case #9: 8814
Case #10: 2877
Case #11: 2124
Case #12: 0
Case #13: 4311
Case #14: 4458
Case #15: 8699
Case #16: 3727
Case #17: 14
Case #18: 5478
Case #19: 7922
Case #20: 6789
Case #21: 1252
Cas...

result:

ok 40 lines

Extra Test:

score: 0
Extra Test Passed