답안 #859503

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
859503 2023-10-10T09:03:36 Z lucri NoM (RMI21_nom) C++17
100 / 100
92 ms 63252 KB
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;
long long n,m,d[2010][2010],r[2010],fact[4010],im[4010],ans,comb[2010][2010];
long long putere(long long a,long long b)
{
    if(b==0)
        return 1;
    long long m=putere(a,b/2);
    m*=m;
    m%=MOD;
    if(b%2)
    {
        m*=a;
        m%=MOD;
    }
    return m;
}
void factorial()
{
    fact[0]=1;
    for(int i=1;i<=4000;++i)
        fact[i]=(fact[i-1]*i)%MOD;
    for(int i=0;i<=4000;++i)
        im[i]=putere(fact[i],MOD-2);
}
/*long long combinari(long long n,long long m)
{
    long long ans=fact[n];
    ans*=putere(fact[m],MOD-2);
    ans%=MOD;
    ans*=putere(fact[n-m],MOD-2);
    ans%=MOD;
    return ans;
}*/
long long aranjamente(long long n,long long m)
{
    long long ans=fact[n];
    ans*=im[n-m];
    ans%=MOD;
    return ans;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    factorial();
    cin>>n>>m;
    for(int i=0;i<=n;++i)
    {
        comb[i][0]=comb[i][i]=1;
        for(int j=1;j<i;++j)
            comb[i][j]=(comb[i-1][j-1]+comb[i-1][j])%MOD;
    }
    d[0][0]=1;
    for(int i=1;i<=2*n;++i)
        ++r[i%m];
    r[m]=r[0];
    for(int j=0;j<=n;++j)
        for(int i=1;i<=m;++i)
            for(int k=0;2*k<=r[i]&&k<=j;++k)
            {
                d[i][j]+=comb[j][k]*aranjamente(r[i],2*k)%MOD*d[i-1][j-k]%MOD;
                if(d[i][j]>=MOD)
                    d[i][j]-=MOD;
            }
    for(int i=1;i<=n;++i)
    {
        ans+=((i-1)%2*2-1)*d[m][i]%MOD*fact[2*n-2*i]%MOD*comb[n][i]%MOD;
        if(ans>=MOD)
            ans-=MOD;
        if(ans<0)
            ans+=MOD;
    }
    ans+=fact[2*n];
    if(ans>=MOD)
        ans-=MOD;
    cout<<ans;
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2648 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2648 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 2 ms 4608 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 2 ms 4444 KB Output is correct
14 Correct 2 ms 4444 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 2 ms 4444 KB Output is correct
17 Correct 2 ms 4440 KB Output is correct
18 Correct 2 ms 4444 KB Output is correct
19 Correct 1 ms 4560 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2648 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 2 ms 4608 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 2 ms 4444 KB Output is correct
14 Correct 2 ms 4444 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 2 ms 4444 KB Output is correct
17 Correct 2 ms 4440 KB Output is correct
18 Correct 2 ms 4444 KB Output is correct
19 Correct 1 ms 4560 KB Output is correct
20 Correct 2 ms 6492 KB Output is correct
21 Correct 2 ms 6660 KB Output is correct
22 Correct 4 ms 7516 KB Output is correct
23 Correct 2 ms 6492 KB Output is correct
24 Correct 4 ms 9048 KB Output is correct
25 Correct 3 ms 7516 KB Output is correct
26 Correct 2 ms 6492 KB Output is correct
27 Correct 4 ms 10076 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2648 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 2 ms 4608 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 2 ms 4444 KB Output is correct
14 Correct 2 ms 4444 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 2 ms 4444 KB Output is correct
17 Correct 2 ms 4440 KB Output is correct
18 Correct 2 ms 4444 KB Output is correct
19 Correct 1 ms 4560 KB Output is correct
20 Correct 2 ms 6492 KB Output is correct
21 Correct 2 ms 6660 KB Output is correct
22 Correct 4 ms 7516 KB Output is correct
23 Correct 2 ms 6492 KB Output is correct
24 Correct 4 ms 9048 KB Output is correct
25 Correct 3 ms 7516 KB Output is correct
26 Correct 2 ms 6492 KB Output is correct
27 Correct 4 ms 10076 KB Output is correct
28 Correct 5 ms 12632 KB Output is correct
29 Correct 8 ms 14940 KB Output is correct
30 Correct 10 ms 17136 KB Output is correct
31 Correct 5 ms 12812 KB Output is correct
32 Correct 9 ms 17244 KB Output is correct
33 Correct 13 ms 20056 KB Output is correct
34 Correct 19 ms 25944 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2648 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 2 ms 4608 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 2 ms 4444 KB Output is correct
14 Correct 2 ms 4444 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 2 ms 4444 KB Output is correct
17 Correct 2 ms 4440 KB Output is correct
18 Correct 2 ms 4444 KB Output is correct
19 Correct 1 ms 4560 KB Output is correct
20 Correct 2 ms 6492 KB Output is correct
21 Correct 2 ms 6660 KB Output is correct
22 Correct 4 ms 7516 KB Output is correct
23 Correct 2 ms 6492 KB Output is correct
24 Correct 4 ms 9048 KB Output is correct
25 Correct 3 ms 7516 KB Output is correct
26 Correct 2 ms 6492 KB Output is correct
27 Correct 4 ms 10076 KB Output is correct
28 Correct 5 ms 12632 KB Output is correct
29 Correct 8 ms 14940 KB Output is correct
30 Correct 10 ms 17136 KB Output is correct
31 Correct 5 ms 12812 KB Output is correct
32 Correct 9 ms 17244 KB Output is correct
33 Correct 13 ms 20056 KB Output is correct
34 Correct 19 ms 25944 KB Output is correct
35 Correct 24 ms 29208 KB Output is correct
36 Correct 64 ms 56400 KB Output is correct
37 Correct 22 ms 29020 KB Output is correct
38 Correct 43 ms 40580 KB Output is correct
39 Correct 54 ms 51460 KB Output is correct
40 Correct 92 ms 63252 KB Output is correct