This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |