#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vb = vector<bool>;
using vvb = vector<vb>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vc = vector<char>;
using vvc = vector<vc>;
const ll mod = 1e9 + 7,inf = 1e18;
#define pb push_back
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int n;
int main()
{
fast;
cin>>n;
vvi a(n + 1,vi(2));
vi dp1(n + 1,0),dp2(n + 1,n + 1),p(n + 1);
if (n <= 5e3){
for (int i = 1;i<=n;i++)cin>>a[i][0],a[i][1] = i;
sort(a.begin() + 1,a.end());
dp1[0] = 0,dp2[0] = 0;
for (int i = 1;i<=n;i++){
for (int j = i - 1;j>=1;j--){
if (i - j + 1 < a[i][0])continue;
if (dp1[i] < dp1[j - 1] + 1){
dp1[i] = dp1[j - 1] + 1;
dp2[i] = max(i - j + 1,dp2[j - 1]);
p[i] = j - 1;
}
if (dp1[i] == dp1[j - 1] + 1){
if (dp2[i] > max(i - j + 1,dp2[j - 1])){
dp2[i] = max(i - j + 1,dp2[j - 1]);
p[i] = j - 1;
}
}
}
if (dp1[i] < 1){
dp1[i] = 1;
dp2[i] = i;
}
}
cout<<dp1[n]<<'\n';
int i = n;
while (i > 0){
int j = p[i];
vi cur;
for (;i>j;i--)
cur.pb(a[i][1]);
cout<<cur.size()<<" ";
for (auto it:cur)cout<<it<<" ";
cout<<'\n';
}
}
else return -1;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
28 ms |
588 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
25 ms |
652 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
8 ms |
5580 KB |
Execution failed because the return code was nonzero |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
8 ms |
6324 KB |
Execution failed because the return code was nonzero |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
65 ms |
50128 KB |
Execution failed because the return code was nonzero |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
80 ms |
66748 KB |
Execution failed because the return code was nonzero |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
78 ms |
66780 KB |
Execution failed because the return code was nonzero |
2 |
Halted |
0 ms |
0 KB |
- |