This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define T int t;cin >> t;while(t--)
#define int long long
#define F first
#define S second
using namespace std;
const int mod = 1e9 + 7;
const int N = 1002;
int n, a[N], dp[N];
bool vis[N];
vector<vector<int>> ans;
vector<int> v;
int Rec(int i) {
int &ret = dp[i];
if (ret != -1) return ret;
ret = 0;
for(int j = i + 1; j <= n; j++) {
if (a[j] > a[i]) ret = max(ret, 1 + Rec(j));
}
return ret;
}
main() {
cin >> n;
for(int i = 1; i <= n; i++) cin >> a[i], dp[i] = -1;
int mx = 0;
for(int i = 1; i <= n; i++)
mx = max(mx, 1 + Rec(i));
for(int i = 1; i <= n; i++) {
if (vis[i]) continue;
if (Rec(i) + 1 == mx) {
int cnt = mx - 1;
v.clear();
v.push_back(i);
vis[i] = 1;
for(int j = i + 1; j <= n; j++)
if (vis[j] == 0 && a[j] > a[i] && Rec(j) + 1 == cnt) v.push_back(j), cnt--, vis[j] = 1;
ans.push_back(v);
}
}
cout << ans.size() << ' ' << mx << '\n';
for(auto x: ans) {
for(auto y: x) cout << y << ' ';
cout << '\n';
}
}
Compilation message (stderr)
Main.cpp:25:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
25 | main() {
| ^~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |