QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#115550#5810. Doubly-sorted Gridjuju52730 ✓5992ms50460kbC++141.8kb2023-06-26 11:37:412023-06-26 11:37:59

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:37:59]
  • 评测
  • 测评结果:30
  • 用时:5992ms
  • 内存:50460kb
  • [2023-06-26 11:37:41]
  • 提交

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
#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,maxt=2e5+5;
int id[maxs],val[maxs],f[maxt][20];
struct trans{int t,lim,w;};
vec<trans> e[maxt];
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)),tot=0;
		for(int i=0;i<S;i++)if(__builtin_popcount(i)==n)id[i]=++tot,val[tot]=i;
		for(int i=1;i<=tot;i++)for(int j=0;j<n+m;j++)f[i][j]=0;
		f[1][0]=1;
		for(int u=1;u<=tot;u++){
			int s=val[u];
			int x=n,y=0;e[u].clear();
			for(int i=n+m-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));
					e[u].eb((trans){id[t],i,a[x][y]});
				}
			}
		}
		for(int c=26;c>=1;c--){
			for(int u=1;u<=tot;u++){
				int s=val[u];
				for(int k=0;k<n+m;k++){
					if(!f[u][k])continue;
					int val=f[u][k];
					for(auto p:e[u]){
						if(p.lim<k-1)break;
						if(!p.w||p.w==c)add(f[p.t][p.lim],val);
					}
				}
			}
			for(int u=0;u<=tot;u++){
				int sum=0;
				for(int k=0;k<n+m;k++)add(sum,f[u][k]),f[u][k]=0;
				f[u][0]=sum;
			}
		}
		int res=0;
		for(int i=0;i<n+m;i++)add(res,f[tot][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: 13228kb

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: 5992ms
memory: 50460kb

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