ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1402. Cocktails

WA#13 WHY?
Posted by snowfly 14 Jul 2009 09:56
#include<iostream>
using namespace std;
int fac[100000],ans[100000],len,alen;
int main (void){
    int n;cin>>n;
    alen=1;
    memset(ans,0,sizeof(ans));
    for (int i=2;i<=n;++i){
        memset(fac,0,sizeof(fac));
        len=1;fac[0]=1;
        for (int j=n;j>n-i;--j){
            for (int k=0;k<len;++k)
                fac[k]*=j;
            for (int k=0;k<len;++k)
                if (fac[k]>=10){
                    fac[k+1]+=fac[k]/10;
                    fac[k]%=10;
                }
            if (fac[len]!=0){
                ++len;
                if (fac[len-1]>=10){
                    fac[len]=fac[len-1]/10;
                    fac[len]%=10;
                    ++len;
                }
            }
        }
        for (int j=0;j<min(alen,len);++j)
            ans[j]+=fac[j];
        if (alen<len){
            for (int j=alen;j<len;++j)
                ans[j]=fac[j];
            alen=len;
        }
        for (int j=0;j<alen;++j)
            if (ans[j]>9){
                ans[j+1]+=ans[j]/10;
                ans[j]%=10;
            }
        while (ans[alen]!=0){
            ++alen;
            ans[alen]+=ans[alen-1]/10;
            ans[alen-1]%=10;
        }
    }
    for (int i=alen-1;i>=0;--i)
        cout<<ans[i];
    cout<<endl;
    return 0;
}