# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
552905 |
2022-04-24T09:35:03 Z |
blue |
Teams (CEOI11_tea) |
C++17 |
|
463 ms |
162796 KB |
#include <iostream>
#include <vector>
using namespace std;
using vi = vector<int>;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int N;
cin >> N;
vi lst[1+N];
for(int i = 1; i <= N; i++)
{
int a;
cin >> a;
lst[a].push_back(i);
}
vi A(1, 0);
vi I(1, 0);
for(int i = N; i >= 1; i--)
{
for(int x : lst[i])
{
A.push_back(i);
I.push_back(x);
}
}
vi maxteams(1+N);
vi sizelim(1+N, 5'000'000);
maxteams[0] = sizelim[0] = 0;
vi occ[1+N+1];
if(A[1] + 1 <= N+1)
occ[A[1] + 1].push_back(1);
for(int i = A[1]+1; i <= N; i++)
{
if(A[i] + i <= N+1)
occ[A[i] + i].push_back(i);
}
for(int i = A[1]; i <= N; i++)
{
// cerr << "i = " << i << '\n';
// if(i < A[1])
// {
// maxteams[i] = sizelim[i] = prev[i] = -1;
// continue;
// }
maxteams[i] = 0;
for(int j : occ[i+1])
{
if(j > i) continue;
if(maxteams[j-1] != maxteams[i-1]) continue;
int currsize = max(sizelim[j-1], i-j+1);
if(maxteams[i] == 0 || sizelim[i] > currsize)
{
maxteams[i] = maxteams[i-1] + 1;
sizelim[i] = currsize;
}
}
// cerr << "phase 1 : " << maxteams[i] << '\n';
if(maxteams[i] == 0)
{
maxteams[i] = maxteams[i-1];
if(maxteams[i-1] * sizelim[i-1] == i-1)
{
sizelim[i] = sizelim[i-1] + 1;
}
else
{
sizelim[i] = sizelim[i-1];
}
// for(int j = 1; j <= i; j++) if(A[j] <= i-j+1)
for(int j : occ[i+1])
{
// if(A[j] > i-j+1) continue;
if(j > i) continue;
if(maxteams[j-1] != maxteams[i] - 1) continue;
int currsize = max(sizelim[j-1], i-j+1);
if(sizelim[i] > currsize)
{
sizelim[i] = currsize;
}
}
}
}
vi teamocc[1+N];
for(int i = A[1]; i <= N; i++)
teamocc[maxteams[i]].push_back(i);
teamocc[0].push_back(0);
// for(int i = 1; i <= N; i++) cerr << A[i] << ' ' << I[i] << " : " << maxteams[i] << ' ' << sizelim[i] << '\n';
int ci = N;
cout << maxteams[N] << '\n';
for(int z = 1; z <= maxteams[N]; z++)
{
int pci = 0;
for(int i : teamocc[maxteams[ci]-1])
{
if(sizelim[i] <= sizelim[N] && maxteams[i] == maxteams[ci] - 1 && A[i+1] <= ci - i && ci - i <= sizelim[N])
{
pci = i;
break;
}
}
// cerr << ci << " -> " << pci << '\n';
// cerr << "ci = " << ci << '\n';
cout << ci - pci << ' ';
for(int q = pci+1; q <= ci; q++)
cout << I[q] << ' ';
cout << '\n';
ci = pci;
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
852 KB |
Output is correct |
2 |
Correct |
3 ms |
980 KB |
Output is correct |
3 |
Correct |
2 ms |
1008 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
852 KB |
Output is correct |
2 |
Correct |
3 ms |
852 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
30 ms |
9720 KB |
Output is correct |
2 |
Correct |
23 ms |
11020 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
26 ms |
11592 KB |
Output is correct |
2 |
Correct |
23 ms |
10404 KB |
Output is correct |
3 |
Correct |
25 ms |
11452 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
253 ms |
100860 KB |
Output is correct |
2 |
Correct |
232 ms |
101456 KB |
Output is correct |
3 |
Correct |
203 ms |
95916 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
275 ms |
128780 KB |
Output is correct |
2 |
Correct |
398 ms |
162796 KB |
Output is correct |
3 |
Correct |
330 ms |
135588 KB |
Output is correct |
4 |
Correct |
341 ms |
115852 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
262 ms |
105752 KB |
Output is correct |
2 |
Correct |
218 ms |
97364 KB |
Output is correct |
3 |
Correct |
270 ms |
134172 KB |
Output is correct |
4 |
Correct |
463 ms |
129068 KB |
Output is correct |