답안 #509804

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
509804 2022-01-14T10:14:41 Z hotboy2703 NoM (RMI21_nom) C++14
100 / 100
125 ms 33180 KB
#include<bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const long long maxn = 2000;
long long fac[maxn * 2 + 100];
long long fiv[maxn * 2 + 100];
long long ml(long long x, long long y){
    return (x * y) % MOD;
}
long long pow_mod(long long x,long long y){
    if (y == 0)return 1;
    long long r = pow_mod(x,y/2);
    r = ml(r,r);
    if (y % 2)r = ml(r,x);
    return r;
}
long long dp[maxn + 100][maxn + 100];
long long choose(long long k,long long n){
    return ml(ml(fac[n],fiv[k]),fiv[n - k]);
}

long long n,m;
int main(){

    //freopen("NOM.INP","r",stdin);
    //freopen("NOM.OUT","w",stdout);
    fac[0] = 1;
    for (long long i = 1;i <= 2 * maxn;i ++){
        fac[i] = ml(fac[i-1],i);
    }
    fiv[maxn * 2] = pow_mod(fac[2 * maxn],MOD - 2);
    for (long long i = maxn * 2 - 1;i >= 0;i --){
        fiv[i] = ml(fiv[i + 1],i + 1);
    }
    cin>>n>>m;
    dp[0][0] = 1;
    dp[0][1] = 0;
    for (long long i = 1;i <= m;i ++){
        long long am;
        if (i <= (2 * n) % m){
            am = (2 * n) / m + 1;
        }
        else{
            am = (2 * n) / m;
        }
        long long buck = am / 2;
        for (long long j = 0;j <= n;j ++){
            for (long long k = 0;k <= j && k <= buck;k ++){
                dp[i][j] += ml(ml(ml(dp[i - 1][j - k], choose(k * 2,am)),fac[k*2]),fiv[k]);
                dp[i][j] %= MOD;
            }
        }
    }
    long long ans = 1;
    for (long long i = 1;i <= 2 * n;i ++){
        ans = ml(ans,i);
    }
    for (long long j = 1;j <= n;j ++){
        //cout<<dp[m][j]<<' ';

        if (j % 2){
            ans -= ml(fac[j],ml(ml(choose(j,n),dp[m][j]),fac[2 * (n - j)])) + MOD;

        }
        else{
                ans += ml(fac[j],ml(ml(choose(j,n),dp[m][j]),fac[2 * (n - j)]));
        }
        ans %= MOD;
    }
    cout<<(ans + MOD) % MOD;
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 460 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 1 ms 368 KB Output is correct
4 Correct 0 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 0 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 460 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 1 ms 368 KB Output is correct
4 Correct 0 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 0 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 624 KB Output is correct
12 Correct 1 ms 588 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 500 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 496 KB Output is correct
18 Correct 1 ms 588 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 460 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 1 ms 368 KB Output is correct
4 Correct 0 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 0 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 624 KB Output is correct
12 Correct 1 ms 588 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 500 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 496 KB Output is correct
18 Correct 1 ms 588 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 716 KB Output is correct
22 Correct 3 ms 1868 KB Output is correct
23 Correct 1 ms 360 KB Output is correct
24 Correct 2 ms 1228 KB Output is correct
25 Correct 3 ms 1772 KB Output is correct
26 Correct 2 ms 460 KB Output is correct
27 Correct 4 ms 2252 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 460 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 1 ms 368 KB Output is correct
4 Correct 0 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 0 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 624 KB Output is correct
12 Correct 1 ms 588 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 500 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 496 KB Output is correct
18 Correct 1 ms 588 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 716 KB Output is correct
22 Correct 3 ms 1868 KB Output is correct
23 Correct 1 ms 360 KB Output is correct
24 Correct 2 ms 1228 KB Output is correct
25 Correct 3 ms 1772 KB Output is correct
26 Correct 2 ms 460 KB Output is correct
27 Correct 4 ms 2252 KB Output is correct
28 Correct 6 ms 460 KB Output is correct
29 Correct 11 ms 3276 KB Output is correct
30 Correct 14 ms 5580 KB Output is correct
31 Correct 6 ms 356 KB Output is correct
32 Correct 17 ms 3484 KB Output is correct
33 Correct 17 ms 6448 KB Output is correct
34 Correct 28 ms 10180 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 460 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 1 ms 368 KB Output is correct
4 Correct 0 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 0 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 624 KB Output is correct
12 Correct 1 ms 588 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 500 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 496 KB Output is correct
18 Correct 1 ms 588 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 716 KB Output is correct
22 Correct 3 ms 1868 KB Output is correct
23 Correct 1 ms 360 KB Output is correct
24 Correct 2 ms 1228 KB Output is correct
25 Correct 3 ms 1772 KB Output is correct
26 Correct 2 ms 460 KB Output is correct
27 Correct 4 ms 2252 KB Output is correct
28 Correct 6 ms 460 KB Output is correct
29 Correct 11 ms 3276 KB Output is correct
30 Correct 14 ms 5580 KB Output is correct
31 Correct 6 ms 356 KB Output is correct
32 Correct 17 ms 3484 KB Output is correct
33 Correct 17 ms 6448 KB Output is correct
34 Correct 28 ms 10180 KB Output is correct
35 Correct 34 ms 616 KB Output is correct
36 Correct 99 ms 27984 KB Output is correct
37 Correct 40 ms 612 KB Output is correct
38 Correct 71 ms 13712 KB Output is correct
39 Correct 80 ms 24800 KB Output is correct
40 Correct 125 ms 33180 KB Output is correct