#include <bits/stdc++.h>
using namespace std;
const int mod=1000000007;
long long lgput (long long a, long long exp)
{
long long rz=1;
while(exp)
{
if(exp&1)
{
exp^=1;
rz=(rz*1LL*a)%mod;
}
else
{
exp>>=1;
a=(a*1LL*a)%mod;
}
}
return rz;
}
int inv2;
long long cmb2 (int n)
{
if(n<2)
return 0;
return n*(n-1LL)%mod*1LL*inv2%mod;
}
int v[605];
int dp[605][605][2][3][2]; /// 0=NU ; 1=URMEAZA ; 2=POATE
int main()
{
ios_base::sync_with_stdio(false);
dp[0][0][0][0][0]=1;
inv2=lgput(2,mod-2);
int n;
cin>>n;
for(int i=1;i<=n;++i)
{
cin>>v[i];
v[i]-=i;
}
for(int prefX=0;prefX<=n;++prefX)
{
int ci=prefX%2;
int ni=1-ci;
for(int i=0;i<=n;++i)
for(int j=0;j<=n;++j)
for(int b=0;b<=2;++b)
for(int c=0;c<=1;++c)
dp[i][j][ni][b][c]=0;
for(int _=0;_<=n;++_)
{
if(_ > prefX)
dp[_][0][ni][2][0] = ( dp[_][0][ni][2][0] + dp[_][0][ci][2][0]*1LL*(_ - prefX)%mod )%mod;
dp[_][0][ci][0][0] = (dp[_][0][ci][0][0] + dp[_][0][ci][2][0])%mod;
}
for(int _=0;_<=n;++_)
for(int x=0;x<=n;++x)
{
++x;
dp[_][x-1][ci][0][0] = (dp[_][x-1][ci][0][0] + dp[_][x][ci][0][1])%mod;
if(x>=2)
dp[_][x-1][ci][1][0] = (dp[_][x-1][ci][1][0] + dp[_][x][ci][1][1])%mod;
else
dp[_][x-1][ni][2][0] = (dp[_][x-1][ni][2][0] + dp[_][x][ci][1][1])%mod;
--x;
int dpc = dp[_][x][ci][0][0];
int cate=v[prefX+1] - _;
dp[_+2][x+0][ci][0][1] = (dp[_+2][x+0][ci][0][1] + dpc*1LL*cmb2(cate)%mod)%mod;
dp[_+1][x+1][ci][0][1] = (dp[_+1][x+1][ci][0][1] + dpc*1LL*cate%mod)%mod;
dp[_+1][x+1][ci][1][1] = (dp[_+1][x+1][ci][1][1] + dpc*1LL*cate%mod)%mod;
dp[_+0][x+2][ci][0][1] = (dp[_+0][x+2][ci][0][1] + dpc*1LL*inv2%mod)%mod;
dp[_+0][x+2][ci][1][1] = (dp[_+0][x+2][ci][1][1] + dpc)%mod;
dpc = dp[_][x][ci][1][0];
dp[_+2][x+0][ci][1][1] = (dp[_+2][x+0][ci][1][1] + dpc*1LL*cmb2(cate)%mod)%mod;
dp[_+1][x+1][ci][1][1] = (dp[_+1][x+1][ci][1][1] + dpc*1LL*cate%mod)%mod;
dp[_+0][x+2][ci][1][1] = (dp[_+0][x+2][ci][1][1] + dpc*1LL*inv2%mod)%mod;
}
}
cout<<dp[n][0][n&1][0][0];
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
328 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
328 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
328 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
328 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
6 ms |
712 KB |
Output is correct |
12 |
Correct |
9 ms |
724 KB |
Output is correct |
13 |
Correct |
6 ms |
716 KB |
Output is correct |
14 |
Correct |
6 ms |
724 KB |
Output is correct |
15 |
Correct |
6 ms |
724 KB |
Output is correct |
16 |
Correct |
6 ms |
784 KB |
Output is correct |
17 |
Correct |
7 ms |
724 KB |
Output is correct |
18 |
Correct |
7 ms |
724 KB |
Output is correct |
19 |
Correct |
7 ms |
724 KB |
Output is correct |
20 |
Correct |
7 ms |
724 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
328 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
328 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
6 ms |
712 KB |
Output is correct |
12 |
Correct |
9 ms |
724 KB |
Output is correct |
13 |
Correct |
6 ms |
716 KB |
Output is correct |
14 |
Correct |
6 ms |
724 KB |
Output is correct |
15 |
Correct |
6 ms |
724 KB |
Output is correct |
16 |
Correct |
6 ms |
784 KB |
Output is correct |
17 |
Correct |
7 ms |
724 KB |
Output is correct |
18 |
Correct |
7 ms |
724 KB |
Output is correct |
19 |
Correct |
7 ms |
724 KB |
Output is correct |
20 |
Correct |
7 ms |
724 KB |
Output is correct |
21 |
Execution timed out |
6089 ms |
17424 KB |
Time limit exceeded |
22 |
Halted |
0 ms |
0 KB |
- |