답안 #703357

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
703357 2023-02-27T07:08:15 Z Nursik NoM (RMI21_nom) C++14
52 / 100
500 ms 16944 KB
#include <iostream>
#include <fstream>
#include <iomanip>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <string>
#include <cmath>
#include <cassert>
#include <ctime>
#include <algorithm>
#include <sstream>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <cstdlib>
#include <cstdio>
#include <iterator>
#include <functional>
#include <unordered_set>
#include <unordered_map>
#include <stdio.h>
#include <bitset>
#include <cstdint>
#include <cassert>
#include <functional>
#include <complex>
#include <random>

using namespace std;
 
#define ll long long
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define ld long double
 
const ll maxn = 2e3 + 10, maxm = 1e7 + 1;
const ll mod = 1e9 + 7, cmod = 998244353, inf = 1e9, blcok = 400, p2 = 31;
const ld eps = 1e-9;

int is[maxn];
ll fact[maxn * 2];
ll dp[maxn][maxn];
ll bp(ll a, ll n){
    ll res = 1;
    while (n > 0){
        if (n & 1)
            res *= a;
        a *= a, n >>= 1;
        res %= mod, a %= mod;
    }
    return res;
}

ll cnk(int n, int k){
    return fact[n] * bp(fact[k], mod - 2) % mod * bp(fact[n - k], mod - 2) % mod;
}
int n, m;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
   // freopen("paths.in", "r", stdin);
   // freopen("paths.out", "w", stdout);
    cin >> n >> m;
    fact[0] = 1;
    for (int i = 1; i <= n * 2; ++i){
        fact[i] = fact[i - 1] * i % mod;
        int z = i % m + 1;
        is[z] += 1;
    }
    dp[0][0] = 1;
    for (int i = 1; i <= m; ++i){
        for (int j = 0; j <= n; ++j){
            if (dp[i - 1][j] > 0){
                for (int k = 0; k * 2 <= is[i]; ++k){
                    if (j + k <= n){
                        dp[i][j + k] = (dp[i][j + k] + dp[i - 1][j] * cnk(j + k, k) % mod * fact[is[i]] % mod * bp(fact[is[i] - 2 * k], mod - 2) % mod) % mod;
                    }
                    else{
                        break;
                    }
                }
            }
            else{
                break;
            }
        }
    }
    ll ans = fact[2 * n];
    int cur = 1;
    //cout << ans << '\n';
    for (int i = 1; i <= n; ++i){
        ll del = cur * cnk(n, i) % mod  * fact[2 * n - 2 * i] % mod * dp[m][i] % mod;
        cur *= -1;
        ans = (ans - del + mod) % mod;
    }
    cout << ans;
}
/*
*/

# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 4 ms 500 KB Output is correct
12 Correct 2 ms 468 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 2 ms 596 KB Output is correct
16 Correct 2 ms 340 KB Output is correct
17 Correct 2 ms 468 KB Output is correct
18 Correct 2 ms 468 KB Output is correct
19 Correct 2 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 4 ms 500 KB Output is correct
12 Correct 2 ms 468 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 2 ms 596 KB Output is correct
16 Correct 2 ms 340 KB Output is correct
17 Correct 2 ms 468 KB Output is correct
18 Correct 2 ms 468 KB Output is correct
19 Correct 2 ms 340 KB Output is correct
20 Correct 6 ms 400 KB Output is correct
21 Correct 7 ms 596 KB Output is correct
22 Correct 27 ms 1492 KB Output is correct
23 Correct 12 ms 340 KB Output is correct
24 Correct 25 ms 1052 KB Output is correct
25 Correct 29 ms 1496 KB Output is correct
26 Correct 15 ms 544 KB Output is correct
27 Correct 40 ms 1852 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 4 ms 500 KB Output is correct
12 Correct 2 ms 468 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 2 ms 596 KB Output is correct
16 Correct 2 ms 340 KB Output is correct
17 Correct 2 ms 468 KB Output is correct
18 Correct 2 ms 468 KB Output is correct
19 Correct 2 ms 340 KB Output is correct
20 Correct 6 ms 400 KB Output is correct
21 Correct 7 ms 596 KB Output is correct
22 Correct 27 ms 1492 KB Output is correct
23 Correct 12 ms 340 KB Output is correct
24 Correct 25 ms 1052 KB Output is correct
25 Correct 29 ms 1496 KB Output is correct
26 Correct 15 ms 544 KB Output is correct
27 Correct 40 ms 1852 KB Output is correct
28 Correct 79 ms 440 KB Output is correct
29 Correct 127 ms 2352 KB Output is correct
30 Correct 139 ms 3972 KB Output is correct
31 Correct 78 ms 416 KB Output is correct
32 Correct 143 ms 2620 KB Output is correct
33 Correct 187 ms 4524 KB Output is correct
34 Correct 331 ms 7024 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 4 ms 500 KB Output is correct
12 Correct 2 ms 468 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 2 ms 596 KB Output is correct
16 Correct 2 ms 340 KB Output is correct
17 Correct 2 ms 468 KB Output is correct
18 Correct 2 ms 468 KB Output is correct
19 Correct 2 ms 340 KB Output is correct
20 Correct 6 ms 400 KB Output is correct
21 Correct 7 ms 596 KB Output is correct
22 Correct 27 ms 1492 KB Output is correct
23 Correct 12 ms 340 KB Output is correct
24 Correct 25 ms 1052 KB Output is correct
25 Correct 29 ms 1496 KB Output is correct
26 Correct 15 ms 544 KB Output is correct
27 Correct 40 ms 1852 KB Output is correct
28 Correct 79 ms 440 KB Output is correct
29 Correct 127 ms 2352 KB Output is correct
30 Correct 139 ms 3972 KB Output is correct
31 Correct 78 ms 416 KB Output is correct
32 Correct 143 ms 2620 KB Output is correct
33 Correct 187 ms 4524 KB Output is correct
34 Correct 331 ms 7024 KB Output is correct
35 Correct 498 ms 608 KB Output is correct
36 Execution timed out 1074 ms 16944 KB Time limit exceeded
37 Halted 0 ms 0 KB -