답안 #957761

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
957761 2024-04-04T09:22:24 Z ArashJafariyan Zapina (COCI20_zapina) C++17
110 / 110
83 ms 1468 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 80 ms 1380 KB Output is correct
3 Correct 79 ms 1360 KB Output is correct
4 Correct 80 ms 1364 KB Output is correct
5 Correct 79 ms 1360 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 79 ms 1360 KB Output is correct
2 Correct 80 ms 1380 KB Output is correct
3 Correct 79 ms 1360 KB Output is correct
4 Correct 80 ms 1364 KB Output is correct
5 Correct 79 ms 1360 KB Output is correct
6 Correct 80 ms 1244 KB Output is correct
7 Correct 79 ms 1332 KB Output is correct
8 Correct 79 ms 1324 KB Output is correct
9 Correct 80 ms 1304 KB Output is correct
10 Correct 83 ms 1300 KB Output is correct
11 Correct 81 ms 1352 KB Output is correct
12 Correct 80 ms 1360 KB Output is correct
13 Correct 79 ms 1360 KB Output is correct
14 Correct 79 ms 1340 KB Output is correct
15 Correct 79 ms 1296 KB Output is correct
16 Correct 79 ms 1168 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 79 ms 1360 KB Output is correct
2 Correct 80 ms 1380 KB Output is correct
3 Correct 79 ms 1360 KB Output is correct
4 Correct 80 ms 1364 KB Output is correct
5 Correct 79 ms 1360 KB Output is correct
6 Correct 80 ms 1244 KB Output is correct
7 Correct 79 ms 1332 KB Output is correct
8 Correct 79 ms 1324 KB Output is correct
9 Correct 80 ms 1304 KB Output is correct
10 Correct 83 ms 1300 KB Output is correct
11 Correct 81 ms 1352 KB Output is correct
12 Correct 80 ms 1360 KB Output is correct
13 Correct 79 ms 1360 KB Output is correct
14 Correct 79 ms 1340 KB Output is correct
15 Correct 79 ms 1296 KB Output is correct
16 Correct 79 ms 1168 KB Output is correct
17 Correct 80 ms 1228 KB Output is correct
18 Correct 79 ms 1364 KB Output is correct
19 Correct 79 ms 1420 KB Output is correct
20 Correct 79 ms 1244 KB Output is correct
21 Correct 79 ms 1284 KB Output is correct
22 Correct 79 ms 1328 KB Output is correct
23 Correct 82 ms 1468 KB Output is correct
24 Correct 79 ms 1352 KB Output is correct
25 Correct 79 ms 1360 KB Output is correct
26 Correct 79 ms 1360 KB Output is correct
27 Correct 80 ms 1400 KB Output is correct
28 Correct 79 ms 1364 KB Output is correct
29 Correct 79 ms 1368 KB Output is correct
30 Correct 79 ms 1184 KB Output is correct
31 Correct 80 ms 1360 KB Output is correct
32 Correct 81 ms 1468 KB Output is correct
33 Correct 79 ms 1360 KB Output is correct
34 Correct 80 ms 1364 KB Output is correct
35 Correct 79 ms 1368 KB Output is correct
36 Correct 79 ms 1320 KB Output is correct
37 Correct 79 ms 1360 KB Output is correct