#include <bits/stdc++.h>
using namespace std;
const long long N = 5e2 + 5, inf = 1e17 + 5, mod = 998244353;
int main()
{
ios_base::sync_with_stdio(0), cin.tie(NULL), cout.tie(NULL);
int n;
cin >> n;
vector<int> arr(n + 1);
for (int i = 1; i <= n; i++)
cin >> arr[i];
vector<int> dp(n + 1, 1);
int mx = 1;
for (int i = 1; i <= n; i++)
for (int j = i - 1; j >= 1; j--)
if (arr[j] < arr[i])
dp[i] = max(dp[i], dp[j] + 1), mx = max(mx, dp[i]);
vector<vector<int>> vec;
vector<bool> vis(n + 1);
for (int i = n; i >= 1; i--)
{
if (!vis[i] && dp[i] == mx)
{
vector<int> tmp;
int cnt = mx;
int lst = arr[i];
for (int j = i; j >= 1 && cnt; j--)
{
if (dp[j] >= cnt && arr[j] <= lst && !vis[j])
tmp.push_back(arr[j]), cnt--, vis[j] = 1, lst = arr[j];
}
if (cnt == 0)
vec.push_back(tmp);
}
}
cout << vec.size() << " " << mx << "\n";
for (auto v : vec)
{
for (int i = v.size() - 1; i >= 0; i--)
cout << v[i] << " ";
cout << "\n";
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Subsequence increasing |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Subsequence increasing |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Subsequence increasing |
2 |
Halted |
0 ms |
0 KB |
- |