답안 #749930

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
749930 2023-05-29T01:29:58 Z Trunkty Zapina (COCI20_zapina) C++14
110 / 110
426 ms 3396 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll

int n,mod=1e9+7;
int comb[355][355];
int dp[355][355][2];

int dopow(int x, int y){
    if(y==0){
        return 1;
    }
    int z = dopow(x,y/2);
    if(y%2){
        return (((z*z)%mod)*x)%mod;
    }
    else{
        return (z*z)%mod;
    }
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n;
    for(int i=0;i<=n;i++){
        comb[i][0] = 1;
        for(int j=1;j<=i;j++){
            comb[i][j] = comb[i][j-1]*(i-j+1LL);
            comb[i][j] %= mod;
            comb[i][j] *= dopow(j,mod-2);
            comb[i][j] %= mod;
        }
    }
    dp[0][n][0] = 1;
    for(int i=0;i<=n-1;i++){
        for(int j=0;j<=n;j++){
            for(int k=0;k<=n;k++){
                if(j>=k){
                    dp[i+1][j-k][1] += dp[i][j][1]*comb[j][k];
                    dp[i+1][j-k][1] %= mod;
                    if(k==i+1){
                        dp[i+1][j-k][1] += dp[i][j][0]*comb[j][k];
                        dp[i+1][j-k][1] %= mod;
                    }
                    else{
                        dp[i+1][j-k][0] += dp[i][j][0]*comb[j][k];
                        dp[i+1][j-k][0] %= mod;
                    }
                }
            }
        }
    }
    cout << dp[n][0][1] << "\n";
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 464 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 1 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 464 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 1 ms 468 KB Output is correct
17 Correct 210 ms 2664 KB Output is correct
18 Correct 2 ms 724 KB Output is correct
19 Correct 46 ms 1616 KB Output is correct
20 Correct 1 ms 468 KB Output is correct
21 Correct 272 ms 2764 KB Output is correct
22 Correct 31 ms 1420 KB Output is correct
23 Correct 4 ms 724 KB Output is correct
24 Correct 63 ms 1720 KB Output is correct
25 Correct 42 ms 1512 KB Output is correct
26 Correct 81 ms 1924 KB Output is correct
27 Correct 391 ms 3100 KB Output is correct
28 Correct 387 ms 3140 KB Output is correct
29 Correct 395 ms 3160 KB Output is correct
30 Correct 395 ms 3104 KB Output is correct
31 Correct 396 ms 3276 KB Output is correct
32 Correct 408 ms 3104 KB Output is correct
33 Correct 422 ms 3136 KB Output is correct
34 Correct 411 ms 3192 KB Output is correct
35 Correct 422 ms 3116 KB Output is correct
36 Correct 418 ms 3128 KB Output is correct
37 Correct 426 ms 3396 KB Output is correct