#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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
228 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
332 KB |
Output is correct |
2 |
Correct |
2 ms |
204 KB |
Output is correct |
3 |
Correct |
3 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
332 KB |
Output is correct |
2 |
Correct |
5 ms |
332 KB |
Output is correct |
3 |
Correct |
5 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
407 ms |
912 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
113 ms |
332 KB |
Output is correct |
2 |
Correct |
104 ms |
404 KB |
Output is correct |
3 |
Correct |
104 ms |
648 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
442 ms |
460 KB |
Output is correct |
2 |
Correct |
426 ms |
484 KB |
Output is correct |
3 |
Correct |
435 ms |
1092 KB |
Output is correct |