답안 #487350

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
487350 2021-11-15T09:33:03 Z LptN21 Zapina (COCI20_zapina) C++14
110 / 110
117 ms 1832 KB
#include <bits/stdc++.h>
using namespace std;
#define fastIO ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define PI acos(-1.0)
#define FF first
#define SS second
#define eps 1e-3
// vector
#define pb push_back
#define sz(v) int((v).size())
#define all(v) (v).begin(), (v).end()
#define lb lower_bound
#define ub upper_bound
// bit
#define CNTBIT(x) __builtin_popcount(x)
#define ODDBIT(x) __builtin_parity(x)
#define MASK(i) (1ll<<(i))
#define BIT(x, i) (((x)>>(i))&1)
#define SUBSET(big, small) (((big)&(small))==(small))
#define MINBIT(x) (x)&(-x)
// typedef
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, int> ii;
typedef pair<int, ii> i3;
/* CODE BELOW */
const int N=350+7, M=17+1, K=243+1;
const int MOD=1e9+7;
const int oo=1e9+7;

int n, m, k, t;

int _dp[N][N][2];
int C[N][N];

int add(int a, int b) {
    a+=b; if(a>=MOD) a-=MOD;
    return a;
}
int mul(int a, int b) {
    return (1LL*a*b)%MOD;
}
void upd(int &a, int b) {
    a+=b; if(a>=MOD) a-=MOD;
}

signed main() {
    //freopen("test.inp", "r", stdin);
    //freopen("test.out", "w", stdout);
    //fastIO;
    scanf("%d", &n);
    _dp[0][0][0]=1, C[0][0]=1;

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

    for(int i=1;i<=n;i++) {
        for(int j=0;j<=n;j++) {
            for(int k=0;k<=j;k++) {
                if(i==k) {
                    upd(_dp[i][j][1], mul(add(_dp[i-1][j-k][0], _dp[i-1][j-k][1]), C[n+k-j][k]));
                } else {
                    upd(_dp[i][j][1], mul(_dp[i-1][j-k][1], C[n+k-j][k]));
                    upd(_dp[i][j][0], mul(_dp[i-1][j-k][0], C[n+k-j][k]));
                }
            }
            //printf("%d %d | %d %d\n", i, j, _dp[i][j][0], _dp[i][j][1]);
        }
    }

    printf("%d", _dp[n][n][1]);

    return 0;
}
/* stuff you should look for
    - int overflow, array bounds
    - special/edge cases (n=1?)
    - do smth instead of nothing and stay organized
    - WRITE STUFF DOWN
    - DONT JUST STICK ON ONE APPROACH
*/

Compilation message

zapina.cpp: In function 'int main()':
zapina.cpp:52:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   52 |     scanf("%d", &n);
      |     ~~~~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 304 KB Output is correct
3 Correct 0 ms 336 KB Output is correct
4 Correct 0 ms 312 KB Output is correct
5 Correct 0 ms 312 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 304 KB Output is correct
3 Correct 0 ms 336 KB Output is correct
4 Correct 0 ms 312 KB Output is correct
5 Correct 0 ms 312 KB Output is correct
6 Correct 0 ms 336 KB Output is correct
7 Correct 0 ms 336 KB Output is correct
8 Correct 0 ms 336 KB Output is correct
9 Correct 0 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 0 ms 336 KB Output is correct
12 Correct 0 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 0 ms 336 KB Output is correct
15 Correct 0 ms 336 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 304 KB Output is correct
3 Correct 0 ms 336 KB Output is correct
4 Correct 0 ms 312 KB Output is correct
5 Correct 0 ms 312 KB Output is correct
6 Correct 0 ms 336 KB Output is correct
7 Correct 0 ms 336 KB Output is correct
8 Correct 0 ms 336 KB Output is correct
9 Correct 0 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 0 ms 336 KB Output is correct
12 Correct 0 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 0 ms 336 KB Output is correct
15 Correct 0 ms 336 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 56 ms 1404 KB Output is correct
18 Correct 1 ms 464 KB Output is correct
19 Correct 13 ms 944 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 77 ms 1444 KB Output is correct
22 Correct 9 ms 848 KB Output is correct
23 Correct 1 ms 464 KB Output is correct
24 Correct 17 ms 976 KB Output is correct
25 Correct 12 ms 976 KB Output is correct
26 Correct 29 ms 1088 KB Output is correct
27 Correct 110 ms 1636 KB Output is correct
28 Correct 110 ms 1648 KB Output is correct
29 Correct 111 ms 1692 KB Output is correct
30 Correct 110 ms 1608 KB Output is correct
31 Correct 115 ms 1740 KB Output is correct
32 Correct 114 ms 1744 KB Output is correct
33 Correct 117 ms 1740 KB Output is correct
34 Correct 114 ms 1692 KB Output is correct
35 Correct 115 ms 1732 KB Output is correct
36 Correct 116 ms 1732 KB Output is correct
37 Correct 117 ms 1832 KB Output is correct