#include <bits/stdc++.h>
#define int long long
#define pii pair<int,int>
#define vi vector<int>
#define ff first
#define ss second
#define all(x) x.begin(),x.end()
#define sp << " " <<
using namespace std;
const int N = 3e5+10,MOD = 1e9+7,inf = 2e12;
void solve() {
int n;
cin >> n;
vi a(n+1);
vector<vi> ans;
for (int i=1;i<=n;i++) cin >> a[i];
assert(n <= 15);
int l = 0;
vi dp(n+1,1);
for (int i = 1;i<=n;i++) {
for (int j = 1;j<i;j++) {
if (a[j] < a[i]) {
dp[i] = max(dp[i],dp[j]+1);
}
}
}
l = *max_element(all(dp));
while (1) {
dp.assign(n+1,1);
for (int i = 1;i<=n;i++) {
if (a[i] == inf) {
dp[i] = 0;
continue;
}
for (int j = 1;j<i;j++) {
if (a[j] < a[i] && a[j] != inf) {
dp[i] = max(dp[i],dp[j]+1);
}
}
}
int pos = 0;
for (int i = n;i>=1;i--) {
if (dp[i] == l) {
pos = i;
break;
}
}
if (!pos) break;
vi cur;
int sea = l-1;
cur.push_back(pos);
for (int i = pos-1;i>=1;i--) {
if (!sea) break;
if (dp[i] == sea) {
sea--;
cur.push_back(i);
a[i] = inf;
}
}
reverse(all(cur));
ans.push_back(cur);
}
cout << ans.size() sp l << endl;
for (auto it : ans) {
for (auto itt : it) cout << itt << ' ';
cout << '\n';
}
}
signed main() {
ios_base::sync_with_stdio(0);cin.tie(0);
#ifdef Dodi
freopen("in.txt","r",stdin);
freopen("out.txt","w",stdout);
#endif
int t = 1;
//cin >> t;
while (t --> 0) solve();
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |