#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fr first
#define sc second
#define clr(a, x) memset(a, x, sizeof(a))
#define dbg(x) cout<<"("<<#x<<"): "<<x<<endl;
#define printvector(arr) for (auto it = arr.begin(); it != arr.end(); ++it) cout<<*it<<" "; cout<<endl;
#define all(v) v.begin(), v.end()
#define lcm(a, b) (a * b)/__gcd(a, b)
#define int long long int
#define printvecpairs(vec) for(auto it: vec) cout<<it.fr<<' '<<it.sc<<endl;
#define endl '\n'
#define float long double
const int MOD = 1e6 + 7;
const int INF = 2e15;
const int MAXN = 1e5 + 5;
int fastexpo(int b, int exp){
if(exp == 0) return 1;
if(exp == 1) return b;
int ans = (fastexpo(b,exp/2) % MOD);
ans *= ans;
ans %= MOD;
if(exp % 2 == 1){
ans *= b;
}
ans %= MOD;
return ans;
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
#ifdef LOCAL
freopen("input.txt", "r", stdin);
#endif
int n;
cin>>n;
int a[n+1];
int prefmx[n+2];
prefmx[0] = 0;
for(int i=1;i<=n;i++){
cin>>a[i];
prefmx[i] = prefmx[i-1];
prefmx[i] = max(prefmx[i], a[i]);
}
int dp[n+2][n+2];
for(int j=1;j<=n;j++) dp[0][j]= 1;
int ans = a[n]%MOD;
for(int i= 1;i<n;i++){
for(int j= 1;j<=n;j++){
dp[i][j] = (((dp[i-1][j]%MOD)*(j%MOD))%MOD + (dp[i-1][j+1]%MOD))%MOD;
}
ans +=((dp[i][prefmx[n-i-1]]%MOD)*(a[n-i]-1+MOD)%MOD)%MOD;
ans %= MOD;
}
cout<<ans%MOD<<endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
0 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
0 ms |
364 KB |
Output is correct |
5 |
Correct |
0 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
2284 KB |
Output is correct |
2 |
Correct |
4 ms |
2284 KB |
Output is correct |
3 |
Correct |
4 ms |
2284 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
8172 KB |
Output is correct |
2 |
Correct |
14 ms |
8300 KB |
Output is correct |
3 |
Correct |
13 ms |
8172 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
117 ms |
65536 KB |
Execution killed with signal 9 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
110 ms |
65540 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
107 ms |
65540 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |