# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
350015 | 2021-01-18T21:26:13 Z | arnold518 | Zapina (COCI20_zapina) | C++14 | 179 ms | 2540 KB |
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; const int MAXN = 350; const ll MOD = 1e9+7; ll mypow(ll x, ll y) { if(y==0) return 1; if(y%2) return mypow(x, y-1)*x%MOD; ll t=mypow(x, y/2); return t*t%MOD; } int N; ll ifac[MAXN+10]; ll dp[MAXN+10][MAXN+10][2]; int main() { scanf("%d", &N); ifac[0]=1; for(int i=1; i<=N; i++) ifac[i]=ifac[i-1]*mypow(i, MOD-2)%MOD; 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(j-k==i) { dp[i][j][1]+=dp[i-1][k][1]*ifac[j-k]%MOD; dp[i][j][1]+=dp[i-1][k][0]*ifac[j-k]%MOD; dp[i][j][1]%=MOD; } else { dp[i][j][0]+=dp[i-1][k][0]*ifac[j-k]%MOD; dp[i][j][1]+=dp[i-1][k][1]*ifac[j-k]%MOD; dp[i][j][0]%=MOD; dp[i][j][1]%=MOD; } } } } ll ans=dp[N][N][1]; for(int i=1; i<=N; i++) ans=ans*i%MOD; printf("%lld\n", ans); }
Compilation message
# | 결과 | 실행 시간 | 메모리 | 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 | 364 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 | 364 KB | Output is correct |
6 | Correct | 1 ms | 364 KB | Output is correct |
7 | Correct | 1 ms | 364 KB | Output is correct |
8 | Correct | 1 ms | 364 KB | Output is correct |
9 | Correct | 1 ms | 364 KB | Output is correct |
10 | Correct | 1 ms | 364 KB | Output is correct |
11 | Correct | 1 ms | 364 KB | Output is correct |
12 | Correct | 1 ms | 364 KB | Output is correct |
13 | Correct | 1 ms | 364 KB | Output is correct |
14 | Correct | 1 ms | 364 KB | Output is correct |
15 | Correct | 1 ms | 364 KB | Output is correct |
16 | Correct | 1 ms | 364 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 | 364 KB | Output is correct |
6 | Correct | 1 ms | 364 KB | Output is correct |
7 | Correct | 1 ms | 364 KB | Output is correct |
8 | Correct | 1 ms | 364 KB | Output is correct |
9 | Correct | 1 ms | 364 KB | Output is correct |
10 | Correct | 1 ms | 364 KB | Output is correct |
11 | Correct | 1 ms | 364 KB | Output is correct |
12 | Correct | 1 ms | 364 KB | Output is correct |
13 | Correct | 1 ms | 364 KB | Output is correct |
14 | Correct | 1 ms | 364 KB | Output is correct |
15 | Correct | 1 ms | 364 KB | Output is correct |
16 | Correct | 1 ms | 364 KB | Output is correct |
17 | Correct | 82 ms | 1900 KB | Output is correct |
18 | Correct | 1 ms | 620 KB | Output is correct |
19 | Correct | 18 ms | 1260 KB | Output is correct |
20 | Correct | 1 ms | 492 KB | Output is correct |
21 | Correct | 109 ms | 2028 KB | Output is correct |
22 | Correct | 13 ms | 1132 KB | Output is correct |
23 | Correct | 2 ms | 636 KB | Output is correct |
24 | Correct | 24 ms | 1388 KB | Output is correct |
25 | Correct | 16 ms | 1260 KB | Output is correct |
26 | Correct | 32 ms | 1388 KB | Output is correct |
27 | Correct | 154 ms | 2284 KB | Output is correct |
28 | Correct | 155 ms | 2284 KB | Output is correct |
29 | Correct | 158 ms | 2284 KB | Output is correct |
30 | Correct | 158 ms | 2540 KB | Output is correct |
31 | Correct | 160 ms | 2304 KB | Output is correct |
32 | Correct | 164 ms | 2388 KB | Output is correct |
33 | Correct | 164 ms | 2284 KB | Output is correct |
34 | Correct | 163 ms | 2284 KB | Output is correct |
35 | Correct | 166 ms | 2540 KB | Output is correct |
36 | Correct | 179 ms | 2284 KB | Output is correct |
37 | Correct | 171 ms | 2284 KB | Output is correct |