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>
using namespace std;
typedef long long int ll;
#define int ll
const int MAXN = 1005;
const ll md = 1e6+7;
ll n, a[MAXN], pt = 0;
ll dp[MAXN][MAXN], ans = 0;
int32_t main()
{
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
for(int i = 1; i < MAXN; i++) dp[1][i] = i+1, dp[0][i] = 1ll;
for(ll i = 2; i < MAXN; i++)
for(ll j = 1; j < MAXN; j++){
dp[i][j] = (j*dp[i-1][j])%md;
if(j+1 < MAXN) dp[i][j] += dp[i-1][j+1], dp[i][j] = (dp[i][j]>=md?dp[i][j]-md:dp[i][j]);
}
cin >> n;
for(int i = 0; i < n; i++) cin >> a[i];
pt = 1;
for(int i = 0; i < n; i++){
if(a[i]==1) continue;
ll tmp = (ll)a[i]-1ll;
tmp = (tmp*dp[n-i-1][pt])%md;
ans = (ans+tmp)%md;
if(a[i]==pt+1) pt++;
}
cout << (ans+1)%md << '\n';
return 0;
}
# | 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... |