# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
282929 |
2020-08-25T07:27:19 Z |
AMO5 |
Zapina (COCI20_zapina) |
C++17 |
|
180 ms |
3832 KB |
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define eb emplace_back
#define mt make_tuple
#define all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
#define MOD 1000000007
typedef long long ll;
typedef pair <int, int> ii;
typedef pair <ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef long double ld;
const ll INF=63;
const int mxn=400;
bool DEBUG=0;
ll choose[mxn][mxn],dp[mxn][mxn][2];
void jia(ll &a, ll b){
a=1ll*(a+b)%MOD;
}
ll mul(ll a, ll b){
return 1ll*a*b%MOD;
}
ll modpow(ll a, ll b){
ll res = 1ll;
while(b){
if(b&1)jia(res,a);
mul(a,a);
b/=2;
}
return res%MOD;
}
void init(){
for(int i=0; i<mxn; i++){
choose[i][0]=1ll;
for(int j=1; j<=i; j++){
choose[i][j]=(choose[i-1][j-1]+choose[i-1][j])%MOD;
}
}
}
int n;
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0);
//freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
init();
cin>>n;
dp[1][0][0]=dp[1][1][1]=1;
for(int i=2; i<=n; i++)
dp[1][i][0]=1;
for(int i=2; i<=n; i++){
for(int j=0; j<=n; j++){
for(int k=0; k<=j; k++){
if(k==i){
jia(dp[i][j][1],mul(dp[i-1][j-k][0],choose[j][k]));
jia(dp[i][j][1],mul(dp[i-1][j-k][1],choose[j][k]));
}else{
jia(dp[i][j][0],mul(dp[i-1][j-k][0],choose[j][k]));
jia(dp[i][j][1],mul(dp[i-1][j-k][1],choose[j][k]));
}
}
}
}
cout<<dp[n][n][1];
}
// READ & UNDERSTAND
// ll, int overflow, array bounds, memset(0)
// special cases (n=1?), n+1 (1-index)
// do smth instead of nothing & stay organized
// WRITE STUFF DOWN
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1536 KB |
Output is correct |
2 |
Correct |
1 ms |
1664 KB |
Output is correct |
3 |
Correct |
1 ms |
1536 KB |
Output is correct |
4 |
Correct |
1 ms |
1664 KB |
Output is correct |
5 |
Correct |
2 ms |
1664 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1536 KB |
Output is correct |
2 |
Correct |
1 ms |
1664 KB |
Output is correct |
3 |
Correct |
1 ms |
1536 KB |
Output is correct |
4 |
Correct |
1 ms |
1664 KB |
Output is correct |
5 |
Correct |
2 ms |
1664 KB |
Output is correct |
6 |
Correct |
2 ms |
1664 KB |
Output is correct |
7 |
Correct |
1 ms |
1664 KB |
Output is correct |
8 |
Correct |
2 ms |
1664 KB |
Output is correct |
9 |
Correct |
1 ms |
1664 KB |
Output is correct |
10 |
Correct |
1 ms |
1664 KB |
Output is correct |
11 |
Correct |
1 ms |
1664 KB |
Output is correct |
12 |
Correct |
2 ms |
1664 KB |
Output is correct |
13 |
Correct |
1 ms |
1664 KB |
Output is correct |
14 |
Correct |
2 ms |
1664 KB |
Output is correct |
15 |
Correct |
1 ms |
1664 KB |
Output is correct |
16 |
Correct |
1 ms |
1664 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1536 KB |
Output is correct |
2 |
Correct |
1 ms |
1664 KB |
Output is correct |
3 |
Correct |
1 ms |
1536 KB |
Output is correct |
4 |
Correct |
1 ms |
1664 KB |
Output is correct |
5 |
Correct |
2 ms |
1664 KB |
Output is correct |
6 |
Correct |
2 ms |
1664 KB |
Output is correct |
7 |
Correct |
1 ms |
1664 KB |
Output is correct |
8 |
Correct |
2 ms |
1664 KB |
Output is correct |
9 |
Correct |
1 ms |
1664 KB |
Output is correct |
10 |
Correct |
1 ms |
1664 KB |
Output is correct |
11 |
Correct |
1 ms |
1664 KB |
Output is correct |
12 |
Correct |
2 ms |
1664 KB |
Output is correct |
13 |
Correct |
1 ms |
1664 KB |
Output is correct |
14 |
Correct |
2 ms |
1664 KB |
Output is correct |
15 |
Correct |
1 ms |
1664 KB |
Output is correct |
16 |
Correct |
1 ms |
1664 KB |
Output is correct |
17 |
Correct |
99 ms |
3320 KB |
Output is correct |
18 |
Correct |
4 ms |
1792 KB |
Output is correct |
19 |
Correct |
23 ms |
2560 KB |
Output is correct |
20 |
Correct |
2 ms |
1664 KB |
Output is correct |
21 |
Correct |
122 ms |
3448 KB |
Output is correct |
22 |
Correct |
14 ms |
2432 KB |
Output is correct |
23 |
Correct |
3 ms |
1920 KB |
Output is correct |
24 |
Correct |
31 ms |
2680 KB |
Output is correct |
25 |
Correct |
22 ms |
2528 KB |
Output is correct |
26 |
Correct |
34 ms |
2808 KB |
Output is correct |
27 |
Correct |
171 ms |
3704 KB |
Output is correct |
28 |
Correct |
176 ms |
3696 KB |
Output is correct |
29 |
Correct |
173 ms |
3772 KB |
Output is correct |
30 |
Correct |
176 ms |
3768 KB |
Output is correct |
31 |
Correct |
178 ms |
3704 KB |
Output is correct |
32 |
Correct |
179 ms |
3704 KB |
Output is correct |
33 |
Correct |
179 ms |
3704 KB |
Output is correct |
34 |
Correct |
178 ms |
3704 KB |
Output is correct |
35 |
Correct |
180 ms |
3704 KB |
Output is correct |
36 |
Correct |
176 ms |
3808 KB |
Output is correct |
37 |
Correct |
175 ms |
3832 KB |
Output is correct |