Submission #499258

# Submission time Handle Problem Language Result Execution time Memory
499258 2021-12-27T14:18:00 Z amunduzbaev NoM (RMI21_nom) C++14
100 / 100
177 ms 368 KB
#include "bits/stdc++.h"
using namespace std;
 
#define ar array
 
const int mod = 1e9 + 7;
 
int pre[5][5] = {
    {0, 2, 2, 2, 2},
    {0, 16, 16, 24, 24},
    {0, 288, 384, 480, 576},
    {0, 9216, 13824, 23040, 26112},
    {0, 460800, 829440, 1428480, 2088960}
};
 
int bp(int a, int b){
    int rr = 1;
    while(b){
        if(b&1) rr = rr * 1ll * a % mod;
        a = a * 1ll * a % mod, b >>= 1; 
    } return rr;
}
 
signed main(){
    ios::sync_with_stdio(0); cin.tie(0);
    
    int n, m; cin>>n>>m;
    vector<int> a(m);
    for(int i=0;i<2*n;i++){
        a[i % m]++;
    }
    
    vector<int> dp(2 * n + 1);
    vector<int> f(2 * n + 1), inv(2 * n + 1);
    f[0] = inv[0] = 1;
    for(int i=1;i<=2 * n;i++){
        f[i] = f[i-1] * 1ll * i % mod;
        inv[i] = bp(f[i], mod - 2);
    }
    auto C = [&](int n, int k){
        return f[n] * 1ll * inv[k] % mod * inv[n - k] % mod;
    };
    reverse(a.begin(), a.end());
    dp[a[0]] = 1;
    int sum = a[0];
 
    for(int i=1;i<m;i++){
        vector<int> nw(2 * n + 1);
        for(int j=0;j<=a[i];j++){
            for(int l=j;l<=sum;l++){
                nw[l + a[i] - j * 2] = (nw[l + a[i] - 2 * j] + dp[l] * 1ll * f[j] % mod * C(a[i], j) % mod * C(l, j)) % mod;
            }
        } dp = nw;
        sum += a[i];
    }
    
    int res = dp[0];
    for(int i=0;i<n;i++) res = res * 2ll % mod;
    res = res * 1ll * f[n] % mod;
    cout<<res<<"\n";
}
 
# Verdict Execution time Memory Grader output
1 Correct 1 ms 312 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 316 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 0 ms 312 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 312 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 316 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 0 ms 312 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 308 KB Output is correct
14 Correct 1 ms 308 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 312 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 312 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 316 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 0 ms 312 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 308 KB Output is correct
14 Correct 1 ms 308 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 312 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 312 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 4 ms 204 KB Output is correct
23 Correct 2 ms 316 KB Output is correct
24 Correct 5 ms 204 KB Output is correct
25 Correct 3 ms 308 KB Output is correct
26 Correct 3 ms 204 KB Output is correct
27 Correct 5 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 312 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 316 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 0 ms 312 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 308 KB Output is correct
14 Correct 1 ms 308 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 312 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 312 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 4 ms 204 KB Output is correct
23 Correct 2 ms 316 KB Output is correct
24 Correct 5 ms 204 KB Output is correct
25 Correct 3 ms 308 KB Output is correct
26 Correct 3 ms 204 KB Output is correct
27 Correct 5 ms 204 KB Output is correct
28 Correct 14 ms 312 KB Output is correct
29 Correct 17 ms 332 KB Output is correct
30 Correct 19 ms 332 KB Output is correct
31 Correct 11 ms 324 KB Output is correct
32 Correct 17 ms 332 KB Output is correct
33 Correct 21 ms 340 KB Output is correct
34 Correct 40 ms 312 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 312 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 316 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 0 ms 312 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 308 KB Output is correct
14 Correct 1 ms 308 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 312 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 312 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 4 ms 204 KB Output is correct
23 Correct 2 ms 316 KB Output is correct
24 Correct 5 ms 204 KB Output is correct
25 Correct 3 ms 308 KB Output is correct
26 Correct 3 ms 204 KB Output is correct
27 Correct 5 ms 204 KB Output is correct
28 Correct 14 ms 312 KB Output is correct
29 Correct 17 ms 332 KB Output is correct
30 Correct 19 ms 332 KB Output is correct
31 Correct 11 ms 324 KB Output is correct
32 Correct 17 ms 332 KB Output is correct
33 Correct 21 ms 340 KB Output is correct
34 Correct 40 ms 312 KB Output is correct
35 Correct 66 ms 344 KB Output is correct
36 Correct 140 ms 356 KB Output is correct
37 Correct 69 ms 344 KB Output is correct
38 Correct 96 ms 332 KB Output is correct
39 Correct 107 ms 348 KB Output is correct
40 Correct 177 ms 368 KB Output is correct