#include <iostream>
#include <iomanip>
#include <fstream>
#include <vector>
#include <array>
#include <algorithm>
#include <utility>
#include <map>
#include <queue>
#include <set>
#include <cmath>
#include <cstdio>
#include <cstring>
#define ll long long
#define ld long double
#define eps 1e-8
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3f
// change if necessary
#define MAXN 1000010
using namespace std;
int n;
pair<int, int> players[MAXN];
// {num_teams, max_size, cur_size}
array<int, 3> dp[MAXN];
array<int, 3> cmp(array<int, 3> &a, const array<int, 3> &b) {
if (a[0] == b[0]) {
if (a[1] == b[1]) {
return a = min(a, b);
}
return a = min(a, b);
}
return a = max(a, b);
}
int main() {
cin.tie(0)->sync_with_stdio(0);
cin >> n;
for (int i = 0; i < n; i++) {
cin >> players[i].first;
players[i].second = i;
}
sort(players, players + n, greater<pair<int, int>>());
for (int i = 0; i <= n; i++) {
dp[i] = {-1, 0, 0};
}
dp[players[0].first] = {1, players[0].first, players[0].first};
for (int i = 0; i < n; i++) {
if (dp[i][0] != -1) {
cmp(dp[i + 1], {dp[i][0], max(dp[i][1], dp[i][2] + 1), dp[i][2] + 1});
if (i + players[i].first <= n) {
cmp(dp[i + players[i].first], {dp[i][0] + 1, max(dp[i][1], players[i].first), players[i].first});
}
}
}
cout << dp[n][0] << '\n';
int cur = n;
while (cur > 0) {
int nxt_cur = cur - dp[cur][2];
cout << cur - nxt_cur << ' ';
for (int i = nxt_cur; i < cur; i++) {
cout << players[i].second + 1 << ' ';
}
cout << '\n';
cur = nxt_cur;
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
512 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
512 KB |
Output is correct |
2 |
Incorrect |
3 ms |
512 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
25 ms |
2432 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
28 ms |
2680 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
232 ms |
20228 KB |
Output is correct |
2 |
Correct |
225 ms |
22520 KB |
Output is correct |
3 |
Correct |
242 ms |
24600 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
325 ms |
26872 KB |
Output is correct |
2 |
Correct |
310 ms |
31840 KB |
Output is correct |
3 |
Correct |
300 ms |
29816 KB |
Output is correct |
4 |
Correct |
296 ms |
28408 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
319 ms |
26872 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |