This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
const ll mod = 1000007;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie();
cout.tie();
int n;
cin>>n;
vector<ll> dp(n+1,0);
dp[1]=2;
ll broj=2;
vector<ll> v;
ll brojac=0;
for(int i=0;i<n;i++)
{
ll a;
cin>>a;
v.push_back(a);
}
for(int i=2;i<=n;i++)
{
broj++;
dp[i]=dp[i-1]+broj;
dp[i]%=mod;
broj%=mod;
}
for(int i=n-1;i>=1;i--)
{
brojac+=dp[v[i-1]-1];
brojac%=mod;
dp[1]=dp[1]+dp[2];
dp[1]%=mod;
broj=dp[1];
for(int j=2;j<i;j++)
{
broj+=dp[j+1];
broj%=mod;
dp[j]=0;
dp[j]=broj;
dp[j]%=mod;
}
}
brojac+=v[n-1];
brojac%=mod;
cout<<brojac<<endl;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |