// Success consists of going from failure to failure without loss of enthusiasm
#include <bits/stdc++.h>
using namespace std;
#define nl '\n'
#define f first
#define s second
#define mp make_pair
using pi = pair<int, int>;
template<class T> using V = vector<T>;
const int MOD = int(1e6) + 7;
int main() {
cin.tie(0)->sync_with_stdio(0);
int N; cin >> N;
V<int> A(N); for(auto& x : A) {
cin >> x; --x;
}
V<array<int, 2>> dp(1, {1, 0}), ndp;
for(int i = 1; i < N; i++) {
ndp = V<array<int, 2>>(i + 1, {0, 0});
for(int x = 0; x < i; x++) {
// cout << i << " " << x << " -> " << dp[x][0] << " " << dp[x][1] << endl;
if (dp[x][1]) {
ndp[x + 1][1] += dp[x][1]; // increase max
ndp[x][1] += ((x + 1) * 1LL * dp[x][1]) % MOD; // keep max
if (ndp[x + 1][1] > MOD) ndp[x + 1][1] -= MOD;
if (ndp[x][1] > MOD) ndp[x][1] -= MOD;
}
if (dp[x][0]) {
assert(dp[x][0] == 1);
int nmx = max(x, A[i]);
ndp[nmx][0] += dp[x][0]; // keep equal
ndp[x][1] += (nmx * 1LL * dp[x][0]) % MOD; // go less
if (ndp[nmx][0] > MOD) ndp[nmx][0] -= MOD;
if (ndp[x][1] > MOD) ndp[x][1] -= MOD;
}
}
dp.swap(ndp);
}
int ans = 0;
for(int i = 0; i < N; i++) {
ans += dp[i][0] + dp[i][1];
ans %= MOD;
}
cout << ans << nl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
320 KB |
Output is correct |
3 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
316 KB |
Output is correct |
2 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
428 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
192 ms |
748 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
53 ms |
548 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
199 ms |
744 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |