답안 #1102277

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1102277 2024-10-18T01:39:40 Z GasmaskChan Zapina (COCI20_zapina) C++17
110 / 110
254 ms 3280 KB
#include <bits/stdc++.h>

using namespace std;
#define int long long

const int MAX = 350 + 5;
const int MOD = 1e9 + 7;

int add(int a, const int &b) {
    a += b;
    while (a >= MOD) a -= MOD;
    while (a < 0) a += MOD;
    return a;
}

int f[MAX][MAX][2], c[MAX][MAX];
int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    //freopen("chiakeo.inp", "r", stdin); freopen("chiakeo.out", "w", stdout);
    int n;
    cin >> n;

    c[0][0] = 1;
    for (int i = 1; i <= n; i++) {
            for (int j = 0; j <= i; j++) {
                c[i][j] = c[i - 1][j];
                if (j) c[i][j] = add(c[i][j], c[i - 1][j - 1]);
            }
    }

    f[0][0][0]  = 1;
    for (int i = 1; i <= n; i++) {
            for (int j = 0; j <= n; j++) {
                    for (int z = 0; z <= j; z++) {
                        if (z == i) {
                                f[i][j][1] = add(f[i][j][1], add(f[i - 1][j - z][1], f[i - 1][j - z][0]) * c[j][z] % MOD);
                        }
                        else {
                                f[i][j][0] = add(f[i][j][0], f[i - 1][j - z][0] * c[j][z] % MOD);
                                f[i][j][1] = add(f[i][j][1], f[i - 1][j - z][1] * c[j][z] % MOD);
                        }
                    }
            }
    }

    cout << f[n][n][1];
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2388 KB Output is correct
2 Correct 1 ms 2388 KB Output is correct
3 Correct 1 ms 2388 KB Output is correct
4 Correct 1 ms 2388 KB Output is correct
5 Correct 1 ms 2388 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2388 KB Output is correct
2 Correct 1 ms 2388 KB Output is correct
3 Correct 1 ms 2388 KB Output is correct
4 Correct 1 ms 2388 KB Output is correct
5 Correct 1 ms 2388 KB Output is correct
6 Correct 1 ms 2388 KB Output is correct
7 Correct 1 ms 2388 KB Output is correct
8 Correct 1 ms 2388 KB Output is correct
9 Correct 1 ms 2388 KB Output is correct
10 Correct 1 ms 2388 KB Output is correct
11 Correct 1 ms 2388 KB Output is correct
12 Correct 1 ms 2388 KB Output is correct
13 Correct 1 ms 2388 KB Output is correct
14 Correct 1 ms 2388 KB Output is correct
15 Correct 1 ms 2388 KB Output is correct
16 Correct 1 ms 2388 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2388 KB Output is correct
2 Correct 1 ms 2388 KB Output is correct
3 Correct 1 ms 2388 KB Output is correct
4 Correct 1 ms 2388 KB Output is correct
5 Correct 1 ms 2388 KB Output is correct
6 Correct 1 ms 2388 KB Output is correct
7 Correct 1 ms 2388 KB Output is correct
8 Correct 1 ms 2388 KB Output is correct
9 Correct 1 ms 2388 KB Output is correct
10 Correct 1 ms 2388 KB Output is correct
11 Correct 1 ms 2388 KB Output is correct
12 Correct 1 ms 2388 KB Output is correct
13 Correct 1 ms 2388 KB Output is correct
14 Correct 1 ms 2388 KB Output is correct
15 Correct 1 ms 2388 KB Output is correct
16 Correct 1 ms 2388 KB Output is correct
17 Correct 125 ms 2896 KB Output is correct
18 Correct 2 ms 2644 KB Output is correct
19 Correct 26 ms 2804 KB Output is correct
20 Correct 1 ms 2388 KB Output is correct
21 Correct 176 ms 2956 KB Output is correct
22 Correct 19 ms 2644 KB Output is correct
23 Correct 3 ms 2812 KB Output is correct
24 Correct 34 ms 2688 KB Output is correct
25 Correct 23 ms 2644 KB Output is correct
26 Correct 47 ms 2696 KB Output is correct
27 Correct 227 ms 3148 KB Output is correct
28 Correct 231 ms 3204 KB Output is correct
29 Correct 243 ms 3152 KB Output is correct
30 Correct 235 ms 3148 KB Output is correct
31 Correct 240 ms 3208 KB Output is correct
32 Correct 238 ms 3152 KB Output is correct
33 Correct 246 ms 3212 KB Output is correct
34 Correct 246 ms 3204 KB Output is correct
35 Correct 246 ms 3280 KB Output is correct
36 Correct 254 ms 3208 KB Output is correct
37 Correct 250 ms 3148 KB Output is correct