#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ii pair<ll,ll>
#define endl '\n'
const ll inf=1e15;
const ll mod=1e6+7;
const ll maxn=10005;
ll dp[maxn],nxt[maxn],arr[maxn],pref[maxn];
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
ll n,ans=0;
cin>>n;
for (int i=1;i<=n;i++){
cin>>arr[i];
dp[i]=1;
pref[i]=max(arr[i],pref[i-1]);
}
for (int i=n;i>=1;i--){
for (int j=1;j<maxn-1;j++){
nxt[j]=(dp[j]*(j))%mod+dp[j+1];
nxt[j]%=mod;
}
for (int j=1;j<arr[i];j++){
ans+=dp[max<ll>(j,pref[i-1])];
ans%=mod;
}
swap(dp,nxt);
}
cout<<(ans+1)%mod;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
460 KB |
Output is correct |
2 |
Correct |
1 ms |
448 KB |
Output is correct |
3 |
Correct |
1 ms |
460 KB |
Output is correct |
4 |
Correct |
1 ms |
460 KB |
Output is correct |
5 |
Correct |
1 ms |
460 KB |
Output is correct |
6 |
Correct |
1 ms |
460 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
460 KB |
Output is correct |
2 |
Correct |
1 ms |
460 KB |
Output is correct |
3 |
Correct |
1 ms |
460 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
448 KB |
Output is correct |
2 |
Correct |
1 ms |
460 KB |
Output is correct |
3 |
Correct |
1 ms |
460 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
448 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
460 KB |
Output is correct |
2 |
Correct |
4 ms |
484 KB |
Output is correct |
3 |
Correct |
4 ms |
452 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
460 KB |
Output is correct |
2 |
Correct |
19 ms |
460 KB |
Output is correct |
3 |
Correct |
22 ms |
488 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
38 ms |
488 KB |
Output is correct |
2 |
Correct |
38 ms |
480 KB |
Output is correct |
3 |
Correct |
41 ms |
460 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
545 ms |
656 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
181 ms |
556 KB |
Output is correct |
2 |
Correct |
211 ms |
560 KB |
Output is correct |
3 |
Correct |
226 ms |
572 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
374 ms |
652 KB |
Output is correct |
2 |
Correct |
358 ms |
640 KB |
Output is correct |
3 |
Correct |
577 ms |
672 KB |
Output is correct |