답안 #786244

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
786244 2023-07-18T05:47:46 Z 이동현(#10029) NoM (RMI21_nom) C++17
9 / 100
47 ms 78388 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;

        // cout << ans << endl;
    }

    cout << ans << '\n';

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 40 ms 78060 KB Output is correct
2 Correct 36 ms 78136 KB Output is correct
3 Correct 40 ms 78112 KB Output is correct
4 Correct 42 ms 78260 KB Output is correct
5 Correct 38 ms 78092 KB Output is correct
6 Correct 38 ms 78076 KB Output is correct
7 Correct 38 ms 78080 KB Output is correct
8 Correct 38 ms 78148 KB Output is correct
9 Correct 38 ms 78132 KB Output is correct
10 Correct 37 ms 78184 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 40 ms 78060 KB Output is correct
2 Correct 36 ms 78136 KB Output is correct
3 Correct 40 ms 78112 KB Output is correct
4 Correct 42 ms 78260 KB Output is correct
5 Correct 38 ms 78092 KB Output is correct
6 Correct 38 ms 78076 KB Output is correct
7 Correct 38 ms 78080 KB Output is correct
8 Correct 38 ms 78148 KB Output is correct
9 Correct 38 ms 78132 KB Output is correct
10 Correct 37 ms 78184 KB Output is correct
11 Correct 39 ms 78336 KB Output is correct
12 Correct 47 ms 78388 KB Output is correct
13 Incorrect 39 ms 78084 KB Output isn't correct
14 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 40 ms 78060 KB Output is correct
2 Correct 36 ms 78136 KB Output is correct
3 Correct 40 ms 78112 KB Output is correct
4 Correct 42 ms 78260 KB Output is correct
5 Correct 38 ms 78092 KB Output is correct
6 Correct 38 ms 78076 KB Output is correct
7 Correct 38 ms 78080 KB Output is correct
8 Correct 38 ms 78148 KB Output is correct
9 Correct 38 ms 78132 KB Output is correct
10 Correct 37 ms 78184 KB Output is correct
11 Correct 39 ms 78336 KB Output is correct
12 Correct 47 ms 78388 KB Output is correct
13 Incorrect 39 ms 78084 KB Output isn't correct
14 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 40 ms 78060 KB Output is correct
2 Correct 36 ms 78136 KB Output is correct
3 Correct 40 ms 78112 KB Output is correct
4 Correct 42 ms 78260 KB Output is correct
5 Correct 38 ms 78092 KB Output is correct
6 Correct 38 ms 78076 KB Output is correct
7 Correct 38 ms 78080 KB Output is correct
8 Correct 38 ms 78148 KB Output is correct
9 Correct 38 ms 78132 KB Output is correct
10 Correct 37 ms 78184 KB Output is correct
11 Correct 39 ms 78336 KB Output is correct
12 Correct 47 ms 78388 KB Output is correct
13 Incorrect 39 ms 78084 KB Output isn't correct
14 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 40 ms 78060 KB Output is correct
2 Correct 36 ms 78136 KB Output is correct
3 Correct 40 ms 78112 KB Output is correct
4 Correct 42 ms 78260 KB Output is correct
5 Correct 38 ms 78092 KB Output is correct
6 Correct 38 ms 78076 KB Output is correct
7 Correct 38 ms 78080 KB Output is correct
8 Correct 38 ms 78148 KB Output is correct
9 Correct 38 ms 78132 KB Output is correct
10 Correct 37 ms 78184 KB Output is correct
11 Correct 39 ms 78336 KB Output is correct
12 Correct 47 ms 78388 KB Output is correct
13 Incorrect 39 ms 78084 KB Output isn't correct
14 Halted 0 ms 0 KB -