/*
+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+
|\/ /|\ \/|\/ /|\ \/|\/ /|\ \/|\/ /|\ \/|\/ /|\ \/|\/ /|\ \/|\/ /|\ \/|\/ /|\ \/|\/ /|\ \/|\/ /|\ \/|\/ /|\ \/|\/ /|\ \/|\/ /|\ \/|
|/\/ | \/\|/\/ | \/\|/\/ | \/\|/\/ | \/\|/\/ | \/\|/\/ | \/\|/\/ | \/\|/\/ | \/\|/\/ | \/\|/\/ | \/\|/\/ | \/\|/\/ | \/\|/\/ | \/\|
| / /|\ \ | / /|\ \ | / /|\ \ | / /|\ \ | / /|\ \ | / /|\ \ | / /|\ \ | / /|\ \ | / /|\ \ | / /|\ \ | / /|\ \ | / /|\ \ | / /|\ \ |
|/ / | \ \|/ / | \ \|/ / | \ \|/ / | \ \|/ / | \ \|/ / | \ \|/ / | \ \|/ / | \ \|/ / | \ \|/ / | \ \|/ / | \ \|/ / | \ \|/ / | \ \|
+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+
|\ \ | / /|\ \ | / /|\ \ | / /|\ \ | / /|\ \ | / /|\ \ | / /|\ \ | / /|\ \ | / /|\ \ | / /|\ \ | / /|\ \ | / /|\ \ | / /|\ \ | / /|
| \ \|/ / | \ \|/ / | \ \|/ / | \ \|/ / | \ \|/ / | \ \|/ / | \ \|/ / | \ \|/ / | \ \|/ / | \ \|/ / | \ \|/ / | \ \|/ / | \ \|/ / |
|\/\ | /\/|\/\ | /\/|\/\ | /\/|\/\ | /\/|\/\ | /\/|\/\ | /\/|\/\ | /\/|\/\ | /\/|\/\ | /\/|\/\ | /\/|\/\ | /\/|\/\ | /\/|\/\ | /\/|
|/\ \|/ /\|/\ \|/ /\|/\ \|/ /\|/\ \|/ /\|/\ \|/ /\|/\ \|/ /\|/\ \|/ /\|/\ \|/ /\|/\ \|/ /\|/\ \|/ /\|/\ \|/ /\|/\ \|/ /\|/\ \|/ /\|
+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+
|\/ /|\ \/|\/ /|\ \/|\/ /|\ \/|\/ /|\ \/|\/ /|\ \/|\/ /|\ \/|\/ /|\ \/|\/ /|\ \/|\/ /|\ \/|\/ /|\ \/|\/ /|\ \/|\/ /|\ \/|\/ /|\ \/|
|/\/ | \/\|/\/ | \/\|/\/ | \/\|/\/ | \/\|/\/ | \/\|/\/ | \/\|/\/ | \/\|/\/ | \/\|/\/ | \/\|/\/ | \/\|/\/ | \/\|/\/ | \/\|/\/ | \/\|
| / /|\ \ | / /|\ \ | / /|\ \ | / /|\ \ | / /|\ \ | / /|\ \ | / /|\ \ | / /|\ \ | / /|\ \ | / /|\ \ | / /|\ \ | / /|\ \ | / /|\ \ |
|/ / | \ \|/ / | \ \|/ / | \ \|/ / | \ \|/ / | \ \|/ / | \ \|/ / | \ \|/ / | \ \|/ / | \ \|/ / | \ \|/ / | \ \|/ / | \ \|/ / | \ \|
+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+
|\ \ | / /|\ \ | / /|\ \ | / /|\ \ | / /|\ \ | / /|\ \ | / /|\ \ | / /|\ \ | / /|\ \ | / /|\ \ | / /|\ \ | / /|\ \ | / /|\ \ | / /|
| \ \|/ / | \ \|/ / | \ \|/ / | \ \|/ / | \ \|/ / | \ \|/ / | \ \|/ / | \ \|/ / | \ \|/ / | \ \|/ / | \ \|/ / | \ \|/ / | \ \|/ / |
|\/\ | /\/|\/\ | /\/|\/\ | /\/|\/\ | /\/|\/\ | /\/|\/\ | /\/|\/\ | /\/|\/\ | /\/|\/\ | /\/|\/\ | /\/|\/\ | /\/|\/\ | /\/|\/\ | /\/|
|/\ \|/ /\|/\ \|/ /\|/\ \|/ /\|/\ \|/ /\|/\ \|/ /\|/\ \|/ /\|/\ \|/ /\|/\ \|/ /\|/\ \|/ /\|/\ \|/ /\|/\ \|/ /\|/\ \|/ /\|/\ \|/ /\|
+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+
*/
#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<vector<vvi> > > dp(N, vector<vector<vvi> >(N, vector<vvi>(N, vvi(N, vi(2, -1))))), cnt = dp;
const function<int(int, int, int, int, bool)> DP = [&](const int x, const int y, const int l, const int r, const bool z) -> int {
if (x > n)
return y;
if (dp[x][y][l][r][z] < 0) {
dp[x][y][l][r][z] = DP(x + 1, y, l, r, z);
if (z) {
if (a[r] < a[x])
maxi(dp[x][y][l][r][z], DP(x + 1, y + 1, l, x, z));
if (a[x] < a[l])
maxi(dp[x][y][l][r][z], DP(x + 1, y + 1, x, r, z));
} else
maxi(dp[x][y][l][r][z], DP(x + 1, y + 1, x, x, true));
}
return dp[x][y][l][r][z];
};
const function<int(int, int, int, int, bool)> Count = [&](const int x, const int y, const int l, const int r, const bool z) -> int {
if (x > n)
return y == 0;
if (cnt[x][y][l][r][z] < 0) {
cnt[x][y][l][r][z] = (Count(x + 1, y, l, r, z) << (x > 1)) % MOD;
if (z) {
if (a[r] < a[x])
(cnt[x][y][l][r][z] += Count(x + 1, y - 1, l, x, z)) %= MOD;
if (a[x] < a[l])
(cnt[x][y][l][r][z] += Count(x + 1, y - 1, x, r, z)) %= MOD;
} else
(cnt[x][y][l][r][z] += (Count(x + 1, y - 1, x, x, true) << (x > 1)) % MOD) %= MOD;
}
return cnt[x][y][l][r][z];
};
cout << DP(1, 0, 0, 0, false) << ' ' << Count(1, DP(1, 0, 0, 0, false), 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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
45 ms |
44108 KB |
Memory limit exceeded |
2 |
Runtime error |
49 ms |
44112 KB |
Memory limit exceeded |
3 |
Runtime error |
48 ms |
44072 KB |
Memory limit exceeded |
4 |
Correct |
1 ms |
460 KB |
Output is correct |
5 |
Runtime error |
58 ms |
44120 KB |
Memory limit exceeded |
6 |
Runtime error |
47 ms |
44108 KB |
Memory limit exceeded |
7 |
Runtime error |
52 ms |
65536 KB |
Execution killed with signal 9 |
8 |
Runtime error |
52 ms |
65536 KB |
Execution killed with signal 9 |
9 |
Runtime error |
51 ms |
65536 KB |
Execution killed with signal 9 |
10 |
Runtime error |
52 ms |
65536 KB |
Execution killed with signal 9 |
11 |
Runtime error |
75 ms |
65536 KB |
Execution killed with signal 9 |
12 |
Runtime error |
73 ms |
65536 KB |
Execution killed with signal 9 |
13 |
Runtime error |
80 ms |
65536 KB |
Execution killed with signal 9 |
14 |
Runtime error |
64 ms |
65536 KB |
Execution killed with signal 9 |
15 |
Runtime error |
70 ms |
65536 KB |
Execution killed with signal 9 |
16 |
Runtime error |
76 ms |
65536 KB |
Execution killed with signal 9 |
17 |
Runtime error |
74 ms |
65536 KB |
Execution killed with signal 9 |
18 |
Runtime error |
71 ms |
65536 KB |
Execution killed with signal 9 |
19 |
Runtime error |
68 ms |
65536 KB |
Execution killed with signal 9 |
20 |
Runtime error |
69 ms |
65536 KB |
Execution killed with signal 9 |