QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#115154#5810. Doubly-sorted GridDerekFeng30 ✓3188ms31520kbC++231.4kb2023-06-24 18:09:102023-06-24 18:09:11

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-24 18:09:11]
  • 评测
  • 测评结果:30
  • 用时:3188ms
  • 内存:31520kb
  • [2023-06-24 18:09:10]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int M=10007;
int n,m,N;char s[12][12];
int mp[1<<20],msk[200000];
int nx[200000][22];bool ok[200000][26];
int dp[200000],ld[26][12],rd[26][12],mt[12];
void add(int &x,int y){if((x+=y)>=M)x-=M;}
void sol(){
	scanf("%d%d",&n,&m),N=0;
	for(int i=1;i<=n;i++)scanf("%s",s[i]+1);
	for(int c=0;c<26;c++)for(int i=1;i<=n;i++){
		ld[c][i]=0;for(int j=1;j<=m;j++)if(s[i][j]!='.'&&s[i][j]<=c+'a')ld[c][i]=j;
		rd[c][i]=m;for(int j=m;j;j--)if(s[i][j]!='.'&&s[i][j]>c+'a')rd[c][i]=j-1;
	}
	memset(mp,0,(1<<n+m+2));
	for(int i=0;i<(1<<n+m);i++)if(__builtin_popcount(i)==n)mp[i]=++N,msk[N]=i;
	memset(nx+1,0,N*88);
	for(int i=1;i<=N;i++){
		for(int j=0;j<n+m;j++)if(msk[i]>>j&1){
			int k;for(k=j+1;msk[i]>>k&1;k++);
			if(k==n+m)nx[i][j]=0;else nx[i][j]=mp[msk[i]^(1<<j)^(1<<k)];
		}
		for(int j=0,k=0;j<n+m;j++){if(msk[i]>>j&1)mt[n-j+k]=k;else k++;}
		for(int c=0;c<26;c++){
			ok[i][c]=1;for(int j=1;j<=n;j++)
				ok[i][c]&=ld[c][j]<=mt[j],ok[i][c]&=mt[j]<=rd[c][j];
		}
	}
	memset(dp+1,0,N<<2),dp[1]=1;
	for(int c=0;c<26;c++){
		for(int i=0;i<n+m;i++)for(int j=1;j<=N;j++)
			if(dp[j]&&nx[j][i])add(dp[nx[j][i]],dp[j]);
		for(int j=1;j<=N;j++)if(!ok[j][c])dp[j]=0;
	}
	printf("%d\n",dp[N]);
}
int main(){
	int tc;scanf("%d",&tc);
	for(int tt=1;tt<=tc;tt++)
		printf("Case #%d: ",tt),sol();
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 10
Accepted

Test #1:

score: 10
Accepted
time: 2ms
memory: 7692kb

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: 3188ms
memory: 31520kb

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