답안 #14652

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
14652 2015-05-24T10:39:51 Z dohyun0324 선다형 시험 (TOKI14_multiple) C++
16 / 100
20 ms 32872 KB
#include<stdio.h>
#define Mod 1000000007
int w2,n,p,q,w,a[2010],b[2010],ch[2010][6],w1,w0,same[2010],dif[2010],cnt2[2010];
long long invfact[4010],t,dap,cnt,d0[2010],d1[2010],d[2010],dif0[2010],dif1[2010],dp[2010][2010],fact[4010];
char x2,c[7];
long long comb(int n,int r)
{
    if(r==0) return 1;
    long long s;
    s=fact[n]*invfact[r]; s%=Mod;
    s*=invfact[n-r]; s%=Mod;
    return s;
}
long long pow(long long x,long long b)
{
    long long c=x,ans=1;
    while(b)
    {
        if(b%2) ans*=c;
        b/=2; c*=c; c%=Mod; ans%=Mod;
    }
    return ans;
}
int main()
{
    int i,j,x;
    scanf("%d %d %d",&n,&p,&q); fact[0]=1; invfact[0]=1;
    for(i=1;i<=4000;i++){fact[i]=fact[i-1]*i; fact[i]%=Mod;}
    for(i=1;i<=4000;i++) invfact[i]=pow(fact[i],Mod-2);
    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[++w0]=cnt2[i]-1;
        }
    }
    dp[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]]) dp[i][0]=dp[i-1][0]*(cnt-1);
        else dp[i][0]=dp[i-1][0]*cnt;
        for(j=1;j<=i;j++){
            if(ch[x][a[x]]) dp[i][j]=dp[i-1][j-1]+dp[i-1][j]*(cnt-1);
            else dp[i][j]=dp[i-1][j]*cnt;
            dp[i][j]%=Mod;
        }
    }
    for(i=0;i<=w;i++) d[i]=dp[w][i];
    for(i=1;i<=w0;i++)
    {
        dp[i][0]=dp[i-1][0]*dif0[i]; dp[i][0]%=Mod;
        for(j=1;j<=i;j++)
        {
            dp[i][j]=dp[i-1][j]*dif0[i]+dp[i-1][j-1];
            dp[i][j]%=Mod;
        }
    }
    for(i=0;i<=w0;i++) d0[i]=dp[w0][i];
    for(i=1;i<=w1;i++)
    {
        dp[i][0]=dp[i-1][0]*dif1[i]; dp[i][0]%=Mod;
        for(j=1;j<=i;j++)
        {
            dp[i][j]=dp[i-1][j]*dif1[i]+dp[i-1][j-1];
            dp[i][j]%=Mod;
        }
    }
    for(i=0;i<=w1;i++) d1[i]=dp[w1][i];
    for(i=0;i<=p;i++)
    {
        for(j=0;j<=p-i;j++)
        {
            if(p+q-i*2-j>=p-j-i && p-i-j>=0)
            {
                t=d0[j]; t%=Mod;
                t*=d1[p+q-i*2-j]; t%=Mod;
                if(t)
                {
                    w1=0;
                }
                t*=comb(p+q-i*2-j,p-j-i)*d[i]; t%=Mod;
            }
            dap+=t;
            dap%=Mod;
        }
    }
    printf("%lld",dap);
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 32872 KB Output is correct
2 Correct 1 ms 32872 KB Output is correct
3 Correct 0 ms 32872 KB Output is correct
4 Correct 0 ms 32872 KB Output is correct
5 Correct 0 ms 32872 KB Output is correct
6 Correct 0 ms 32872 KB Output is correct
7 Correct 0 ms 32872 KB Output is correct
8 Incorrect 0 ms 32872 KB Output isn't correct
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 32872 KB Output is correct
2 Correct 0 ms 32872 KB Output is correct
3 Correct 4 ms 32872 KB Output is correct
4 Correct 20 ms 32872 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 32872 KB Output isn't correct
2 Halted 0 ms 0 KB -