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 MAXN = 10 * 1000 + 23, D = 1000 * 1000 + 7;
int dp[2][MAXN], a[MAXN], n, cnt[MAXN], jav;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr), cout.tie(nullptr);
cin >> n;
for (int i = 0; i < n; i++) cin >> a[i];
{
set<int> s;
for (int i = 0; i < n; i++) {
s.insert(a[i]);
cnt[i] = s.size();
}
}
fill(dp[1], dp[1] + n, 1);
for (int i = 0; i < n - 1; i++) {
for (int j = 1; j < n - 1; j++) dp[i & 1][j] = (1ll * dp[1 - (i & 1)][j] * j % D + dp[1 - (i & 1)][j + 1]) % D;
int j = n - i - 1;
jav += 1ll * (a[j] - 1) * dp[1 - (i & 1)][cnt[j - 1]] % D;
jav %= D;
}
cout << (jav + 1) % D;
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... |