Submission #14645

# Submission time Handle Problem Language Result Execution time Memory
14645 2015-05-24T07:52:50 Z dohyun0324 선다형 시험 (TOKI14_multiple) C++
0 / 100
0 ms 65536 KB
#include<stdio.h>
int w2,n,p,q,w,a[2010],b[2010],ch[2010][6],w1,w0,same[2010],dif[2010],cnt2[2010];
long long dap,cnt,d0[2010][2010],d1[2010][2010],d[2010][2010],dif0[2010],dif1[2010],comb[2010][2010];
char x2,c[7];
long long comb2(int n,int r)
{
    int i;
    long long c=1;
    for(i=r+1;i<=n;i++) c*=i, c%=1000000007;
    return c;
}
int main()
{
    int i,j,x;
    scanf("%d %d %d",&n,&p,&q);
    for(i=1;i<=n;i++){
        scanf(" %c",&x2);
        a[i]=x2-'a'+1;
    }
    for(i=1;i<=n;i++){
        scanf(" %c",&x2);
        b[i]=x2-'a'+1;
    }
    for(i=1;i<=n;i++){
        scanf("%s",&c);
        for(j=0;j<=4;j++){
            if(c[j]!='.') ch[i][j+1]=1, cnt2[i]++;
        }
    }
    for(i=1;i<=n;i++){
        if(a[i]==b[i]) same[++w]=i;
        else
        {
            if(ch[i][b[i]]) dif1[++w1]=cnt2[i]-2;
            else dif0[++w2]=cnt2[i]-1;
        }
    }
    d0[0][0]=d[0][0]=d1[0][0]=1;
    for(i=1;i<=w;i++){
        x=same[i]; cnt=0;
        for(j=1;j<=5;j++){
            if(ch[x][j]) cnt++;
        }
        if(ch[x][a[x]]) d[i][0]=d[i-1][0]*(cnt-1);
        else d[i][0]=d[i-1][0]*cnt;
        for(j=1;j<=i;j++){
            if(ch[x][a[x]]) d[i][j]=d[i-1][j-1]+d[i-1][j]*(cnt-1);
            else d[i][j]=d[i-1][j]*cnt;
            d[i][j]%=1000000007;
        }
    }
    for(i=1;i<=w0;i++)
    {
        d0[i][0]=d0[i-1][0]*dif0[i]; d0[i][0]%=1000000007;
        for(j=1;j<=i;j++)
        {
            d0[i][j]=d0[i-1][j]*dif0[i]+d0[i-1][j-1];
            d0[i][j]%=1000000007;
        }
    }
    for(i=1;i<=w1;i++)
    {
        d1[i][0]=d1[i-1][0]*dif1[i]; d1[i][0]%=1000000007;
        for(j=1;j<=i;j++)
        {
            d1[i][j]=d1[i-1][j]*dif1[i]+d1[i-1][j-1];
            d1[i][j]%=1000000007;
        }
    }
    comb[0][0]=1;
    for(i=1;i<=w1;i++)
    {
        comb[i][0]=1;
        for(j=1;j<=i;j++)
        {
            comb[i][j]=comb[i-1][j]+comb[i-1][j-1];
            comb[i][j]%=1000000007;
        }
    }
    for(i=0;i<=p;i++)
    {
        for(j=0;j<=p-i;j++)
        {
            if(p+q-i*2-j>=0) dap+=d0[w0][j]*d1[w1][p+q-i*2-j]*comb[w1][p+q-i*2-j]*d[w][i];
            dap%=1000000007;
        }
    }
    printf("%lld",dap);
    return 0;
}
# Verdict Execution time Memory Grader output
1 Memory limit exceeded 0 ms 65536 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Memory limit exceeded 0 ms 65536 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Memory limit exceeded 0 ms 65536 KB Memory limit exceeded
2 Halted 0 ms 0 KB -