답안 #442918

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
442918 2021-07-09T10:53:20 Z colossal_pepe Zapina (COCI20_zapina) C++17
110 / 110
157 ms 2272 KB
#include <iostream>
#include <cstring>
using namespace std;

typedef long long ll;

const ll MOD = 1000000007;

ll n, C[355][355], dp[355][355];

void fillC() {
    C[0][0] = 1;
    for (int i = 1; i < 355; i++) {
        C[i][0] = C[i][i] = 1;
        for (int j = 1; j < 355; j++) {
            C[i][j] = C[i - 1][j - 1] + C[i - 1][j];
            C[i][j] %= MOD;
        }
    }
}

void setup() {
    memset(dp, -1, sizeof(dp));
    for (int i = n + 1; i < 355; i++) {
        dp[i][0] = 1;
        for (int j = 1; j < 355; j++) {
            dp[i][j] = 0;
        }
    }
}

ll modMinus(ll a, ll b) {
    ll ans = a%MOD - b%MOD;
    if (ans < 0) ans += MOD;
    return ans;
}

ll ways(ll x) {
    ll ans = 1;
    for (int i = 0; i < x; i++) {
        ans *= x;
        ans %= MOD;
    }
    return ans;
}

ll badWays(ll p, ll t) {
    if (dp[p][t] != -1) return dp[p][t];
    dp[p][t] = 0;
    for (int i = 0; i <= t; i++) {
        if (i == p) continue;
        dp[p][t] += C[t][i] * badWays(p + 1, t - i);
        dp[p][t] %= MOD;
    }
    return dp[p][t];
}

int main() {
    fillC();
    cin >> n;
    setup();
    cout << modMinus(ways(n), badWays(1, n)) << endl;
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2252 KB Output is correct
2 Correct 2 ms 2252 KB Output is correct
3 Correct 2 ms 2252 KB Output is correct
4 Correct 2 ms 2252 KB Output is correct
5 Correct 2 ms 2252 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2252 KB Output is correct
2 Correct 2 ms 2252 KB Output is correct
3 Correct 2 ms 2252 KB Output is correct
4 Correct 2 ms 2252 KB Output is correct
5 Correct 2 ms 2252 KB Output is correct
6 Correct 2 ms 2252 KB Output is correct
7 Correct 2 ms 2252 KB Output is correct
8 Correct 2 ms 2252 KB Output is correct
9 Correct 2 ms 2252 KB Output is correct
10 Correct 2 ms 2252 KB Output is correct
11 Correct 2 ms 2252 KB Output is correct
12 Correct 2 ms 2252 KB Output is correct
13 Correct 2 ms 2252 KB Output is correct
14 Correct 2 ms 2252 KB Output is correct
15 Correct 2 ms 2252 KB Output is correct
16 Correct 2 ms 2252 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2252 KB Output is correct
2 Correct 2 ms 2252 KB Output is correct
3 Correct 2 ms 2252 KB Output is correct
4 Correct 2 ms 2252 KB Output is correct
5 Correct 2 ms 2252 KB Output is correct
6 Correct 2 ms 2252 KB Output is correct
7 Correct 2 ms 2252 KB Output is correct
8 Correct 2 ms 2252 KB Output is correct
9 Correct 2 ms 2252 KB Output is correct
10 Correct 2 ms 2252 KB Output is correct
11 Correct 2 ms 2252 KB Output is correct
12 Correct 2 ms 2252 KB Output is correct
13 Correct 2 ms 2252 KB Output is correct
14 Correct 2 ms 2252 KB Output is correct
15 Correct 2 ms 2252 KB Output is correct
16 Correct 2 ms 2252 KB Output is correct
17 Correct 76 ms 2252 KB Output is correct
18 Correct 2 ms 2252 KB Output is correct
19 Correct 17 ms 2268 KB Output is correct
20 Correct 2 ms 2252 KB Output is correct
21 Correct 110 ms 2260 KB Output is correct
22 Correct 14 ms 2252 KB Output is correct
23 Correct 2 ms 2252 KB Output is correct
24 Correct 23 ms 2272 KB Output is correct
25 Correct 16 ms 2272 KB Output is correct
26 Correct 32 ms 2252 KB Output is correct
27 Correct 146 ms 2272 KB Output is correct
28 Correct 146 ms 2252 KB Output is correct
29 Correct 151 ms 2268 KB Output is correct
30 Correct 148 ms 2252 KB Output is correct
31 Correct 151 ms 2264 KB Output is correct
32 Correct 155 ms 2252 KB Output is correct
33 Correct 151 ms 2268 KB Output is correct
34 Correct 155 ms 2264 KB Output is correct
35 Correct 155 ms 2252 KB Output is correct
36 Correct 157 ms 2252 KB Output is correct
37 Correct 157 ms 2268 KB Output is correct