Submission #649208

# Submission time Handle Problem Language Result Execution time Memory
649208 2022-10-09T15:29:26 Z boris_mihov NoM (RMI21_nom) C++17
21 / 100
500 ms 6288 KB
#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;
llong fact[MAXN];
llong var[MAXN][MAXN];
llong comb[MAXN][MAXN];
llong dp[2][MAXN][MAXN];
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; 
        }
    }

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

    int ans = dp[m&1][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;
}
# Verdict Execution time Memory 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 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 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 1 ms 340 KB Output is correct
# Verdict Execution time Memory 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 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 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 1 ms 340 KB Output is correct
11 Correct 22 ms 2132 KB Output is correct
12 Correct 9 ms 1492 KB Output is correct
13 Correct 5 ms 1492 KB Output is correct
14 Correct 7 ms 1588 KB Output is correct
15 Correct 10 ms 1636 KB Output is correct
16 Correct 11 ms 1876 KB Output is correct
17 Correct 7 ms 1480 KB Output is correct
18 Correct 9 ms 1556 KB Output is correct
19 Correct 6 ms 1876 KB Output is correct
# Verdict Execution time Memory 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 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 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 1 ms 340 KB Output is correct
11 Correct 22 ms 2132 KB Output is correct
12 Correct 9 ms 1492 KB Output is correct
13 Correct 5 ms 1492 KB Output is correct
14 Correct 7 ms 1588 KB Output is correct
15 Correct 10 ms 1636 KB Output is correct
16 Correct 11 ms 1876 KB Output is correct
17 Correct 7 ms 1480 KB Output is correct
18 Correct 9 ms 1556 KB Output is correct
19 Correct 6 ms 1876 KB Output is correct
20 Correct 74 ms 3620 KB Output is correct
21 Correct 81 ms 3400 KB Output is correct
22 Execution timed out 503 ms 6288 KB Time limit exceeded
23 Halted 0 ms 0 KB -
# Verdict Execution time Memory 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 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 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 1 ms 340 KB Output is correct
11 Correct 22 ms 2132 KB Output is correct
12 Correct 9 ms 1492 KB Output is correct
13 Correct 5 ms 1492 KB Output is correct
14 Correct 7 ms 1588 KB Output is correct
15 Correct 10 ms 1636 KB Output is correct
16 Correct 11 ms 1876 KB Output is correct
17 Correct 7 ms 1480 KB Output is correct
18 Correct 9 ms 1556 KB Output is correct
19 Correct 6 ms 1876 KB Output is correct
20 Correct 74 ms 3620 KB Output is correct
21 Correct 81 ms 3400 KB Output is correct
22 Execution timed out 503 ms 6288 KB Time limit exceeded
23 Halted 0 ms 0 KB -
# Verdict Execution time Memory 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 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 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 1 ms 340 KB Output is correct
11 Correct 22 ms 2132 KB Output is correct
12 Correct 9 ms 1492 KB Output is correct
13 Correct 5 ms 1492 KB Output is correct
14 Correct 7 ms 1588 KB Output is correct
15 Correct 10 ms 1636 KB Output is correct
16 Correct 11 ms 1876 KB Output is correct
17 Correct 7 ms 1480 KB Output is correct
18 Correct 9 ms 1556 KB Output is correct
19 Correct 6 ms 1876 KB Output is correct
20 Correct 74 ms 3620 KB Output is correct
21 Correct 81 ms 3400 KB Output is correct
22 Execution timed out 503 ms 6288 KB Time limit exceeded
23 Halted 0 ms 0 KB -