#include<bits/stdc++.h>
#define pb push_back
#define pli pair<int,int>
#define fi first
#define se second
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;
using ll=int;
const ll maxN=1e4+10;
const ll inf=1e9;
const ll mod=1e6+7;
void add(ll &x,ll y)
{
x+=y;
if(x>=mod) x-=mod;
}
ll a[maxN],dp[2][maxN][2],n;
void solve()
{
cin >> n;
for(int i=1;i<=n;i++)
{
cin >> a[i];
}
dp[0][0][0]=1;
for(int i=0;i<n;i++)
{
for(int j=1;j<=i+1;j++)
{
dp[(i+1)&1][j][0]=dp[(i+1)&1][j][1]=0;
}
ll st;
if(i==0) st=0;
else st=1;
for(int j=st;j<=i;j++)
{
if(a[i+1]<=j+1)
{
ll x;
if(a[i+1]==j+1) x=j+1;
else x=j;
add(dp[(i+1)&1][x][0],dp[i&1][j][0]);
}
ll cc=min(a[i+1]-1,j);
add(dp[(i+1)&1][j][1],cc*dp[i&1][j][0]%mod);
if(j+1<a[i+1])
{
add(dp[(i+1)&1][j+1][1],dp[i&1][j][0]);
}
add(dp[(i+1)&1][j][1],j*dp[i&1][j][1]%mod);
add(dp[(i+1)&1][j+1][1],dp[i&1][j][1]);
}
}
ll ans=0;
for(int i=1;i<=n;i++)
{
add(ans,dp[n&1][i][0]);
add(ans,dp[n&1][i][1]);
}
cout << ans;
}
int main()
{
fastio
//freopen(TASKNAME".INP","r",stdin);
//freopen(TASKNAME".OUT","w",stdout);
solve();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
600 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
344 KB |
Output is correct |
2 |
Correct |
2 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
600 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
344 KB |
Output is correct |
2 |
Correct |
6 ms |
344 KB |
Output is correct |
3 |
Correct |
5 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
328 ms |
544 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
111 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
378 ms |
628 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |