답안 #319570

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
319570 2020-11-05T14:11:01 Z BeanZ Zapina (COCI20_zapina) C++14
110 / 110
199 ms 3428 KB
// I_Love_LPL
#include <bits/stdc++.h>
using namespace std;
//#define task "A"
#define ll long long
#define endl '\n'
const int N = 355;
const int mod = 1e9 + 7;
const int lg = 18;
ll dp[N][N][2];
ll fact[N], f[N][N];
ll binpow(ll u, ll p){
    if (p == 0) return 1;
    if (p == 1) return u;
    ll t = binpow(u, p / 2);
    if (p & 1) return t * t % mod * u % mod;
    return t * t % mod;
}
ll nCk(ll n, ll k){
    return fact[n] * binpow(fact[n - k], mod - 2) % mod * binpow(fact[k], mod - 2) % mod;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    if (fopen(".inp", "r")){
        freopen(".inp", "r", stdin);
        freopen(".out", "w", stdout);
    }
    ll n;
    cin >> n;
    fact[0] = 1;
    for (int i = 1; i <= n; i++){
        fact[i] = fact[i - 1] * i % mod;
    }
    for (int i = 0; i <= n; i++){
        for (int j = 0; j <= i; j++){
            f[i][j] = nCk(i, j);
        }
    }
    dp[0][0][0] = 1;
    for (int i = 1; i <= n; i++){
        for (int j = 0; j <= n; j++){
            for (int k = 0; k <= j; k++){
                if (k == i){
                    dp[i][j][1] = (dp[i][j][1] + dp[i - 1][j - k][0] * f[n - (j - k)][k]) % mod;
                    dp[i][j][1] = (dp[i][j][1] + dp[i - 1][j - k][1] * f[n - (j - k)][k]) % mod;
                } else {
                    dp[i][j][0] = (dp[i][j][0] + dp[i - 1][j - k][0] * f[n - (j - k)][k]) % mod;
                    dp[i][j][1] = (dp[i][j][1] + dp[i - 1][j - k][1] * f[n - (j - k)][k]) % mod;
                }
            }
        }
    }
    cout << dp[n][n][1];
}
/*
*/

Compilation message

zapina.cpp: In function 'int main()':
zapina.cpp:26:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   26 |         freopen(".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~
zapina.cpp:27:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   27 |         freopen(".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 492 KB Output is correct
8 Correct 1 ms 492 KB Output is correct
9 Correct 1 ms 492 KB Output is correct
10 Correct 1 ms 492 KB Output is correct
11 Correct 1 ms 492 KB Output is correct
12 Correct 1 ms 492 KB Output is correct
13 Correct 1 ms 492 KB Output is correct
14 Correct 1 ms 512 KB Output is correct
15 Correct 1 ms 528 KB Output is correct
16 Correct 1 ms 492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 492 KB Output is correct
8 Correct 1 ms 492 KB Output is correct
9 Correct 1 ms 492 KB Output is correct
10 Correct 1 ms 492 KB Output is correct
11 Correct 1 ms 492 KB Output is correct
12 Correct 1 ms 492 KB Output is correct
13 Correct 1 ms 492 KB Output is correct
14 Correct 1 ms 512 KB Output is correct
15 Correct 1 ms 528 KB Output is correct
16 Correct 1 ms 492 KB Output is correct
17 Correct 100 ms 2788 KB Output is correct
18 Correct 2 ms 876 KB Output is correct
19 Correct 25 ms 1764 KB Output is correct
20 Correct 2 ms 492 KB Output is correct
21 Correct 130 ms 2916 KB Output is correct
22 Correct 18 ms 1516 KB Output is correct
23 Correct 3 ms 876 KB Output is correct
24 Correct 31 ms 1900 KB Output is correct
25 Correct 22 ms 1644 KB Output is correct
26 Correct 42 ms 2296 KB Output is correct
27 Correct 179 ms 3172 KB Output is correct
28 Correct 182 ms 3172 KB Output is correct
29 Correct 184 ms 3172 KB Output is correct
30 Correct 186 ms 3176 KB Output is correct
31 Correct 198 ms 3300 KB Output is correct
32 Correct 199 ms 3172 KB Output is correct
33 Correct 189 ms 3172 KB Output is correct
34 Correct 190 ms 3176 KB Output is correct
35 Correct 191 ms 3300 KB Output is correct
36 Correct 199 ms 3428 KB Output is correct
37 Correct 197 ms 3284 KB Output is correct