Submission #786248

# Submission time Handle Problem Language Result Execution time Memory
786248 2023-07-18T05:49:11 Z 이동현(#10029) NoM (RMI21_nom) C++17
100 / 100
72 ms 109548 KB
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#define int long long
using namespace std;

const int mod = (int)1e9 + 7;
int n, m;
int dp[2004][2004];
int comb[4004][4004];
int fact[4004];
int factinv[4004];
vector<int> a;

int pw(int x, int y){
    if(!y) return 1;
    if(y == 1) return x;
    int val = pw(x, y / 2);
    return val * val % mod * (y % 2 ? x : 1) % mod;
}

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    cin >> n >> m;
    a.push_back(-1);
    for(int i = 0; i < m - n * 2 % m; ++i){
        a.push_back(n * 2 / m);
    }
    for(int i = 0; i < n * 2 % m; ++i){
        a.push_back(n * 2 / m + 1);
    }

    for(int i = 0; i < 4004; ++i){
        comb[i][0] = 1;
        for(int j = 1; j <= i; ++j){
            comb[i][j] = (comb[i - 1][j - 1] + comb[i - 1][j]) % mod;
        }
    }
    fact[0] = 1;
    factinv[0] = 1;
    for(int i = 1; i < 4004; ++i){
        fact[i] = fact[i - 1] * i % mod;
        factinv[i] = pw(fact[i], mod - 2);
    }

    dp[0][0] = 1;
    for(int i = 1; i <= m; ++i){
        // cout << a[i] << endl;
        int gop = 1;
        for(int j = 0; j * 2 <= a[i]; ++j){
            for(int k = 0; k + j <= n; ++k){
                (dp[i][k + j] += dp[i - 1][k] * gop % mod * factinv[j]) %= mod;
            }
            (gop *= a[i] - j * 2) %= mod;
            (gop *= a[i] - j * 2 - 1) %= mod;
        }
    }

    int ans = 0;
    for(int i = 0; i <= n; ++i){
        int op = (i % 2 ? -1 : 1);

        (ans += fact[i] * comb[n][i] % mod * dp[m][i] % mod * fact[(n - i) * 2] * op % mod + mod) %= mod;

        // cout << ans << endl;
    }

    cout << ans << '\n';

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 37 ms 78172 KB Output is correct
2 Correct 37 ms 78156 KB Output is correct
3 Correct 37 ms 78136 KB Output is correct
4 Correct 43 ms 78088 KB Output is correct
5 Correct 36 ms 78176 KB Output is correct
6 Correct 37 ms 78092 KB Output is correct
7 Correct 44 ms 78116 KB Output is correct
8 Correct 35 ms 78104 KB Output is correct
9 Correct 37 ms 78100 KB Output is correct
10 Correct 36 ms 78116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 37 ms 78172 KB Output is correct
2 Correct 37 ms 78156 KB Output is correct
3 Correct 37 ms 78136 KB Output is correct
4 Correct 43 ms 78088 KB Output is correct
5 Correct 36 ms 78176 KB Output is correct
6 Correct 37 ms 78092 KB Output is correct
7 Correct 44 ms 78116 KB Output is correct
8 Correct 35 ms 78104 KB Output is correct
9 Correct 37 ms 78100 KB Output is correct
10 Correct 36 ms 78116 KB Output is correct
11 Correct 37 ms 78328 KB Output is correct
12 Correct 45 ms 78372 KB Output is correct
13 Correct 37 ms 78140 KB Output is correct
14 Correct 37 ms 78232 KB Output is correct
15 Correct 39 ms 78424 KB Output is correct
16 Correct 37 ms 78148 KB Output is correct
17 Correct 37 ms 78248 KB Output is correct
18 Correct 38 ms 78392 KB Output is correct
19 Correct 36 ms 78100 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 37 ms 78172 KB Output is correct
2 Correct 37 ms 78156 KB Output is correct
3 Correct 37 ms 78136 KB Output is correct
4 Correct 43 ms 78088 KB Output is correct
5 Correct 36 ms 78176 KB Output is correct
6 Correct 37 ms 78092 KB Output is correct
7 Correct 44 ms 78116 KB Output is correct
8 Correct 35 ms 78104 KB Output is correct
9 Correct 37 ms 78100 KB Output is correct
10 Correct 36 ms 78116 KB Output is correct
11 Correct 37 ms 78328 KB Output is correct
12 Correct 45 ms 78372 KB Output is correct
13 Correct 37 ms 78140 KB Output is correct
14 Correct 37 ms 78232 KB Output is correct
15 Correct 39 ms 78424 KB Output is correct
16 Correct 37 ms 78148 KB Output is correct
17 Correct 37 ms 78248 KB Output is correct
18 Correct 38 ms 78392 KB Output is correct
19 Correct 36 ms 78100 KB Output is correct
20 Correct 37 ms 78224 KB Output is correct
21 Correct 37 ms 78560 KB Output is correct
22 Correct 39 ms 79788 KB Output is correct
23 Correct 37 ms 78172 KB Output is correct
24 Correct 39 ms 79044 KB Output is correct
25 Correct 39 ms 79620 KB Output is correct
26 Correct 38 ms 78156 KB Output is correct
27 Correct 38 ms 80076 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 37 ms 78172 KB Output is correct
2 Correct 37 ms 78156 KB Output is correct
3 Correct 37 ms 78136 KB Output is correct
4 Correct 43 ms 78088 KB Output is correct
5 Correct 36 ms 78176 KB Output is correct
6 Correct 37 ms 78092 KB Output is correct
7 Correct 44 ms 78116 KB Output is correct
8 Correct 35 ms 78104 KB Output is correct
9 Correct 37 ms 78100 KB Output is correct
10 Correct 36 ms 78116 KB Output is correct
11 Correct 37 ms 78328 KB Output is correct
12 Correct 45 ms 78372 KB Output is correct
13 Correct 37 ms 78140 KB Output is correct
14 Correct 37 ms 78232 KB Output is correct
15 Correct 39 ms 78424 KB Output is correct
16 Correct 37 ms 78148 KB Output is correct
17 Correct 37 ms 78248 KB Output is correct
18 Correct 38 ms 78392 KB Output is correct
19 Correct 36 ms 78100 KB Output is correct
20 Correct 37 ms 78224 KB Output is correct
21 Correct 37 ms 78560 KB Output is correct
22 Correct 39 ms 79788 KB Output is correct
23 Correct 37 ms 78172 KB Output is correct
24 Correct 39 ms 79044 KB Output is correct
25 Correct 39 ms 79620 KB Output is correct
26 Correct 38 ms 78156 KB Output is correct
27 Correct 38 ms 80076 KB Output is correct
28 Correct 38 ms 78284 KB Output is correct
29 Correct 40 ms 81064 KB Output is correct
30 Correct 41 ms 83404 KB Output is correct
31 Correct 43 ms 78196 KB Output is correct
32 Correct 42 ms 81408 KB Output is correct
33 Correct 43 ms 84280 KB Output is correct
34 Correct 47 ms 88052 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 37 ms 78172 KB Output is correct
2 Correct 37 ms 78156 KB Output is correct
3 Correct 37 ms 78136 KB Output is correct
4 Correct 43 ms 78088 KB Output is correct
5 Correct 36 ms 78176 KB Output is correct
6 Correct 37 ms 78092 KB Output is correct
7 Correct 44 ms 78116 KB Output is correct
8 Correct 35 ms 78104 KB Output is correct
9 Correct 37 ms 78100 KB Output is correct
10 Correct 36 ms 78116 KB Output is correct
11 Correct 37 ms 78328 KB Output is correct
12 Correct 45 ms 78372 KB Output is correct
13 Correct 37 ms 78140 KB Output is correct
14 Correct 37 ms 78232 KB Output is correct
15 Correct 39 ms 78424 KB Output is correct
16 Correct 37 ms 78148 KB Output is correct
17 Correct 37 ms 78248 KB Output is correct
18 Correct 38 ms 78392 KB Output is correct
19 Correct 36 ms 78100 KB Output is correct
20 Correct 37 ms 78224 KB Output is correct
21 Correct 37 ms 78560 KB Output is correct
22 Correct 39 ms 79788 KB Output is correct
23 Correct 37 ms 78172 KB Output is correct
24 Correct 39 ms 79044 KB Output is correct
25 Correct 39 ms 79620 KB Output is correct
26 Correct 38 ms 78156 KB Output is correct
27 Correct 38 ms 80076 KB Output is correct
28 Correct 38 ms 78284 KB Output is correct
29 Correct 40 ms 81064 KB Output is correct
30 Correct 41 ms 83404 KB Output is correct
31 Correct 43 ms 78196 KB Output is correct
32 Correct 42 ms 81408 KB Output is correct
33 Correct 43 ms 84280 KB Output is correct
34 Correct 47 ms 88052 KB Output is correct
35 Correct 44 ms 78396 KB Output is correct
36 Correct 72 ms 104548 KB Output is correct
37 Correct 45 ms 78368 KB Output is correct
38 Correct 52 ms 90992 KB Output is correct
39 Correct 62 ms 101628 KB Output is correct
40 Correct 72 ms 109548 KB Output is correct