답안 #859499

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
859499 2023-10-10T08:59:28 Z lucri NoM (RMI21_nom) C++17
52 / 100
500 ms 29264 KB
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;
long long n,m,d[2010][2010],r[2010],fact[4010],ans,comb[2010][2010];
void factorial()
{
    fact[0]=1;
    for(int i=1;i<=4000;++i)
        fact[i]=(fact[i-1]*i)%MOD;
}
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;
}
/*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*=putere(fact[n-m],MOD-2);
    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 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 0 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 0 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 4 ms 4696 KB Output is correct
12 Correct 2 ms 4608 KB Output is correct
13 Correct 2 ms 4444 KB Output is correct
14 Correct 2 ms 4444 KB Output is correct
15 Correct 3 ms 4472 KB Output is correct
16 Correct 2 ms 4444 KB Output is correct
17 Correct 2 ms 4444 KB Output is correct
18 Correct 2 ms 4440 KB Output is correct
19 Correct 2 ms 4440 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 0 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 4 ms 4696 KB Output is correct
12 Correct 2 ms 4608 KB Output is correct
13 Correct 2 ms 4444 KB Output is correct
14 Correct 2 ms 4444 KB Output is correct
15 Correct 3 ms 4472 KB Output is correct
16 Correct 2 ms 4444 KB Output is correct
17 Correct 2 ms 4444 KB Output is correct
18 Correct 2 ms 4440 KB Output is correct
19 Correct 2 ms 4440 KB Output is correct
20 Correct 7 ms 6492 KB Output is correct
21 Correct 8 ms 6492 KB Output is correct
22 Correct 31 ms 7788 KB Output is correct
23 Correct 13 ms 6668 KB Output is correct
24 Correct 28 ms 9052 KB Output is correct
25 Correct 27 ms 7512 KB Output is correct
26 Correct 15 ms 6488 KB Output is correct
27 Correct 40 ms 10020 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 0 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 4 ms 4696 KB Output is correct
12 Correct 2 ms 4608 KB Output is correct
13 Correct 2 ms 4444 KB Output is correct
14 Correct 2 ms 4444 KB Output is correct
15 Correct 3 ms 4472 KB Output is correct
16 Correct 2 ms 4444 KB Output is correct
17 Correct 2 ms 4444 KB Output is correct
18 Correct 2 ms 4440 KB Output is correct
19 Correct 2 ms 4440 KB Output is correct
20 Correct 7 ms 6492 KB Output is correct
21 Correct 8 ms 6492 KB Output is correct
22 Correct 31 ms 7788 KB Output is correct
23 Correct 13 ms 6668 KB Output is correct
24 Correct 28 ms 9052 KB Output is correct
25 Correct 27 ms 7512 KB Output is correct
26 Correct 15 ms 6488 KB Output is correct
27 Correct 40 ms 10020 KB Output is correct
28 Correct 82 ms 12792 KB Output is correct
29 Correct 139 ms 14836 KB Output is correct
30 Correct 157 ms 17232 KB Output is correct
31 Correct 82 ms 12796 KB Output is correct
32 Correct 150 ms 17232 KB Output is correct
33 Correct 191 ms 20004 KB Output is correct
34 Correct 336 ms 25684 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 0 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 4 ms 4696 KB Output is correct
12 Correct 2 ms 4608 KB Output is correct
13 Correct 2 ms 4444 KB Output is correct
14 Correct 2 ms 4444 KB Output is correct
15 Correct 3 ms 4472 KB Output is correct
16 Correct 2 ms 4444 KB Output is correct
17 Correct 2 ms 4444 KB Output is correct
18 Correct 2 ms 4440 KB Output is correct
19 Correct 2 ms 4440 KB Output is correct
20 Correct 7 ms 6492 KB Output is correct
21 Correct 8 ms 6492 KB Output is correct
22 Correct 31 ms 7788 KB Output is correct
23 Correct 13 ms 6668 KB Output is correct
24 Correct 28 ms 9052 KB Output is correct
25 Correct 27 ms 7512 KB Output is correct
26 Correct 15 ms 6488 KB Output is correct
27 Correct 40 ms 10020 KB Output is correct
28 Correct 82 ms 12792 KB Output is correct
29 Correct 139 ms 14836 KB Output is correct
30 Correct 157 ms 17232 KB Output is correct
31 Correct 82 ms 12796 KB Output is correct
32 Correct 150 ms 17232 KB Output is correct
33 Correct 191 ms 20004 KB Output is correct
34 Correct 336 ms 25684 KB Output is correct
35 Execution timed out 529 ms 29264 KB Time limit exceeded
36 Halted 0 ms 0 KB -