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>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define N 2000001
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll INF = 1e18, MOD = 1e6 + 7, MOD2 = 1e6 + 3;
ll ans = 1, d[10001][2], a[N], n, mx[N];
int main () {
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
mx[i] = a[i];
if (i) mx[i] = max (mx[i], mx[i-1]);
}
for (int i = 0; i < n; i++) {
d[i][0] = 1;
}
for (int i = n - 1; i >= 0; i--) {
int k = ((n - i) & 1);
for (int j = 0; j <= n; j++) {
d[j][k] = (j * d[j][!k] + d[j+1][!k]) % MOD;
}
ans = (ans + (a[i] - 1) * d[i ? mx[i-1] : 0LL][!k]) % 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... |