#include <bits/stdc++.h>
#define int long long
using namespace std;
int dp[1000100][3];
int ma[1000100];
vector<int>x;
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int N;
cin >>N;
int i;
for(i=1;i<N;i++)
{
int a;
cin >>a;
x.push_back(a);
}
x.push_back(0);
dp[0][0]=1;
if(x[0]>2)
{
cout <<0;
return 0;
}
for(i=0;i<N;i++)
{
ma[i+1]=max(ma[i],x[i]);
}
for(i=1;i<=N;i++)
{
if(ma[i-1]+1>=x[i-1])
{
dp[i][0]=dp[i-1][0];
dp[i][2]+=dp[i-1][0];
dp[i][1]+=(ma[i-1]-1)*dp[i-1][0];
if(ma[i-1]+1==x[i-1])
{
dp[i][2]-=dp[i-1][0];
dp[i][1]+=dp[i-1][0];
}
}
else
{
if(ma[i-1]+2>=x[i-1])
{
dp[i][2]=dp[i-1][0];
}
else
{
cout <<0;
return 0;
}
}
if(i==1)
{
dp[i][2]+=x[0]!=1;
}
else
{
if(ma[i-2]+1>=x[i-2])
{
dp[i][1]+=dp[i-1][1];
}
if(ma[i-2]+2>=x[i-2])
{
if(ma[i-2]+1<=ma[i-1])
dp[i][1]+=dp[i-1][2];
else
dp[i][2]+=dp[i-1][2];
}
}
}
cout <<dp[N][1]+dp[N][2]+dp[N][0];
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
324 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
324 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
324 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |