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;
using lint = long long;
const int MAX_N = 1e4 + 5;
const lint MOD = 1e6 + 7;
int n;
int arr[MAX_N];
lint mod(lint x) {
return x % MOD;
}
lint dp[MAX_N][MAX_N];
void precomp() {
for (int s = n; s >= 1; s--) {
for (int t = 1; t <= s; t++) {
if (s == n) dp[s][t] = 1;
else dp[s][t] = mod(dp[s + 1][t + 1] + mod(t * dp[s + 1][t]));
}
}
}
int main() {
// freopen("calvin.in", "r", stdin);
cin >> n;
for (int i = 1; i <= n; i++) cin >> arr[i];
precomp();
set<int> unis;
lint ans = 0;
for (int i = 1; i <= n; i++) {
lint n_unis = unis.size();
ans = mod(ans + mod(dp[i][n_unis] * (arr[i] - 1))); // Should be fine if n_unis = 0
unis.insert(arr[i]);
}
ans++;
cout << ans << '\n';
}
# | 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... |