/*
+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+
|\/ /|\ \/|\/ /|\ \/|\/ /|\ \/|\/ /|\ \/|\/ /|\ \/|\/ /|\ \/|\/ /|\ \/|\/ /|\ \/|\/ /|\ \/|\/ /|\ \/|\/ /|\ \/|\/ /|\ \/|\/ /|\ \/|
|/\/ | \/\|/\/ | \/\|/\/ | \/\|/\/ | \/\|/\/ | \/\|/\/ | \/\|/\/ | \/\|/\/ | \/\|/\/ | \/\|/\/ | \/\|/\/ | \/\|/\/ | \/\|/\/ | \/\|
| / /|\ \ | / /|\ \ | / /|\ \ | / /|\ \ | / /|\ \ | / /|\ \ | / /|\ \ | / /|\ \ | / /|\ \ | / /|\ \ | / /|\ \ | / /|\ \ | / /|\ \ |
|/ / | \ \|/ / | \ \|/ / | \ \|/ / | \ \|/ / | \ \|/ / | \ \|/ / | \ \|/ / | \ \|/ / | \ \|/ / | \ \|/ / | \ \|/ / | \ \|/ / | \ \|
+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+
|\ \ | / /|\ \ | / /|\ \ | / /|\ \ | / /|\ \ | / /|\ \ | / /|\ \ | / /|\ \ | / /|\ \ | / /|\ \ | / /|\ \ | / /|\ \ | / /|\ \ | / /|
| \ \|/ / | \ \|/ / | \ \|/ / | \ \|/ / | \ \|/ / | \ \|/ / | \ \|/ / | \ \|/ / | \ \|/ / | \ \|/ / | \ \|/ / | \ \|/ / | \ \|/ / |
|\/\ | /\/|\/\ | /\/|\/\ | /\/|\/\ | /\/|\/\ | /\/|\/\ | /\/|\/\ | /\/|\/\ | /\/|\/\ | /\/|\/\ | /\/|\/\ | /\/|\/\ | /\/|\/\ | /\/|
|/\ \|/ /\|/\ \|/ /\|/\ \|/ /\|/\ \|/ /\|/\ \|/ /\|/\ \|/ /\|/\ \|/ /\|/\ \|/ /\|/\ \|/ /\|/\ \|/ /\|/\ \|/ /\|/\ \|/ /\|/\ \|/ /\|
+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+
|\/ /|\ \/|\/ /|\ \/|\/ /|\ \/|\/ /|\ \/|\/ /|\ \/|\/ /|\ \/|\/ /|\ \/|\/ /|\ \/|\/ /|\ \/|\/ /|\ \/|\/ /|\ \/|\/ /|\ \/|\/ /|\ \/|
|/\/ | \/\|/\/ | \/\|/\/ | \/\|/\/ | \/\|/\/ | \/\|/\/ | \/\|/\/ | \/\|/\/ | \/\|/\/ | \/\|/\/ | \/\|/\/ | \/\|/\/ | \/\|/\/ | \/\|
| / /|\ \ | / /|\ \ | / /|\ \ | / /|\ \ | / /|\ \ | / /|\ \ | / /|\ \ | / /|\ \ | / /|\ \ | / /|\ \ | / /|\ \ | / /|\ \ | / /|\ \ |
|/ / | \ \|/ / | \ \|/ / | \ \|/ / | \ \|/ / | \ \|/ / | \ \|/ / | \ \|/ / | \ \|/ / | \ \|/ / | \ \|/ / | \ \|/ / | \ \|/ / | \ \|
+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+
|\ \ | / /|\ \ | / /|\ \ | / /|\ \ | / /|\ \ | / /|\ \ | / /|\ \ | / /|\ \ | / /|\ \ | / /|\ \ | / /|\ \ | / /|\ \ | / /|\ \ | / /|
| \ \|/ / | \ \|/ / | \ \|/ / | \ \|/ / | \ \|/ / | \ \|/ / | \ \|/ / | \ \|/ / | \ \|/ / | \ \|/ / | \ \|/ / | \ \|/ / | \ \|/ / |
|\/\ | /\/|\/\ | /\/|\/\ | /\/|\/\ | /\/|\/\ | /\/|\/\ | /\/|\/\ | /\/|\/\ | /\/|\/\ | /\/|\/\ | /\/|\/\ | /\/|\/\ | /\/|\/\ | /\/|
|/\ \|/ /\|/\ \|/ /\|/\ \|/ /\|/\ \|/ /\|/\ \|/ /\|/\ \|/ /\|/\ \|/ /\|/\ \|/ /\|/\ \|/ /\|/\ \|/ /\|/\ \|/ /\|/\ \|/ /\|/\ \|/ /\|
+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+
*/
#include <bits/stdc++.h>
#define fore(i, a, b) for (int i = (a), i##_last = (b); i < i##_last; ++i)
#define fort(i, a, b) for (int i = (a), i##_last = (b); i <= i##_last; ++i)
#define ford(i, a, b) for (int i = (a), i##_last = (b); i >= i##_last; --i)
#define fi first
#define se second
#define pb push_back
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
using namespace std;
using ll = long long;
using ld = long double;
template<class A, class B> bool maxi(A &a, const B &b) {return (a < b) ? (a = b, true):false;};
template<class A, class B> bool mini(A &a, const B &b) {return (a > b) ? (a = b, true):false;};
typedef unsigned long long ull;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
const int maxN = 2e5 + 5, MOD = 1e9 + 7;
int n, a[maxN];
void subtask1() {
const int N = n + 5;
vector<vector<vvi> > dp(N, vector<vvi>(N, vvi(N, vi(2, -1)))), cnt = dp;
const function<int(int, int, int, bool)> DP = [&](const int x, const int l, const int r, const bool z) -> int {
if (x > n)
return 0;
if (dp[x][l][r][z] < 0) {
dp[x][l][r][z] = DP(x + 1, l, r, z);
if (z) {
if (a[r] < a[x])
maxi(dp[x][l][r][z], 1 + DP(x + 1, l, x, z));
if (a[x] < a[l])
maxi(dp[x][l][r][z], 1 + DP(x + 1, x, r, z));
} else
maxi(dp[x][l][r][z], 1 + DP(x + 1, x, x, true));
}
return dp[x][l][r][z];
};
const function<int(int, int, int, bool)> Count = [&](const int x, const int l, const int r, const bool z) -> int {
if (x > n)
return 1;
if (cnt[x][l][r][z] < 0) {
cnt[x][l][r][z] = 0;
if (DP(x, l, r, z) == DP(x + 1, l, r, z))
(cnt[x][l][r][z] += (Count(x + 1, l, r, z) << (x > 1)) % MOD) %= MOD;
if (z) {
if (a[r] < a[x] && DP(x, l, r, z) == DP(x + 1, l, x, z) + 1)
(cnt[x][l][r][z] += Count(x + 1, l, x, z)) %= MOD;
if (a[x] < a[l] && DP(x, l, r, z) == DP(x + 1, x, r, z) + 1)
(cnt[x][l][r][z] += Count(x + 1, x, r, z)) %= MOD;
} else if (DP(x, l, r, z) == 1 + DP(x + 1, x, x, true))
(cnt[x][l][r][z] += (Count(x + 1, x, x, true) << (x > 1)) % MOD) %= MOD;
}
return cnt[x][l][r][z];
};
cout << DP(1, 0, 0, false) << ' ' << Count(1, 0, 0, false) << '\n';
}
void input() {
cin >> n;
fort(i, 1, n)
cin >> a[i];
}
int main() {
#ifdef LOCAL
freopen("input.INP", "r", stdin);
#endif // LOCAL
cin.tie(0) -> sync_with_stdio(0);
cout.tie(0);
input();
subtask1();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2004 KB |
Output is correct |
2 |
Correct |
2 ms |
2004 KB |
Output is correct |
3 |
Correct |
2 ms |
2004 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
2 ms |
2000 KB |
Output is correct |
6 |
Correct |
2 ms |
2004 KB |
Output is correct |
7 |
Runtime error |
54 ms |
65536 KB |
Execution killed with signal 9 |
8 |
Runtime error |
52 ms |
65536 KB |
Execution killed with signal 9 |
9 |
Runtime error |
52 ms |
65536 KB |
Execution killed with signal 9 |
10 |
Runtime error |
53 ms |
65536 KB |
Execution killed with signal 9 |
11 |
Runtime error |
62 ms |
65536 KB |
Execution killed with signal 9 |
12 |
Runtime error |
61 ms |
65536 KB |
Execution killed with signal 9 |
13 |
Runtime error |
63 ms |
65536 KB |
Execution killed with signal 9 |
14 |
Runtime error |
85 ms |
65536 KB |
Execution killed with signal 9 |
15 |
Runtime error |
73 ms |
65536 KB |
Execution killed with signal 9 |
16 |
Runtime error |
69 ms |
65536 KB |
Execution killed with signal 9 |
17 |
Runtime error |
69 ms |
65536 KB |
Execution killed with signal 9 |
18 |
Runtime error |
65 ms |
65536 KB |
Execution killed with signal 9 |
19 |
Runtime error |
73 ms |
65536 KB |
Execution killed with signal 9 |
20 |
Runtime error |
69 ms |
65536 KB |
Execution killed with signal 9 |