#include <bits/stdc++.h>
#include <math.h>
#include <chrono>
using namespace std;
#pragma GCC optimize("-O3")
#define endl "\n"
#define mp make_pair
#define st first
#define nd second
#define pii pair<int, int>
#define pb push_back
#define _upgrade ios_base::sync_with_stdio(0), cout.setf(ios::fixed), cout.precision(10) //cin.tie(0); cout.tie(0);
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define FWD(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define fwd(i, a, b) for (int i = (a); i < (b); ++i)
#define all(c) (c).begin(), (c).end()
#define what(x) cerr << #x << " is " << x << endl;
const int MAXN = 1e6 + 1e2;
vector<pii> L;
int dp[MAXN];
bool brac[MAXN];
int n;
void solve()
{
for (int i = 1; i <= n; i++)
{
if ((i - L[i].st >= 0 && dp[i - L[i].st] + 1 >= dp[i - 1]) || i == n - 1)
{
brac[i] = true;
dp[i] = dp[i - L[i].st] + 1;
}
else
dp[i] = dp[i - 1];
}
cout << dp[n - 1] << endl;
int j = n;
while (j > 0)
{
vector<int> X;
int k = j;
for (; (k > j - L[j].st || brac[k] == false) && k > 0; k--)
X.pb(L[k].nd);
j = k;
cout << X.size() << " ";
for (int a : X)
cout << a << " ";
cout << endl;
}
}
main()
{
_upgrade;
cin >> n;
L.resize(n + 1);
L[0] = {0, 0};
rep(i, n)
{
cin >> L[i].st;
L[i].nd = i + 1;
}
sort(all(L));
solve();
}
Compilation message
tea.cpp:55:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
main()
^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
504 KB |
Integer 0 violates the range [1, 1] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
508 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
432 KB |
Output is correct |
2 |
Incorrect |
4 ms |
452 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
27 ms |
2576 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
32 ms |
2680 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
238 ms |
18760 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
335 ms |
26676 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
357 ms |
30516 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |