QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#734343#5810. Doubly-sorted Gridlichenyu_ac10 19ms18712kbC++141.4kb2024-11-11 09:07:012024-11-11 09:07:02

Judging History

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

  • [2024-11-11 09:07:02]
  • 评测
  • 测评结果:10
  • 用时:19ms
  • 内存:18712kb
  • [2024-11-11 09:07:01]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int N=35,M=1<<20,mod=1e4+7;

int n,m;
int f[2][M],tmp[M],val[M];
char g[N][N];
// vector<int> v;
int sta[N],top;

void Add(int &x,int y){
    x+=y;
    if(x>=mod)x-=mod;
}

void solve(int testCase){
    memset(f,0,sizeof(f));
    memset(tmp,0,sizeof(tmp));

    scanf("%d%d",&n,&m);
    for(int i=0;i<n;i++)scanf("%s",g[i]);

    f[0][(1<<m)-1]=1;
    int now=0;

    for(int i=0;i<26;i++){
        now^=1;
        for(int s=0;s<1<<(n+m);s++){
            if(__builtin_popcount(s)!=m)continue;
            f[now][s]=f[now^1][s];
            // v.clear();
            top=0;
            int x=-1,y=m-1;
            for(int j=0;j<n+m-1;j++){
                (s>>j&1) ? y-- : x++;
                if((s>>j&3)==2){
                    if(g[x][y]=='.'||g[x][y]==i+'a')sta[top++]=3<<j;
                }
            }
            for(int j=1;j<1<<top;j++){
                if(j==(j&-j))tmp[j]=sta[val[j]];
                else tmp[j]=tmp[j^(j&-j)]^tmp[j&-j];
                if(__builtin_popcount(j)&1)Add(f[now][s],f[now][tmp[j]^s]);
                else Add(f[now][s],mod-f[now][tmp[j]^s]);
            }
        }
    }
    printf("Case #%d: %d\n",testCase,f[now][((1<<m)-1)<<n]);
}

int main(){
    for(int i=1;i<25;i++)
        if((1<<i)<M)val[1<<i]=i;
    int T;scanf("%d",&T);
    for(int i=1;i<=T;i++)solve(i);
    return 0;
}

詳細信息

Subtask #1:

score: 10
Accepted

Test #1:

score: 10
Accepted
time: 19ms
memory: 18712kb

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: