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;
#define FOR(v, s, e) for (int v = s; v < e; v++)
#define FOR_REV(v, s, e) for (int v = e - 1; v >= s; v--)
#define int long long
#define MOD 1000007
int n, ans;
int val[10005], cmax[10005];
int dp[2][10005];
int32_t main() {
cin >> n;
cmax[n - 1] = 1;
FOR_REV(i, 0, n) {
cin >> val[i];
if (i != 0)
cmax[i - 1] = max(cmax[i], val[i]);
}
FOR(i, 0, n) {
dp[0][i] = 1;
}
bool flag = false;
FOR(i, 0, n) {
ans = (ans + (val[i] - 1) * dp[flag][cmax[i] - 1]) % MOD;
FOR(j, 0, n - 1) {
dp[1 - flag][j] = ((j + 1) * dp[flag][j] + dp[flag][j + 1]) % MOD;
}
flag = 1 - flag;
}
cout << (ans + 1) % MOD;
}
# | 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... |