답안 #464830

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
464830 2021-08-14T09:49:22 Z TheScrasse Zapina (COCI20_zapina) C++17
110 / 110
334 ms 1348 KB
#include <bits/stdc++.h>
using namespace std;

#define nl "\n"
#define nf endl
#define ll long long
#define pb push_back
#define _ << ' ' <<

#define INF (ll)1e18
#define mod 1000000007
#define maxn 360

ll i, i1, j, k, k1, t, n, m, res, flag[10], a, b;
ll fc[maxn], nv[maxn], dp[maxn][maxn];

ll fxp(ll b, ll e) {
    ll r = 1, k = b;
    while (e != 0) {
        if (e % 2) r = (r * k) % mod;
        k = (k * k) % mod; e /= 2;
    }
    return r;
}

ll inv(ll x) {
    return fxp(x, mod - 2);
}

ll bnm(ll a, ll b) {
    if (a < b || b < 0) return 0;
    ll r = (fc[a] * nv[b]) % mod;
    r = (r * nv[a - b]) % mod;
    return r;
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);

    #if !ONLINE_JUDGE && !EVAL
        ifstream cin("input.txt");
        ofstream cout("output.txt");
    #endif

    fc[0] = 1; nv[0] = 1;
    for (i = 1; i < maxn; i++) {
        fc[i] = (i * fc[i - 1]) % mod; nv[i] = inv(fc[i]);
    }

    cin >> n;

    dp[0][0] = 1;
    for (i = 1; i <= n; i++) {
        for (j = 0; j <= n; j++) {
            dp[i][j] = 0;
            for (k = 0; k <= j; k++) {
                dp[i][j] = (dp[i][j] + dp[i - 1][k] * bnm(n - k, n - j)) % mod;
            }
        }
    }
    res = dp[n][n];

    dp[0][0] = 1;
    for (i = 1; i <= n; i++) {
        for (j = 0; j <= n; j++) {
            dp[i][j] = 0;
            for (k = 0; k <= j; k++) {
                if (j - k == i) continue;
                dp[i][j] = (dp[i][j] + dp[i - 1][k] * bnm(n - k, n - j)) % mod;
            }
        }
    }
    res = (res - dp[n][n] + mod) % mod;

    cout << res << nl;

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 328 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 328 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 328 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 328 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 328 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 156 ms 1092 KB Output is correct
18 Correct 2 ms 460 KB Output is correct
19 Correct 34 ms 716 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 213 ms 1136 KB Output is correct
22 Correct 23 ms 716 KB Output is correct
23 Correct 2 ms 460 KB Output is correct
24 Correct 44 ms 808 KB Output is correct
25 Correct 30 ms 756 KB Output is correct
26 Correct 60 ms 836 KB Output is correct
27 Correct 296 ms 1220 KB Output is correct
28 Correct 312 ms 1268 KB Output is correct
29 Correct 302 ms 1268 KB Output is correct
30 Correct 310 ms 1276 KB Output is correct
31 Correct 306 ms 1348 KB Output is correct
32 Correct 305 ms 1276 KB Output is correct
33 Correct 312 ms 1224 KB Output is correct
34 Correct 311 ms 1200 KB Output is correct
35 Correct 334 ms 1260 KB Output is correct
36 Correct 325 ms 1348 KB Output is correct
37 Correct 317 ms 1292 KB Output is correct