답안 #649214

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
649214 2022-10-09T15:36:54 Z boris_mihov NoM (RMI21_nom) C++17
100 / 100
260 ms 71028 KB
#include <unordered_map>
#include <algorithm>
#include <iostream>
#include <numeric>
#include <vector>
#include <set>

typedef long long llong;
const int MAXN = 2000 + 10;
const int MOD  = 1e9 + 7;
const int INF  = 1e9;

int n, m;
int fact[MAXN];
int var[MAXN][MAXN];
int comb[MAXN][MAXN];
inline llong getKey(int idx, int zeros, int ones)
{
    return 1LL * idx * MAXN * MAXN + zeros * MAXN + ones;
}

std::unordered_map <llong,int> dp;
int f(int idx, int zeros, int ones)
{
    if (idx == 0)
    {
        return (zeros == 0 && ones == 0);
    }

    llong key = getKey(idx, zeros, ones);
    if (dp.count(key))
    {
        return dp[key];
    }

    int res = 0;
    int len = (2*n - idx + 1) / m + (idx != 1);
    for (int addOnes = std::max(0, len - ones) ; addOnes <= std::min(len, zeros) ; ++addOnes)
    {
        res += (((((1LL * f(idx-1, zeros - addOnes, ones + 2*addOnes - len) * comb[len][addOnes]) % MOD) * var[zeros][addOnes]) % MOD) * var[ones][len - addOnes]) % MOD;
        if (res >= MOD) res -= MOD;
    }

    return dp[key] = res;
}
void solve()
{
    for (int i = 0 ; i <= n ; ++i)
    {
        comb[i][0] = 1;
    }

    fact[0] = 1;
    for (int i = 1 ; i <= n ; ++i)
    {
        fact[i] = (1LL * fact[i-1] * i) % MOD;
    }

    for (int i = 1 ; i <= n ; ++i)
    {
        for (int j = 1 ; j <= i ; ++j)
        {
            comb[i][j] = comb[i-1][j] + comb[i-1][j-1];
            if (comb[i][j] >= MOD) comb[i][j] -= MOD;
        }
    }

    for (int i = 0 ; i <= n ; ++i)
    {
        for (int j = 0 ; j <= i ; ++j)
        {
            var[i][j] = (1LL * comb[i][j] * fact[j]) % MOD; 
        }
    }

    int ans = f(m, n, 0);
    for (int i = 1 ; i <= n ; ++i)
    {
        ans *= 2;
        ans %= MOD;
    }

    std::cout << ans << '\n';
}

void read() 
{
    std::cin >> n >> m;
}

void fastIO()
{
    std::ios_base :: sync_with_stdio(0);
    std::cout.tie(nullptr);
    std::cin.tie(nullptr);
}

int main()
{
    fastIO();
    read();
    solve();

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 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 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 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 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 1108 KB Output is correct
12 Correct 1 ms 852 KB Output is correct
13 Correct 1 ms 852 KB Output is correct
14 Correct 1 ms 852 KB Output is correct
15 Correct 1 ms 980 KB Output is correct
16 Correct 1 ms 980 KB Output is correct
17 Correct 1 ms 852 KB Output is correct
18 Correct 1 ms 852 KB Output is correct
19 Correct 1 ms 980 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 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 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 1108 KB Output is correct
12 Correct 1 ms 852 KB Output is correct
13 Correct 1 ms 852 KB Output is correct
14 Correct 1 ms 852 KB Output is correct
15 Correct 1 ms 980 KB Output is correct
16 Correct 1 ms 980 KB Output is correct
17 Correct 1 ms 852 KB Output is correct
18 Correct 1 ms 852 KB Output is correct
19 Correct 1 ms 980 KB Output is correct
20 Correct 1 ms 1748 KB Output is correct
21 Correct 2 ms 1748 KB Output is correct
22 Correct 5 ms 3412 KB Output is correct
23 Correct 3 ms 2516 KB Output is correct
24 Correct 4 ms 3540 KB Output is correct
25 Correct 5 ms 3284 KB Output is correct
26 Correct 2 ms 2644 KB Output is correct
27 Correct 5 ms 4180 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 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 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 1108 KB Output is correct
12 Correct 1 ms 852 KB Output is correct
13 Correct 1 ms 852 KB Output is correct
14 Correct 1 ms 852 KB Output is correct
15 Correct 1 ms 980 KB Output is correct
16 Correct 1 ms 980 KB Output is correct
17 Correct 1 ms 852 KB Output is correct
18 Correct 1 ms 852 KB Output is correct
19 Correct 1 ms 980 KB Output is correct
20 Correct 1 ms 1748 KB Output is correct
21 Correct 2 ms 1748 KB Output is correct
22 Correct 5 ms 3412 KB Output is correct
23 Correct 3 ms 2516 KB Output is correct
24 Correct 4 ms 3540 KB Output is correct
25 Correct 5 ms 3284 KB Output is correct
26 Correct 2 ms 2644 KB Output is correct
27 Correct 5 ms 4180 KB Output is correct
28 Correct 8 ms 6996 KB Output is correct
29 Correct 16 ms 9700 KB Output is correct
30 Correct 22 ms 11876 KB Output is correct
31 Correct 8 ms 7056 KB Output is correct
32 Correct 17 ms 10200 KB Output is correct
33 Correct 46 ms 13188 KB Output is correct
34 Correct 48 ms 20324 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 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 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 1108 KB Output is correct
12 Correct 1 ms 852 KB Output is correct
13 Correct 1 ms 852 KB Output is correct
14 Correct 1 ms 852 KB Output is correct
15 Correct 1 ms 980 KB Output is correct
16 Correct 1 ms 980 KB Output is correct
17 Correct 1 ms 852 KB Output is correct
18 Correct 1 ms 852 KB Output is correct
19 Correct 1 ms 980 KB Output is correct
20 Correct 1 ms 1748 KB Output is correct
21 Correct 2 ms 1748 KB Output is correct
22 Correct 5 ms 3412 KB Output is correct
23 Correct 3 ms 2516 KB Output is correct
24 Correct 4 ms 3540 KB Output is correct
25 Correct 5 ms 3284 KB Output is correct
26 Correct 2 ms 2644 KB Output is correct
27 Correct 5 ms 4180 KB Output is correct
28 Correct 8 ms 6996 KB Output is correct
29 Correct 16 ms 9700 KB Output is correct
30 Correct 22 ms 11876 KB Output is correct
31 Correct 8 ms 7056 KB Output is correct
32 Correct 17 ms 10200 KB Output is correct
33 Correct 46 ms 13188 KB Output is correct
34 Correct 48 ms 20324 KB Output is correct
35 Correct 47 ms 22348 KB Output is correct
36 Correct 260 ms 63932 KB Output is correct
37 Correct 45 ms 22052 KB Output is correct
38 Correct 127 ms 36028 KB Output is correct
39 Correct 203 ms 46320 KB Output is correct
40 Correct 247 ms 71028 KB Output is correct