#include <bits/stdc++.h>
#define int long long
using namespace std;
namespace std {
template <typename T> ostream &operator<<(ostream &out, const vector<T> &vec) {
out << "[";
for (int i = 0; i < (int)vec.size(); ++i) {
out << vec[i];
if (i + 1 < (int)vec.size())
out << ", ";
}
return out << "]";
}
} // namespace std
void dbg_out() { cout << endl; }
template <typename Head, typename... Tail> void dbg_out(Head H, Tail... T) {
cout << ' ' << H;
dbg_out(T...);
}
#ifdef DEBUG
#define dbg(...) cout << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
#else
#define dbg(...)
#endif
const int MOD = 1e6 + 7;
const int MAXN = 1e4 + 1;
int fact[MAXN];
int DP[2][MAXN];
void init() {
fact[0] = 1;
for (int i = 1; i < MAXN; i++)
fact[i] = i * fact[i - 1] % MOD;
}
signed main(void) {
ios_base::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
vector<int> a(n);
for (int &x : a) {
cin >> x;
}
int ret = 0;
vector<int> prefMax(n + 1);
for (int i = 1; i < n; ++i)
prefMax[i + 1] = max(prefMax[i], a[i]);
for (int i = 1; i <= n; ++i)
DP[0][i] = 1;
for (int i = n - 1; i >= 1; --i) {
int maxVu = prefMax[i];
int restant = n - i - 1;
for (int val = 1; val < a[i]; ++val) {
ret += DP[restant % 2][max(val, maxVu)];
dbg(i, val, ret);
if (ret >= MOD)
ret -= MOD;
}
int p = (restant + 1) % 2;
for (int vu = 1; vu <= n; ++vu) {
DP[p][vu] = vu * DP[!p][vu] % MOD;
if (vu < n) {
DP[p][vu] += DP[!p][vu + 1];
if (DP[p][vu] >= MOD)
DP[p][vu] -= MOD;
}
}
}
cout << ret + 1 << endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
328 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
328 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
2 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
368 KB |
Output is correct |
2 |
Correct |
3 ms |
340 KB |
Output is correct |
3 |
Correct |
4 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
368 ms |
676 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
73 ms |
492 KB |
Output is correct |
2 |
Correct |
70 ms |
488 KB |
Output is correct |
3 |
Correct |
86 ms |
504 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
297 ms |
656 KB |
Output is correct |
2 |
Correct |
298 ms |
652 KB |
Output is correct |
3 |
Correct |
357 ms |
672 KB |
Output is correct |