답안 #957635

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
957635 2024-04-04T06:37:58 Z vjudge1 Zapina (COCI20_zapina) C++17
110 / 110
91 ms 1624 KB
#include <bits/stdc++.h>
using namespace std;

#ifdef DEBUG
#include "debug.h"
#else
#define debug(...) 0
#endif

#define pb push_back
#define ll long long
#define i2 array<int, 2>
#define SZ(x) (int) (x).size()

const int N = 350 + 4, M = 1e9 + 7;

int power(int a, int b) {
    int ret = 1;
    while (b) {
        if (b & 1)
            ret = 1LL * ret * a % M;
        b >>= 1;
        a = 1LL * a * a % M;
    }
    return ret;
}

int n, c[N][N], dp[N][N];

void solve() {
    for (int i = 0; i < N; i++) {
        for (int j = 0; j <= i; j++) {
            if (!j || !i)
                c[i][j] = 1;
            else
                c[i][j] = (c[i - 1][j] + c[i - 1][j - 1]) % M;
        }
    }
    cin >> n;
    for (int i = 0; i < N; i++)
        if (i != 1)
            dp[1][i] = 1;
    for (int i = 2; i < N; i++) {
        for (int j = 0; j < N; j++) {
            for (int k = 0; k <= j; k++) {
                if (k != i) {
                    int add = 1LL * c[j][k] * dp[i - 1][j - k] % M;
                    // if (i == 2 && j == 2 && k == 0)
                    dp[i][j] = (dp[i][j] + add) % M;
                }
            }
        }
    }
    cout << (power(n, n) - dp[n][n] + M) % M;
}

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

    int t = 1;
    // cin >> t;
    while (t--) {
        solve();
    }

    return 0;
}

# 결과 실행 시간 메모리 Grader output
1 Correct 79 ms 1360 KB Output is correct
2 Correct 79 ms 1336 KB Output is correct
3 Correct 81 ms 1256 KB Output is correct
4 Correct 84 ms 1168 KB Output is correct
5 Correct 80 ms 1164 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 79 ms 1360 KB Output is correct
2 Correct 79 ms 1336 KB Output is correct
3 Correct 81 ms 1256 KB Output is correct
4 Correct 84 ms 1168 KB Output is correct
5 Correct 80 ms 1164 KB Output is correct
6 Correct 81 ms 1304 KB Output is correct
7 Correct 82 ms 1304 KB Output is correct
8 Correct 83 ms 1572 KB Output is correct
9 Correct 82 ms 1164 KB Output is correct
10 Correct 79 ms 1272 KB Output is correct
11 Correct 80 ms 1412 KB Output is correct
12 Correct 81 ms 1288 KB Output is correct
13 Correct 81 ms 1412 KB Output is correct
14 Correct 80 ms 1256 KB Output is correct
15 Correct 83 ms 1360 KB Output is correct
16 Correct 91 ms 1364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 79 ms 1360 KB Output is correct
2 Correct 79 ms 1336 KB Output is correct
3 Correct 81 ms 1256 KB Output is correct
4 Correct 84 ms 1168 KB Output is correct
5 Correct 80 ms 1164 KB Output is correct
6 Correct 81 ms 1304 KB Output is correct
7 Correct 82 ms 1304 KB Output is correct
8 Correct 83 ms 1572 KB Output is correct
9 Correct 82 ms 1164 KB Output is correct
10 Correct 79 ms 1272 KB Output is correct
11 Correct 80 ms 1412 KB Output is correct
12 Correct 81 ms 1288 KB Output is correct
13 Correct 81 ms 1412 KB Output is correct
14 Correct 80 ms 1256 KB Output is correct
15 Correct 83 ms 1360 KB Output is correct
16 Correct 91 ms 1364 KB Output is correct
17 Correct 81 ms 1360 KB Output is correct
18 Correct 86 ms 1360 KB Output is correct
19 Correct 79 ms 1396 KB Output is correct
20 Correct 79 ms 1364 KB Output is correct
21 Correct 79 ms 1336 KB Output is correct
22 Correct 79 ms 1212 KB Output is correct
23 Correct 79 ms 1624 KB Output is correct
24 Correct 79 ms 1360 KB Output is correct
25 Correct 79 ms 1364 KB Output is correct
26 Correct 85 ms 1364 KB Output is correct
27 Correct 79 ms 1344 KB Output is correct
28 Correct 79 ms 1364 KB Output is correct
29 Correct 79 ms 1396 KB Output is correct
30 Correct 79 ms 1248 KB Output is correct
31 Correct 79 ms 1168 KB Output is correct
32 Correct 81 ms 1360 KB Output is correct
33 Correct 82 ms 1352 KB Output is correct
34 Correct 81 ms 1360 KB Output is correct
35 Correct 79 ms 1340 KB Output is correct
36 Correct 79 ms 1332 KB Output is correct
37 Correct 80 ms 1380 KB Output is correct