// 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] += (A[i] * 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 |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
324 KB |
Output is correct |
4 |
Correct |
0 ms |
316 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
316 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
316 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
320 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
316 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
340 KB |
Output is correct |
2 |
Correct |
3 ms |
340 KB |
Output is correct |
3 |
Correct |
3 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
195 ms |
752 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
48 ms |
504 KB |
Output is correct |
2 |
Correct |
49 ms |
552 KB |
Output is correct |
3 |
Correct |
49 ms |
508 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
194 ms |
752 KB |
Output is correct |
2 |
Correct |
197 ms |
744 KB |
Output is correct |
3 |
Correct |
193 ms |
760 KB |
Output is correct |