#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define ld long double
#define F first
#define S second
#define pii pair<ll,ll>
using namespace :: std;
const ll mod=1e6+7;
const ll maxn=10010;
ll a[maxn];
ll f[2][maxn];
ll mx[maxn];
inline void jam(ll &a,ll b){
a+=b;
if(a>=mod)a-=mod;
}
int main(){
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
ll n;
cin>>n;
for(ll i=0;i<n;i++){
cin>>a[i];
}
mx[0]=a[0];
for(ll i=1;i<n;i++){
mx[i]=max(mx[i-1],a[i]);
}
ll ans=1;
for(ll i=0;i<maxn;i++){
f[0][i]=1;
}
for(ll i=n-1;i>=1;i--){
jam(ans,((a[i]-1)*f[(n-i-1)&1][mx[i-1]])%mod);
bool no=(n-i)&1;
bool la=(n-i-1)&1;
for(ll j=0;j+1<maxn;j++){
f[no][j]=(f[la][j+1]+f[la][j]*j)%mod;
}
}
cout<<ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
512 KB |
Output is correct |
2 |
Correct |
2 ms |
512 KB |
Output is correct |
3 |
Correct |
2 ms |
512 KB |
Output is correct |
4 |
Correct |
2 ms |
512 KB |
Output is correct |
5 |
Correct |
2 ms |
512 KB |
Output is correct |
6 |
Correct |
2 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
512 KB |
Output is correct |
2 |
Correct |
2 ms |
512 KB |
Output is correct |
3 |
Correct |
2 ms |
512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
512 KB |
Output is correct |
2 |
Correct |
2 ms |
512 KB |
Output is correct |
3 |
Correct |
2 ms |
512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
512 KB |
Output is correct |
2 |
Correct |
4 ms |
512 KB |
Output is correct |
3 |
Correct |
4 ms |
512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
512 KB |
Output is correct |
2 |
Correct |
12 ms |
512 KB |
Output is correct |
3 |
Correct |
12 ms |
512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
22 ms |
512 KB |
Output is correct |
2 |
Correct |
22 ms |
512 KB |
Output is correct |
3 |
Correct |
22 ms |
512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
206 ms |
696 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
107 ms |
620 KB |
Output is correct |
2 |
Correct |
109 ms |
616 KB |
Output is correct |
3 |
Correct |
106 ms |
640 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
207 ms |
640 KB |
Output is correct |
2 |
Correct |
204 ms |
696 KB |
Output is correct |
3 |
Correct |
205 ms |
640 KB |
Output is correct |