# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
338328 |
2020-12-23T02:52:48 Z |
lohacho |
Teams (CEOI11_tea) |
C++14 |
|
774 ms |
262144 KB |
#include <bits/stdc++.h>
using namespace std;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int N;
cin >> N;
vector<pair<int, int>> a(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>> dp(N, vector<int>(3, -(int)1e9));
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);
}
}
look.resize(0);
vector<vector<int>> teams;
vector<int> pmin;
priority_queue<pair<int, int>> pq;
function<void(int)> 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});
}
};
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;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
392 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
1004 KB |
Output is correct |
2 |
Correct |
3 ms |
1024 KB |
Output is correct |
3 |
Correct |
3 ms |
1004 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
876 KB |
Output is correct |
2 |
Correct |
3 ms |
1024 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
42 ms |
10860 KB |
Output is correct |
2 |
Correct |
43 ms |
10348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
47 ms |
12544 KB |
Output is correct |
2 |
Correct |
41 ms |
10348 KB |
Output is correct |
3 |
Correct |
48 ms |
11500 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
398 ms |
94340 KB |
Output is correct |
2 |
Correct |
396 ms |
95724 KB |
Output is correct |
3 |
Correct |
401 ms |
94700 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
531 ms |
125344 KB |
Output is correct |
2 |
Correct |
774 ms |
262144 KB |
Output is correct |
3 |
Correct |
522 ms |
126720 KB |
Output is correct |
4 |
Correct |
489 ms |
113516 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
497 ms |
109728 KB |
Output is correct |
2 |
Correct |
404 ms |
97320 KB |
Output is correct |
3 |
Correct |
528 ms |
124832 KB |
Output is correct |
4 |
Correct |
558 ms |
122612 KB |
Output is correct |