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 MOD 1000007
#define ll long long int
ll dp[10005];
ll dp2[10005];
void calc() {
for(ll i = 1; i <= 10000; i++) {
dp2[i] = (dp[i+1]+dp[i]*i)%MOD;
}
for(int i = 1; i <= 10000; i++) {
dp[i] = dp2[i];
}
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
vector<ll> arr(n);
vector<int> cnt(n+1,0);
for(int i = 0; i < n; i++) {
dp[i] = 1;
cin >> arr[i];
cnt[arr[i]]++;
}
dp[n] = 1;
ll ans = 1;
for(ll i = n-1; i >= 0; i--) {
if(arr[i] > 1) {
if(cnt[arr[i]] == 1) {
ans+= ((arr[i]-1)*dp[arr[i]-1])%MOD;
} else {
ans+= ((arr[i]-1)*dp[arr[i]])%MOD;
}
}
calc();
cnt[arr[i]]--;
}
cout << ans%MOD;
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... |