Submission #703355

# Submission time Handle Problem Language Result Execution time Memory
703355 2023-02-27T07:00:09 Z Nursik NoM (RMI21_nom) C++14
52 / 100
500 ms 7016 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;
                    }
                }
            }
        }
    }
    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;
}
/*
*/

# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 4 ms 468 KB Output is correct
12 Correct 2 ms 468 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 2 ms 340 KB Output is correct
15 Correct 3 ms 596 KB Output is correct
16 Correct 2 ms 340 KB Output is correct
17 Correct 2 ms 460 KB Output is correct
18 Correct 2 ms 468 KB Output is correct
19 Correct 2 ms 456 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 4 ms 468 KB Output is correct
12 Correct 2 ms 468 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 2 ms 340 KB Output is correct
15 Correct 3 ms 596 KB Output is correct
16 Correct 2 ms 340 KB Output is correct
17 Correct 2 ms 460 KB Output is correct
18 Correct 2 ms 468 KB Output is correct
19 Correct 2 ms 456 KB Output is correct
20 Correct 7 ms 340 KB Output is correct
21 Correct 9 ms 600 KB Output is correct
22 Correct 29 ms 1484 KB Output is correct
23 Correct 12 ms 416 KB Output is correct
24 Correct 25 ms 1072 KB Output is correct
25 Correct 28 ms 1480 KB Output is correct
26 Correct 14 ms 340 KB Output is correct
27 Correct 38 ms 1860 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 4 ms 468 KB Output is correct
12 Correct 2 ms 468 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 2 ms 340 KB Output is correct
15 Correct 3 ms 596 KB Output is correct
16 Correct 2 ms 340 KB Output is correct
17 Correct 2 ms 460 KB Output is correct
18 Correct 2 ms 468 KB Output is correct
19 Correct 2 ms 456 KB Output is correct
20 Correct 7 ms 340 KB Output is correct
21 Correct 9 ms 600 KB Output is correct
22 Correct 29 ms 1484 KB Output is correct
23 Correct 12 ms 416 KB Output is correct
24 Correct 25 ms 1072 KB Output is correct
25 Correct 28 ms 1480 KB Output is correct
26 Correct 14 ms 340 KB Output is correct
27 Correct 38 ms 1860 KB Output is correct
28 Correct 81 ms 444 KB Output is correct
29 Correct 132 ms 2428 KB Output is correct
30 Correct 144 ms 3924 KB Output is correct
31 Correct 78 ms 400 KB Output is correct
32 Correct 140 ms 2640 KB Output is correct
33 Correct 177 ms 4500 KB Output is correct
34 Correct 335 ms 7016 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 4 ms 468 KB Output is correct
12 Correct 2 ms 468 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 2 ms 340 KB Output is correct
15 Correct 3 ms 596 KB Output is correct
16 Correct 2 ms 340 KB Output is correct
17 Correct 2 ms 460 KB Output is correct
18 Correct 2 ms 468 KB Output is correct
19 Correct 2 ms 456 KB Output is correct
20 Correct 7 ms 340 KB Output is correct
21 Correct 9 ms 600 KB Output is correct
22 Correct 29 ms 1484 KB Output is correct
23 Correct 12 ms 416 KB Output is correct
24 Correct 25 ms 1072 KB Output is correct
25 Correct 28 ms 1480 KB Output is correct
26 Correct 14 ms 340 KB Output is correct
27 Correct 38 ms 1860 KB Output is correct
28 Correct 81 ms 444 KB Output is correct
29 Correct 132 ms 2428 KB Output is correct
30 Correct 144 ms 3924 KB Output is correct
31 Correct 78 ms 400 KB Output is correct
32 Correct 140 ms 2640 KB Output is correct
33 Correct 177 ms 4500 KB Output is correct
34 Correct 335 ms 7016 KB Output is correct
35 Execution timed out 519 ms 632 KB Time limit exceeded
36 Halted 0 ms 0 KB -