//HAPPY BIRTHDAY!!!
#include <bits/stdc++.h>
#define int long long
using namespace std;
typedef pair<int,int> ii;
int mod = 1000007;
int ans = 0;
int dp[10005];
signed main(){
ios_base::sync_with_stdio(false); cin.tie(0);
int n; cin >> n;
int arr[n]; for(int i = 0;i < n;i++) cin >> arr[i];
int pre[n];
pre[0] = arr[0];
for(int i = 1;i < n;i++){
pre[i] = max(pre[i-1], arr[i]);
}
for(int i = 1;i <= n;i++) dp[i] = 1;
for(int p = n-1;p >= 0;p--){
for(int v = 1;v < arr[p];v++){
int maxValue = v;
if(p != 0) maxValue = max(maxValue, pre[p-1]);
ans += dp[maxValue];
//cout << p << " " << v << " " << dp[maxValue] << "\n";
ans %= mod;
}
for(int i = 1;i <= n;i++){
dp[i] = dp[i] * i + dp[i+1];
dp[i] %= mod;
}
//for(int i = 1;i <= n;i++) cout << dp[i] << " ";
//cout << "\n";
}
ans++; ans %= mod;
cout << ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
256 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
384 KB |
Output is correct |
2 |
Correct |
6 ms |
384 KB |
Output is correct |
3 |
Correct |
7 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
512 KB |
Output is correct |
2 |
Correct |
11 ms |
384 KB |
Output is correct |
3 |
Correct |
14 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
968 ms |
640 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
181 ms |
384 KB |
Output is correct |
2 |
Correct |
184 ms |
632 KB |
Output is correct |
3 |
Correct |
248 ms |
632 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
729 ms |
632 KB |
Output is correct |
2 |
Correct |
735 ms |
640 KB |
Output is correct |
3 |
Correct |
994 ms |
760 KB |
Output is correct |