#include <bits/stdc++.h>
using namespace std;
vector<vector<int>> teams;
vector<int> pmin;
priority_queue<pair<int, int>> pq;
vector<vector<int>> dp((int)1e6, vector<int>(3, -(int)1e9));
vector<pair<int, int>> a((int)1e6);
void f(int x){
if(x < 0){
return;
}
if(dp[x][2] < x - 1){
++dp[x][2];
f(dp[x][2]);
vector<int> np(x - dp[x][2]);
for(int j = x; j > dp[x][2]; --j){
np[x - j] = a[j].second;
}
pq.push({-(int)np.size(), (int)teams.size()});
teams.push_back(np);
}
else{
f(x - 1);
int top = pq.top().second; pq.pop();
teams[top].push_back(a[x].second);
pq.push({-(int)teams[top].size(), top});
}
};
int main(){
//ios_base::sync_with_stdio(false);
//cin.tie(NULL);
int N;
cin >> N;
for(int i = 0; i < N; ++i){
cin >> a[i].first;
a[i].second = i;
}
sort(a.begin(), a.end());
reverse(a.begin(), a.end());
vector<vector<int>> look(N);
vector<int> nnow = {1, -a[0].first, -2};
dp[a[0].first - 1] = nnow;
for(int i = 0; i < N; ++i){
for(auto&j:look[i]){
vector<int> now = {dp[j][0] + 1, -max(-dp[j][1], i - j), j - 1};
dp[i] = max(dp[i], now);
}
if(i){
vector<int> now = {dp[i - 1][0], -(-dp[i - 1][1] + (i == dp[i - 1][0] * -dp[i - 1][1])), i - 1};
dp[i] = max(dp[i], now);
}
if(i < N - 1 && i + a[i + 1].first < N){
look[i + a[i + 1].first].push_back(i);
}
}
f(N - 1);
cout << (int)teams.size() << '\n';
for(auto&i:teams){
cout << (int)i.size() << ' ';
for(auto&j:i){
cout << j + 1 << ' ';
}
cout << '\n';
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
94 ms |
62956 KB |
Output is correct |
2 |
Correct |
97 ms |
63084 KB |
Output is correct |
3 |
Correct |
103 ms |
62956 KB |
Output is correct |
4 |
Correct |
97 ms |
63084 KB |
Output is correct |
5 |
Correct |
96 ms |
62956 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
96 ms |
62956 KB |
Output is correct |
2 |
Correct |
101 ms |
62976 KB |
Output is correct |
3 |
Correct |
124 ms |
62976 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
96 ms |
62956 KB |
Output is correct |
2 |
Correct |
95 ms |
62956 KB |
Output is correct |
3 |
Correct |
98 ms |
62988 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
109 ms |
63340 KB |
Output is correct |
2 |
Correct |
121 ms |
63340 KB |
Output is correct |
3 |
Correct |
100 ms |
63340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
102 ms |
63340 KB |
Output is correct |
2 |
Correct |
113 ms |
63340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
174 ms |
68460 KB |
Output is correct |
2 |
Correct |
154 ms |
68332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
165 ms |
69356 KB |
Output is correct |
2 |
Correct |
170 ms |
68504 KB |
Output is correct |
3 |
Correct |
168 ms |
68716 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
607 ms |
112920 KB |
Output is correct |
2 |
Correct |
554 ms |
114848 KB |
Output is correct |
3 |
Correct |
619 ms |
113444 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
790 ms |
129804 KB |
Output is correct |
2 |
Runtime error |
622 ms |
262148 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
796 ms |
117812 KB |
Output is correct |
2 |
Correct |
658 ms |
97704 KB |
Output is correct |
3 |
Correct |
739 ms |
129260 KB |
Output is correct |
4 |
Correct |
809 ms |
126816 KB |
Output is correct |