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;
const int mod = 1000007;
#define maxn 10010
int dp[2][maxn];
int n;
int nums[maxn];
int maxbef[maxn];
int main() {
fill(dp[0], dp[0]+maxn, 1);
fill(dp[1], dp[1]+maxn, 1);
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int cur = 0, prev = 1;
cin >> n;
//going to do 1-indexed
for (int i = 1; i <= n; i++) {
cin >> nums[i];
}
for (int i = 1; i <= n; i++) {
maxbef[i] = max(maxbef[i-1], nums[i-1]);
}
int ans = 0;
for (int i = n; i >= 1; i--, swap(prev, cur)) {
for (int j = 1; j <= i; j++) {
//this whole thing is free range
dp[cur][j] = (j*1LL*dp[prev][j])%mod;
dp[cur][j] = (dp[cur][j] + dp[prev][j+1])%mod;
}
int val = 0;
val = (val + (nums[i]-1)*1LL*dp[prev][maxbef[i]])%mod;
ans = (ans+val)%mod;
}
cout << ans+1 << endl; //think we want the plus 1
}
# | 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... |