QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#115539#5810. Doubly-sorted Gridjuju52710 3ms5788kbC++141.7kb2023-06-26 11:22:542023-06-26 11:22:55

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-06-26 11:22:55]
  • 评测
  • 测评结果:10
  • 用时:3ms
  • 内存:5788kb
  • [2023-06-26 11:22:54]
  • 提交

answer

//Code by juju527.
#include<bits/stdc++.h>
typedef long long ll;
#define pii pair<int,int>
#define fi first
#define se second
#define vec vector<int>
#define eb emplace_back
using namespace std;
const int maxn=15,mod=1e4+7;
char s[maxn];
int a[maxn][maxn];
int read(){
	int x=0,y=1;
	char ch=getchar();
	while(ch<48||ch>57){if(ch==45)y=-1;ch=getchar();}
	while(ch>=48&&ch<=57)x=(x<<3)+(x<<1)+(ch^48),ch=getchar();
	return x*y;
}
inline int add(int x){return (x>=mod)?x-mod:x;}
inline void add(int &x,int y){x=add(x+y);return ;}
const int maxs=(1<<20)+5;
int f[maxs][20];
int main(){
	int T,cas=0;
	T=read();
	while(T--){
		int n,m;
		n=read(),m=read();
		for(int i=1;i<=n;i++){
			scanf("%s",s+1);
			for(int j=1;j<=m;j++)if(s[j]=='.')a[i][j]=0;else a[i][j]=s[j]-'a'+1;
		}
		int S=(1<<(n+m));
		for(int i=0;i<S;i++)for(int j=0;j<n+m;j++)f[i][j]=0;
		f[(1<<n)-1][0]=1;
		for(int c=26;c>=1;c--){
			for(int s=0;s<S;s++){
				if(__builtin_popcount(s)!=n)continue;
				for(int k=0;k<n+m;k++){
					if(!f[s][k])continue;
					int x=n,y=0;
					for(int i=n+m-1;i>=k-1&&i;i--){
						if(!((s>>i)&1))y++;else x--;
						if(!((s>>i)&1)&&((s>>(i-1))&1)){
							int t=s^(1<<i)^(1<<(i-1));
							if(a[x][y]&&a[x][y]!=c)continue;
							add(f[t][i],f[s][k]);
						}
					}
				}
			}
			for(int s=0;s<S;s++){
				if(__builtin_popcount(s)!=n)continue;
				int sum=0;
				for(int k=0;k<n+m;k++)add(sum,f[s][k]),f[s][k]=0;
				f[s][0]=sum;
			}
//			for(int s=0;s<S;s++)if(f[s])cerr<<c<<" "<<s<<" "<<f[s]<<endl;
		}
		int res=0;
		for(int i=0;i<n+m;i++)add(res,f[((1<<n)-1)<<m][i]);
		printf("Case #%d: %d\n",++cas,res);
	}
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 10
Accepted

Test #1:

score: 10
Accepted
time: 3ms
memory: 5788kb

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: