#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N = 1e4 + 10;
const ll mod = 1e6 + 7;
ll n, ans, a[N], dp[2][N];
int main(){
cin >> n;
ll mx = 0;
vector<pair<ll, ll>> vec;
vector<ll> vals;
for (ll i=1; i<=n; i++){
cin >> a[i];
if (i < n)
vec.push_back({i + 1, mx + 1});
mx = max(mx, a[i]);
}
vec.push_back({n, a[n]});
for (ll i=n; i>0; i--){
for (ll j=1; j<=n; j++){
if (i==n){
dp[i % 2][j] = dp[i % 2][j-1] + 1;
continue;
}
dp[i % 2][j] = (j-1) * dp[(i+1) % 2][j] + dp[(i+1) % 2][j+1];
dp[i % 2][j] %= mod;
}
while (vec.size() and vec.back().first == i){
vals.push_back(dp[i % 2][vec.back().second]);
vec.pop_back();
}
}
reverse(vals.begin(), vals.end());
mx = 0;
for (ll i=1; i<n; i++){
ans += (a[i] - 1) * vals.back();
vals.pop_back();
ans %= mod;
mx = max(mx, a[i]);
}
ans += vals.back();
ans %= mod;
cout << ans << endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
336 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
212 ms |
952 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
51 ms |
592 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
212 ms |
964 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |