# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
691790 |
2023-01-31T14:50:10 Z |
Johann |
Teams (CEOI11_tea) |
C++14 |
|
454 ms |
26804 KB |
#include "bits/stdc++.h"
using namespace std;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
vi konstruct(vpii &A, int limit)
{
int n = sz(A);
vi last(n + 1, -1);
vi dp(n + 1, 0);
vi lastMaxIdx(n + 1, 0);
for (int i = 1; i <= n; ++i)
{
// interval to search: [ i - limit, i - A[i].first ] (inclusive borders)
int teams, la;
if (i >= A[i - 1].first)
{
int tmp = lastMaxIdx[i - A[i - 1].first];
if (tmp < i - limit)
teams = 0, la = -1;
else
teams = dp[tmp] + 1, la = tmp;
}
else
{
teams = 0, la = -1;
}
dp[i] = teams;
last[i] = la;
lastMaxIdx[i] = lastMaxIdx[i - 1];
if (dp[i] >= dp[lastMaxIdx[i]])
lastMaxIdx[i] = i;
}
vi ans;
int idx = n;
while (idx > 0)
{
ans.push_back(idx - 1);
idx = last[idx];
}
return ans;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
vpii A(n);
for (int i = 0; i < n; ++i)
cin >> A[i].first, A[i].second = i + 1;
sort(all(A));
int opt = sz(konstruct(A, n));
int l = A.back().first, r = n;
while (l < r)
{
int m = (l + r) / 2;
int ans = sz(konstruct(A, m));
if (ans < opt)
l = m + 1;
else
r = m;
}
vi order = konstruct(A, l);
reverse(all(order));
cout << sz(order) << "\n";
int idx = 0;
for (int x : order)
{
cout << x - idx + 1 << " ";
while (idx <= x)
cout << A[idx++].second << " ";
cout << "\n";
}
cout << "\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
468 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
388 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
35 ms |
2392 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
34 ms |
2576 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
353 ms |
18744 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
448 ms |
25784 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
454 ms |
26804 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |