Submission #509594

# Submission time Handle Problem Language Result Execution time Memory
509594 2022-01-14T07:11:01 Z phamhoanghiep NoM (RMI21_nom) C++14
100 / 100
133 ms 15896 KB
#include<bits/stdc++.h>
using namespace std;
const int maxn=2002;
const int mod=1e9+7;
int fact[2*maxn];
int invf[2*maxn];
int dp[maxn][maxn];
int n,m;
int Mul(int a, int b) {
    return 1ll*a*b%mod;
}
int Add(int a, int b) {
    if(a+b>=mod) return a+b-mod;
    return a+b;
}
int Bpow(int a, int b) {
    int res=1;
    int cur=a;
    while(b) {
        if(b&1) res=Mul(res,cur);
        cur=Mul(cur,cur);
        b/=2;
    }
    return res;
}
void init() {
    fact[0]=fact[1]=1;
    invf[0]=invf[1]=1;
    for(int i=2 ; i<2*maxn ; i++) {
        fact[i]=Mul(fact[i-1],i);
        invf[i]=Bpow(fact[i],mod-2);
    }
}
int C(int k, int n) {
    if(k>n) return 0;
    return Mul(fact[n],Mul(invf[n-k],invf[k]));
}
signed main() {
    cin>>n>>m;
    init();
    dp[0][0]=1;
    int rem=(2*n)%m;
    for(int i=1 ; i<=m ; i++) {
        int n_i=(2*n)/m+(i<=rem);
        for(int j=0 ; j<=n ; j++) {
            for(int k=0 ; 2*k<=n_i&&k<=j ; k++) {
                int add=dp[i-1][j-k];
                add=Mul(add,fact[n_i]); add=Mul(add,invf[n_i-2*k]);
                add=Mul(add,C(k,j));
                dp[i][j]=Add(dp[i][j],add);
            }
        }
    }
    int ans=fact[2*n];
    for(int i=1 ; i<=n ; i++) {
        int add=Mul(C(i,n),dp[m][i]);
        add=Mul(add,fact[2*n-2*i]);
        if(i&1) {
            ans-=add;
            if(ans<0) ans+=mod;
        }
        else {
            ans+=add;
            if(ans>=mod) ans-=mod;
        }
    }
    cout<<ans;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 460 KB Output is correct
12 Correct 2 ms 460 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 588 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 460 KB Output is correct
18 Correct 1 ms 460 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 460 KB Output is correct
12 Correct 2 ms 460 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 588 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 460 KB Output is correct
18 Correct 1 ms 460 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 2 ms 712 KB Output is correct
22 Correct 3 ms 1612 KB Output is correct
23 Correct 2 ms 332 KB Output is correct
24 Correct 3 ms 972 KB Output is correct
25 Correct 3 ms 1484 KB Output is correct
26 Correct 2 ms 320 KB Output is correct
27 Correct 4 ms 1832 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 460 KB Output is correct
12 Correct 2 ms 460 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 588 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 460 KB Output is correct
18 Correct 1 ms 460 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 2 ms 712 KB Output is correct
22 Correct 3 ms 1612 KB Output is correct
23 Correct 2 ms 332 KB Output is correct
24 Correct 3 ms 972 KB Output is correct
25 Correct 3 ms 1484 KB Output is correct
26 Correct 2 ms 320 KB Output is correct
27 Correct 4 ms 1832 KB Output is correct
28 Correct 6 ms 332 KB Output is correct
29 Correct 12 ms 2424 KB Output is correct
30 Correct 18 ms 4128 KB Output is correct
31 Correct 6 ms 408 KB Output is correct
32 Correct 11 ms 2508 KB Output is correct
33 Correct 15 ms 4636 KB Output is correct
34 Correct 25 ms 7028 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 460 KB Output is correct
12 Correct 2 ms 460 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 588 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 460 KB Output is correct
18 Correct 1 ms 460 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 2 ms 712 KB Output is correct
22 Correct 3 ms 1612 KB Output is correct
23 Correct 2 ms 332 KB Output is correct
24 Correct 3 ms 972 KB Output is correct
25 Correct 3 ms 1484 KB Output is correct
26 Correct 2 ms 320 KB Output is correct
27 Correct 4 ms 1832 KB Output is correct
28 Correct 6 ms 332 KB Output is correct
29 Correct 12 ms 2424 KB Output is correct
30 Correct 18 ms 4128 KB Output is correct
31 Correct 6 ms 408 KB Output is correct
32 Correct 11 ms 2508 KB Output is correct
33 Correct 15 ms 4636 KB Output is correct
34 Correct 25 ms 7028 KB Output is correct
35 Correct 35 ms 380 KB Output is correct
36 Correct 85 ms 13420 KB Output is correct
37 Correct 31 ms 456 KB Output is correct
38 Correct 52 ms 6612 KB Output is correct
39 Correct 76 ms 12060 KB Output is correct
40 Correct 133 ms 15896 KB Output is correct