QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#88366#5810. Doubly-sorted Grid10circle10 17ms11692kbC++141.7kb2023-03-16 08:37:592023-03-16 08:38:00

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-03-16 08:38:00]
  • 评测
  • 测评结果:10
  • 用时:17ms
  • 内存:11692kb
  • [2023-03-16 08:37:59]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long
using namespace std;

int read(){
	int a=0,b=0;char c=getchar();
	while(c<'0'||c>'9')b^=(c=='-'),c=getchar();
	while(c>='0'&&c<='9')a=a*10+c-48,c=getchar();
	return b?-a:a;
}

const int mod=10007,st=184756,K=1<<20;

int n,m,ans;
char s[12][12];
int dp[2][K],popc[K];
int cu[1024],lb[1024];

int sol(){
	n=read(),m=read(),ans=0;
	for(int i=0;i<n;i++)scanf("%s",s[i]);
	for(int i=0;i<n;i++)for(int j=0;j<m;j++)if('a'<=s[i][j]&&s[i][j]<='z')s[i][j]-='a';
	int u=n+m,o=1<<u;
	for(int i=1;i<o;i++)popc[i]=popc[i>>1]+(i&1);
	for(int i=0;i<1024;i++)lb[i]=lb[i/2]+1;
	memset(dp,0,sizeof dp);
	dp[1][(1<<m)-1]=1;
	for(int i=0;i<26;i++){
		for(int j=0;j<o;j++)if(popc[j]==m){
			int c[10]={0},ct=0,re=0,ag=0;
			for(int k=1;k<u;k++){
				re+=(j>>(k-1))&1;
				if(!((j>>(k-1))&1)&&((j>>k)&1)){
					int q=m-re-1;
					int p=k-re-1;
					//cout<<i<<' '<<j<<' '<<k<<' '<<p<<' '<<q<<'\n';
					if(s[p][q]!='.'&&s[p][q]!=i)continue;
					c[ct++]=(1<<k)|(1<<(k-1));
				}
			}
			dp[i&1][j]=dp[!(i&1)][j];
			int p=1<<ct;
			for(int k=1;k<p;k++){
				cu[k]=cu[k-(k&-k)]^cu[k&-k];
				if(k==(k&-k)){
					cu[k]=0;
					for(int l=0;l<ct;l++)if((k>>l)&1){cu[k]=c[l];break;}
				}
				int q=cu[k]^j;
				//for(int l=0;l<ct;l++)if((k>>l)&1)q^=c[l];
				if(popc[k]&1){
					dp[i&1][j]+=dp[(i&1)][q];
					if(dp[i&1][j]>=mod)dp[i&1][j]-=mod;
				}else{
					dp[i&1][j]-=dp[(i&1)][q];
					if(dp[i&1][j]<0)dp[i&1][j]+=mod;
				}
			}
			//cout<<i<<' '<<j<<' '<<dp[i&1][j]<<'\n';
		}
	}
	return dp[25&1][((1<<m)-1)<<n];
}

int main(){
	int T=read();
	for(int i=1;i<=T;i++){
		printf("Case #%d: %d\n",i,sol());
	}
	return 0;
}

详细

Subtask #1:

score: 10
Accepted

Test #1:

score: 10
Accepted
time: 17ms
memory: 11692kb

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: 0
Time Limit Exceeded

Test #2:

score: 0
Time Limit Exceeded

input:

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

output:


result: