답안 #540497

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
540497 2022-03-20T14:49:43 Z doowey NoM (RMI21_nom) C++14
100 / 100
95 ms 57740 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

#define fi first
#define se second
#define mp make_pair
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

const int N = 2005;
const int M = N * 2;
const int MOD = (int)1e9 + 7;

int mult(int x, int y){
    return (x * 1ll * y) % MOD;
}

void add(int &u, int v){
    u = (u + v) % MOD;
}

int pick[M][M];
int cnt[M];
int fac[M];
int dp[N][N];

int main(){
    fastIO;
    int n, m;
    cin >> n >> m;
    for(int i = 0 ; i < n * 2; i ++ ){
        cnt[i % m] ++ ;
    }
    for(int i = 0 ; i < M; i ++ ){
        pick[i][0]=1;
    }
    for(int i = 1; i < M; i ++ ){
        for(int j = 1; j <= i; j ++ ){
            add(pick[i][j], pick[i-1][j]);
            add(pick[i][j], pick[i-1][j-1]);
        }
    }
    fac[0] = 1;
    for(int i = 1; i < M; i ++ ){
        fac[i] = mult(fac[i - 1], i);
    }
    dp[0][0] = mult(pick[n][cnt[0]], fac[cnt[0]]);
    int total = 0;
    int single;
    int value;
    for(int i = 1; i < m ; i ++ ){
        total += cnt[i - 1];
        for(int j = 0 ; j <= n; j ++ ){
            if(dp[i-1][j] == 0) continue;
            for(int nx = 0; nx <= cnt[i]; nx ++ ){
                single = total - 2ll * j;
                if(single < 0) continue;
                if(nx > single) continue;
                if(single + j > n) continue;
                if(j + nx > n) continue;
                value = dp[i - 1][j];
                value = mult(value, pick[single][nx]);
                value = mult(value, pick[n - single - j][cnt[i] - nx]);
                value = mult(value, fac[cnt[i]]);
                add(dp[i][j + nx], value);
            }
        }
    }
    int sol = dp[m-1][n];
    for(int i = 1; i <= n; i ++ ){
        sol = mult(sol, 2);
    }
    cout << sol << "\n";

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 55 ms 45820 KB Output is correct
2 Correct 49 ms 45744 KB Output is correct
3 Correct 49 ms 45820 KB Output is correct
4 Correct 50 ms 45720 KB Output is correct
5 Correct 49 ms 45772 KB Output is correct
6 Correct 47 ms 45832 KB Output is correct
7 Correct 58 ms 45768 KB Output is correct
8 Correct 47 ms 45792 KB Output is correct
9 Correct 47 ms 45768 KB Output is correct
10 Correct 46 ms 45772 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 55 ms 45820 KB Output is correct
2 Correct 49 ms 45744 KB Output is correct
3 Correct 49 ms 45820 KB Output is correct
4 Correct 50 ms 45720 KB Output is correct
5 Correct 49 ms 45772 KB Output is correct
6 Correct 47 ms 45832 KB Output is correct
7 Correct 58 ms 45768 KB Output is correct
8 Correct 47 ms 45792 KB Output is correct
9 Correct 47 ms 45768 KB Output is correct
10 Correct 46 ms 45772 KB Output is correct
11 Correct 48 ms 46032 KB Output is correct
12 Correct 48 ms 45952 KB Output is correct
13 Correct 47 ms 45772 KB Output is correct
14 Correct 54 ms 45868 KB Output is correct
15 Correct 48 ms 46208 KB Output is correct
16 Correct 47 ms 45840 KB Output is correct
17 Correct 46 ms 45900 KB Output is correct
18 Correct 47 ms 45960 KB Output is correct
19 Correct 53 ms 45848 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 55 ms 45820 KB Output is correct
2 Correct 49 ms 45744 KB Output is correct
3 Correct 49 ms 45820 KB Output is correct
4 Correct 50 ms 45720 KB Output is correct
5 Correct 49 ms 45772 KB Output is correct
6 Correct 47 ms 45832 KB Output is correct
7 Correct 58 ms 45768 KB Output is correct
8 Correct 47 ms 45792 KB Output is correct
9 Correct 47 ms 45768 KB Output is correct
10 Correct 46 ms 45772 KB Output is correct
11 Correct 48 ms 46032 KB Output is correct
12 Correct 48 ms 45952 KB Output is correct
13 Correct 47 ms 45772 KB Output is correct
14 Correct 54 ms 45868 KB Output is correct
15 Correct 48 ms 46208 KB Output is correct
16 Correct 47 ms 45840 KB Output is correct
17 Correct 46 ms 45900 KB Output is correct
18 Correct 47 ms 45960 KB Output is correct
19 Correct 53 ms 45848 KB Output is correct
20 Correct 47 ms 45992 KB Output is correct
21 Correct 46 ms 46084 KB Output is correct
22 Correct 49 ms 46864 KB Output is correct
23 Correct 48 ms 45904 KB Output is correct
24 Correct 47 ms 46432 KB Output is correct
25 Correct 51 ms 46808 KB Output is correct
26 Correct 48 ms 45784 KB Output is correct
27 Correct 47 ms 47064 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 55 ms 45820 KB Output is correct
2 Correct 49 ms 45744 KB Output is correct
3 Correct 49 ms 45820 KB Output is correct
4 Correct 50 ms 45720 KB Output is correct
5 Correct 49 ms 45772 KB Output is correct
6 Correct 47 ms 45832 KB Output is correct
7 Correct 58 ms 45768 KB Output is correct
8 Correct 47 ms 45792 KB Output is correct
9 Correct 47 ms 45768 KB Output is correct
10 Correct 46 ms 45772 KB Output is correct
11 Correct 48 ms 46032 KB Output is correct
12 Correct 48 ms 45952 KB Output is correct
13 Correct 47 ms 45772 KB Output is correct
14 Correct 54 ms 45868 KB Output is correct
15 Correct 48 ms 46208 KB Output is correct
16 Correct 47 ms 45840 KB Output is correct
17 Correct 46 ms 45900 KB Output is correct
18 Correct 47 ms 45960 KB Output is correct
19 Correct 53 ms 45848 KB Output is correct
20 Correct 47 ms 45992 KB Output is correct
21 Correct 46 ms 46084 KB Output is correct
22 Correct 49 ms 46864 KB Output is correct
23 Correct 48 ms 45904 KB Output is correct
24 Correct 47 ms 46432 KB Output is correct
25 Correct 51 ms 46808 KB Output is correct
26 Correct 48 ms 45784 KB Output is correct
27 Correct 47 ms 47064 KB Output is correct
28 Correct 48 ms 46000 KB Output is correct
29 Correct 50 ms 47332 KB Output is correct
30 Correct 53 ms 48500 KB Output is correct
31 Correct 51 ms 45864 KB Output is correct
32 Correct 54 ms 47436 KB Output is correct
33 Correct 52 ms 48800 KB Output is correct
34 Correct 56 ms 50160 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 55 ms 45820 KB Output is correct
2 Correct 49 ms 45744 KB Output is correct
3 Correct 49 ms 45820 KB Output is correct
4 Correct 50 ms 45720 KB Output is correct
5 Correct 49 ms 45772 KB Output is correct
6 Correct 47 ms 45832 KB Output is correct
7 Correct 58 ms 45768 KB Output is correct
8 Correct 47 ms 45792 KB Output is correct
9 Correct 47 ms 45768 KB Output is correct
10 Correct 46 ms 45772 KB Output is correct
11 Correct 48 ms 46032 KB Output is correct
12 Correct 48 ms 45952 KB Output is correct
13 Correct 47 ms 45772 KB Output is correct
14 Correct 54 ms 45868 KB Output is correct
15 Correct 48 ms 46208 KB Output is correct
16 Correct 47 ms 45840 KB Output is correct
17 Correct 46 ms 45900 KB Output is correct
18 Correct 47 ms 45960 KB Output is correct
19 Correct 53 ms 45848 KB Output is correct
20 Correct 47 ms 45992 KB Output is correct
21 Correct 46 ms 46084 KB Output is correct
22 Correct 49 ms 46864 KB Output is correct
23 Correct 48 ms 45904 KB Output is correct
24 Correct 47 ms 46432 KB Output is correct
25 Correct 51 ms 46808 KB Output is correct
26 Correct 48 ms 45784 KB Output is correct
27 Correct 47 ms 47064 KB Output is correct
28 Correct 48 ms 46000 KB Output is correct
29 Correct 50 ms 47332 KB Output is correct
30 Correct 53 ms 48500 KB Output is correct
31 Correct 51 ms 45864 KB Output is correct
32 Correct 54 ms 47436 KB Output is correct
33 Correct 52 ms 48800 KB Output is correct
34 Correct 56 ms 50160 KB Output is correct
35 Correct 58 ms 45900 KB Output is correct
36 Correct 83 ms 55628 KB Output is correct
37 Correct 63 ms 45836 KB Output is correct
38 Correct 74 ms 50568 KB Output is correct
39 Correct 75 ms 54200 KB Output is correct
40 Correct 95 ms 57740 KB Output is correct