#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
#define pb push_back
#define pii pair < ll , ll >
#define F first
#define S second
#define endl '\n'
#define int long long
#define sync ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#define kill(x) return cout<<x<<'\n', 0;
using namespace std;
const int N=1e4+100;
ll dp[2][N];
ll a[N];
ll mod=1e6+7;
ll par[N];
int32_t main(){
sync;
ll n;
cin >> n;
for (int i=1;i<=n;i++){
cin >> a[i];
}
for (int i=1;i<=n;i++){
par[i]=max(par[i-1],a[i]);
}
for (int i=0;i<=n;i++){
dp[0][i]=1;
}
ll ans=a[n];
for (int i=1;i<n;i++){
for (int j=1;j<=n;j++){
dp[i%2][j]=dp[(i-1)%2][j]*j%mod+dp[(i-1)%2][j+1];
dp[i%2][j]%=mod;
//cout << i << " " << j << " " << dp[i][par] << endl;
}
ans+=dp[i%2][par[n-i-1]]*(a[n-i]-1)%mod;
}
cout << ans%mod;
}
# |
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 |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
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 |
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 |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
364 KB |
Output is correct |
2 |
Correct |
4 ms |
364 KB |
Output is correct |
3 |
Correct |
4 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
492 KB |
Output is correct |
2 |
Correct |
13 ms |
364 KB |
Output is correct |
3 |
Correct |
13 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1097 ms |
748 KB |
Time limit exceeded |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
307 ms |
620 KB |
Output is correct |
2 |
Correct |
311 ms |
620 KB |
Output is correct |
3 |
Correct |
310 ms |
492 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1093 ms |
620 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |