#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
const ll mod = 1000007;
int main()
{
int n;
cin>>n;
vector<int> v;
vector<int> maxi;
vector<int> dp;
for(int i=0;i<n;i++)
{
int a;
cin>>a;
v.push_back(a);
if(maxi.size())
{
maxi.push_back(max(maxi[maxi.size()-1],a));
}
else
maxi.push_back(a);
dp.push_back(i+1);
}
dp.push_back(n+1);
ll brojac=1;
for(int i=n-2;i>=0;i--)
{
brojac+=(v[i]-1)*dp[maxi[i]];
ll broj=dp[1];
for(int j=1;j<=i+1;j++)
{
broj+=dp[j+1];
dp[j]=broj;
}
}
cout<<brojac<<endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
380 KB |
Output is correct |
2 |
Incorrect |
2 ms |
380 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
380 KB |
Output is correct |
2 |
Incorrect |
2 ms |
440 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
476 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
580 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
580 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
644 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
684 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
39 ms |
996 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
14 ms |
996 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
48 ms |
1076 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |