| # | Time | Username | Problem | Language | Result | Execution time | Memory | 
|---|---|---|---|---|---|---|---|
| 210006 | SamAnd | Zapina (COCI20_zapina) | C++17 | 71 ms | 5752 KiB | 
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
const int N = 1003;
const int M = 1000000007;
int n;
int c[N][N];
int dp[N][N];
int dp1[N][N];
//int dp11[N][N];
int main()
{
    for (int i = 0; i < N; ++i)
    {
        c[i][0] = 1;
        for (int j = 1; j <= i; ++j)
            c[i][j] = (c[i - 1][j] + c[i - 1][j - 1]) % M;
    }
    scanf("%d", &n);
    dp[0][0] = 1;
    for (int x = 1; x <= n; ++x)
    {
        for (int i = n; i >= 0; --i)
        {
            for (int j = n; j >= 0; --j)
            {
                if (!dp[i][j])
                    continue;
                if (j + x <= n)
                    dp[i + 1][j + x] = (dp[i + 1][j + x] + (dp[i][j] * 1LL * c[n - j][x]) % M) % M;
            }
        }
    }
    /*for (int j = 0; j <= n; ++j)
    {
        for (int i = 0; i <= n; ++i)
            for (int k = 0; k <= j; ++k)
                dp11[i][k] = 0;
        dp11[0][0] = 1;
        for (int i = 1; i <= n; ++i)
        {
            for (int k = 0; k <= j; ++k)
            {
                for (int q = 0; q <= k; ++q)
                {
                    dp11[i][k] = (dp11[i][k] + (dp11[i - 1][k - q] * 1LL * c[k][q]) % M) % M;
                }
            }
        }
        for (int i = 0; i <= n; ++i)
            dp1[i][j] = dp11[i][j];
    }*/
    for (int i = 0; i <= n; ++i)
    {
        dp1[i][0] = 1;
        for (int j = 1; j <= n; ++j)
            dp1[i][j] = (dp1[i][j - 1] * 1LL * i) % M;
    }
    int ans = 0;
    for (int i = 1; i <= n; ++i)
    {
        for (int j = 1; j <= n; ++j)
        {
            if (i % 2 == 1)
            {
                ans = (ans + (dp[i][j] * 1LL * dp1[n - i][n - j]) % M) % M;
            }
            else
            {
                ans = (ans - (dp[i][j] * 1LL * dp1[n - i][n - j]) % M + M) % M;
            }
        }
    }
    printf("%d\n", ans);
    return 0;
}
Compilation message (stderr)
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
