QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#115758#5810. Doubly-sorted Gridhgzxwzf30 ✓10894ms30252kbC++142.1kb2023-06-26 19:23:552023-06-26 19:23:56

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 19:23:56]
  • 评测
  • 测评结果:30
  • 用时:10894ms
  • 内存:30252kb
  • [2023-06-26 19:23:55]
  • 提交

answer

#include<bits/stdc++.h>

#define rep(x,y,z) for(int x=y;x<=z;x++)
#define per(x,y,z) for(int x=z;x>=y;x--)

using namespace std;

const int N=11,Max=2e5+10,mod=10007;

int li[N][N],n,m,idx;
int lim[1<<N],cnt[1<<N],nt[1<<N];
int dp[Max][28],id[1<<20],cur[Max];

void dfs(int i,int j,int step)
{
    if(i==n+m+1)
    {
        if(j==n) id[step]=++idx,cur[idx]=step;
        return ;
    }
    dfs(i+1,j+1,step|(1<<i-1));
    dfs(i+1,j,step);
}

int add(int x,int y)
{
    return x+y>=mod?x+y-mod:x+y;
}

void work()
{
    cin>>n>>m;
    rep(i,0,(1<<m)-1) cnt[i]=__builtin_popcount(i);
    idx=0;
    rep(i,1,n)
    {
        string s;
        cin>>s;
        rep(j,1,m)
            li[i][j]=s[j-1]=='.'?0:s[j-1];
    }
    dfs(1,0,0);
    rep(i,1,idx) rep(j,1,26) dp[i][j]=0;
    dp[1][0]=1;
    rep(i,1,idx)
    {
        vector<array<int,3>> cro;
        int x=n,y=0;
        rep(j,1,n+m-1)
        {
            if(cur[i]>>j-1&1) x--;
            else y++;
            if((cur[i]>>j-1&1)&&!(cur[i]>>j&1)) cro.push_back({x,y,j});
        }
        int t=cro.size();
        rep(j,1,(1<<t)-1)
        {
            lim[j]=0;
            nt[j]=cur[i];
            rep(k,0,t-1)
                if(j>>k&1)
                {
                	nt[j]^=1<<cro[k][2]-1,nt[j]^=1<<cro[k][2];
                    int l=li[cro[k][0]+1][cro[k][1]+1];
                    if(!l) continue;
                    if(!lim[j]) lim[j]=l;
                    else if(l!=lim[j]) {lim[j]=-1;break;}
                }
        }
        rep(j,1,26)
        {
            dp[i][j]=add(dp[i][j],dp[i][j-1]);
            rep(k,1,(1<<t)-1)
            {
                if(lim[k]&&lim[k]-'a'+1!=j) continue;
                int c=(cnt[k]&1)?1:mod-1;
                dp[id[nt[k]]][j]=add(dp[id[nt[k]]][j],1ll*dp[i][j]*c%mod);
            }
        }
    }
    cout<<dp[idx][26]<<endl;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0),cout.tie(0);
//    freopen("in","r",stdin);
//    freopen("out","w",stdout);
    int T;
    cin>>T;
    rep(t,1,T) cout<<"Case #"<<t<<": ",work();
    return 0;
}

详细

Subtask #1:

score: 10
Accepted

Test #1:

score: 10
Accepted
time: 0ms
memory: 7548kb

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: 10894ms
memory: 30252kb

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