답안 #871083

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
871083 2023-11-09T20:49:03 Z Ahmed57 NoM (RMI21_nom) C++17
100 / 100
184 ms 32100 KB
#include <bits/stdc++.h>
using namespace std;
long long mod = 1000000007;
long long fact[10001],inv[10001];
long long fast(long long a,long long b){
    if(b==0)return 1;
    if(b==1)return a;
    long long h = fast(a,b/2);
    h*=h;h%=mod;
    if(b%2)return (h*a)%mod;
    else return h;
}
long long nPr(long long a,long long b){
    return (fact[a]*inv[a-b])%mod;
}
long long nCr(long long a,long long b){
    return (((fact[a]*inv[a-b])%mod)*inv[b])%mod;
}
long long dp[2001][2001];
int n,m;int cnt[2001];
long long solve(int i,int rem){
    if(i==m){
        return fact[rem*2];
    }
    if(dp[i][rem]!=-1)return dp[i][rem];
    long long de = 1;
    long long all =0;
    for(int j = 0;j<=cnt[i]/2;j++){
        all+=(((((solve(i+1,rem-j)*nPr(cnt[i],j*2))%mod)*nCr(rem,j))%mod)*de)%mod;
        all%=mod;
        de*=(mod-1);de%=mod;
    }
    return dp[i][rem] = all;
}
signed main(){
    ios_base::sync_with_stdio(false);cin.tie(0);
    memset(dp,-1,sizeof dp);
    fact[0] = 1;inv[0] = fast(fact[0],mod-2);
    for(long long i = 1;i<=1e4;i++){
        fact[i]=(fact[i-1]*i)%mod;
        inv[i]=fast(fact[i],mod-2);
    }
    cin>>n>>m;
    for(int i = 0;i<2*n;i++){
        cnt[i%m]++;
    }
    cout<<solve(0,n)<<endl;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 31832 KB Output is correct
2 Correct 8 ms 31836 KB Output is correct
3 Correct 8 ms 31836 KB Output is correct
4 Correct 9 ms 31832 KB Output is correct
5 Correct 8 ms 31832 KB Output is correct
6 Correct 8 ms 31836 KB Output is correct
7 Correct 8 ms 31848 KB Output is correct
8 Correct 8 ms 31836 KB Output is correct
9 Correct 8 ms 31836 KB Output is correct
10 Correct 8 ms 31848 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 31832 KB Output is correct
2 Correct 8 ms 31836 KB Output is correct
3 Correct 8 ms 31836 KB Output is correct
4 Correct 9 ms 31832 KB Output is correct
5 Correct 8 ms 31832 KB Output is correct
6 Correct 8 ms 31836 KB Output is correct
7 Correct 8 ms 31848 KB Output is correct
8 Correct 8 ms 31836 KB Output is correct
9 Correct 8 ms 31836 KB Output is correct
10 Correct 8 ms 31848 KB Output is correct
11 Correct 8 ms 31836 KB Output is correct
12 Correct 8 ms 31832 KB Output is correct
13 Correct 8 ms 31836 KB Output is correct
14 Correct 8 ms 31836 KB Output is correct
15 Correct 8 ms 31916 KB Output is correct
16 Correct 9 ms 31836 KB Output is correct
17 Correct 8 ms 31912 KB Output is correct
18 Correct 8 ms 31836 KB Output is correct
19 Correct 9 ms 32088 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 31832 KB Output is correct
2 Correct 8 ms 31836 KB Output is correct
3 Correct 8 ms 31836 KB Output is correct
4 Correct 9 ms 31832 KB Output is correct
5 Correct 8 ms 31832 KB Output is correct
6 Correct 8 ms 31836 KB Output is correct
7 Correct 8 ms 31848 KB Output is correct
8 Correct 8 ms 31836 KB Output is correct
9 Correct 8 ms 31836 KB Output is correct
10 Correct 8 ms 31848 KB Output is correct
11 Correct 8 ms 31836 KB Output is correct
12 Correct 8 ms 31832 KB Output is correct
13 Correct 8 ms 31836 KB Output is correct
14 Correct 8 ms 31836 KB Output is correct
15 Correct 8 ms 31916 KB Output is correct
16 Correct 9 ms 31836 KB Output is correct
17 Correct 8 ms 31912 KB Output is correct
18 Correct 8 ms 31836 KB Output is correct
19 Correct 9 ms 32088 KB Output is correct
20 Correct 9 ms 31836 KB Output is correct
21 Correct 9 ms 31836 KB Output is correct
22 Correct 11 ms 31836 KB Output is correct
23 Correct 9 ms 31912 KB Output is correct
24 Correct 11 ms 31972 KB Output is correct
25 Correct 11 ms 31836 KB Output is correct
26 Correct 10 ms 31960 KB Output is correct
27 Correct 12 ms 31836 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 31832 KB Output is correct
2 Correct 8 ms 31836 KB Output is correct
3 Correct 8 ms 31836 KB Output is correct
4 Correct 9 ms 31832 KB Output is correct
5 Correct 8 ms 31832 KB Output is correct
6 Correct 8 ms 31836 KB Output is correct
7 Correct 8 ms 31848 KB Output is correct
8 Correct 8 ms 31836 KB Output is correct
9 Correct 8 ms 31836 KB Output is correct
10 Correct 8 ms 31848 KB Output is correct
11 Correct 8 ms 31836 KB Output is correct
12 Correct 8 ms 31832 KB Output is correct
13 Correct 8 ms 31836 KB Output is correct
14 Correct 8 ms 31836 KB Output is correct
15 Correct 8 ms 31916 KB Output is correct
16 Correct 9 ms 31836 KB Output is correct
17 Correct 8 ms 31912 KB Output is correct
18 Correct 8 ms 31836 KB Output is correct
19 Correct 9 ms 32088 KB Output is correct
20 Correct 9 ms 31836 KB Output is correct
21 Correct 9 ms 31836 KB Output is correct
22 Correct 11 ms 31836 KB Output is correct
23 Correct 9 ms 31912 KB Output is correct
24 Correct 11 ms 31972 KB Output is correct
25 Correct 11 ms 31836 KB Output is correct
26 Correct 10 ms 31960 KB Output is correct
27 Correct 12 ms 31836 KB Output is correct
28 Correct 20 ms 31848 KB Output is correct
29 Correct 22 ms 31836 KB Output is correct
30 Correct 23 ms 31836 KB Output is correct
31 Correct 19 ms 31940 KB Output is correct
32 Correct 23 ms 31836 KB Output is correct
33 Correct 26 ms 31832 KB Output is correct
34 Correct 44 ms 31836 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 31832 KB Output is correct
2 Correct 8 ms 31836 KB Output is correct
3 Correct 8 ms 31836 KB Output is correct
4 Correct 9 ms 31832 KB Output is correct
5 Correct 8 ms 31832 KB Output is correct
6 Correct 8 ms 31836 KB Output is correct
7 Correct 8 ms 31848 KB Output is correct
8 Correct 8 ms 31836 KB Output is correct
9 Correct 8 ms 31836 KB Output is correct
10 Correct 8 ms 31848 KB Output is correct
11 Correct 8 ms 31836 KB Output is correct
12 Correct 8 ms 31832 KB Output is correct
13 Correct 8 ms 31836 KB Output is correct
14 Correct 8 ms 31836 KB Output is correct
15 Correct 8 ms 31916 KB Output is correct
16 Correct 9 ms 31836 KB Output is correct
17 Correct 8 ms 31912 KB Output is correct
18 Correct 8 ms 31836 KB Output is correct
19 Correct 9 ms 32088 KB Output is correct
20 Correct 9 ms 31836 KB Output is correct
21 Correct 9 ms 31836 KB Output is correct
22 Correct 11 ms 31836 KB Output is correct
23 Correct 9 ms 31912 KB Output is correct
24 Correct 11 ms 31972 KB Output is correct
25 Correct 11 ms 31836 KB Output is correct
26 Correct 10 ms 31960 KB Output is correct
27 Correct 12 ms 31836 KB Output is correct
28 Correct 20 ms 31848 KB Output is correct
29 Correct 22 ms 31836 KB Output is correct
30 Correct 23 ms 31836 KB Output is correct
31 Correct 19 ms 31940 KB Output is correct
32 Correct 23 ms 31836 KB Output is correct
33 Correct 26 ms 31832 KB Output is correct
34 Correct 44 ms 31836 KB Output is correct
35 Correct 82 ms 31840 KB Output is correct
36 Correct 135 ms 32100 KB Output is correct
37 Correct 81 ms 31832 KB Output is correct
38 Correct 98 ms 32016 KB Output is correct
39 Correct 108 ms 32092 KB Output is correct
40 Correct 184 ms 32088 KB Output is correct