# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
773354 |
2023-07-05T00:50:55 Z |
NK_ |
Teams (CEOI11_tea) |
C++17 |
|
467 ms |
84600 KB |
// Success consists of going from failure to failure without loss of enthusiasm
#include <bits/stdc++.h>
using namespace std;
#define nl '\n'
#define f first
#define s second
#define mp make_pair
#define sz(x) int(x.size())
using pi = pair<int, int>;
template<class T> using V = vector<T>;
using vi = V<int>;
const int INF = int(1e9) + 10;
int main() {
cin.tie(0)->sync_with_stdio(0);
int N; cin >> N;
V<int> A(N); for(auto& x : A) cin >> x;
V<pi> B(N); for(int i = 0; i < N; i++) B[i] = mp(A[i], i);
sort(begin(B), end(B));
V<int> dp, par;
auto check = [&](int W) {
deque<pi> q;
dp = V<int>(N+1, -INF), par = V<int>(N+1, -INF);
dp[0] = 0, par[0] = -1;
int l = 0, r = 0;
for(int i = 1; i <= N; i++) {
int L = max(0, i - W) - 1, R = max(-1, i - B[i-1].first);
// cout << l << " " << r << endl;
// cout << i << " -> " << L << " " << R << endl;
while(r <= R) {
while(sz(q) && q.back().first < dp[r]) q.pop_back();
q.push_back(mp(dp[r], r)); ++r;
}
while(l <= L) {
if (sz(q) && q.front().second == l) q.pop_front();
++l;
}
if (sz(q)) {
// cout << l << " " << r << endl;
// cout << i << " -> " << B[i-1].first << " " << sz(q) << " " << q.front().second << endl;
// cout << dp[best] + 1 << endl;
tie(dp[i], par[i]) = q.front(); dp[i]++;
}
// cout << endl;
}
// for(int i = 0; i <= N; i++) cout << dp[i] << " " << par[i] << endl;
return dp[N];
};
int most = check(N + 1);
int lo = *max_element(begin(A), end(A)), hi = N + 1;
while(lo < hi) {
int mid = (lo + hi) / 2;
// cout << lo << " < " << mid << " < " << hi << endl;
if (check(mid) == most) hi = mid;
else lo = mid + 1;
// cout << dp[N - 1] << endl;
}
// cout << "ANS: " << lo << endl;
check(lo);
int x = N;
V<V<int>> ans;
while(x > 0) {
int nxt = par[x];
ans.push_back({});
while(x > nxt) ans.back().push_back(B[--x].second + 1);
}
cout << sz(ans) << nl;
for(auto& v : ans) {
cout << sz(v) << " ";
for(auto c : v) {
cout << c << " ";
assert(sz(v) >= A[c - 1]);
}
cout << nl;
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Runtime error |
1 ms |
468 KB |
Execution killed with signal 6 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
468 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
2 ms |
724 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
468 KB |
Output is correct |
2 |
Correct |
2 ms |
468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
32 ms |
5172 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
32 ms |
3292 KB |
Output is correct |
2 |
Correct |
27 ms |
2908 KB |
Output is correct |
3 |
Correct |
34 ms |
3092 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
314 ms |
23668 KB |
Output is correct |
2 |
Correct |
309 ms |
25320 KB |
Output is correct |
3 |
Correct |
309 ms |
24644 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
414 ms |
32532 KB |
Output is correct |
2 |
Correct |
467 ms |
84600 KB |
Output is correct |
3 |
Correct |
420 ms |
33644 KB |
Output is correct |
4 |
Runtime error |
369 ms |
44964 KB |
Execution killed with signal 6 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
424 ms |
33140 KB |
Output is correct |
2 |
Correct |
178 ms |
36656 KB |
Output is correct |
3 |
Correct |
409 ms |
31536 KB |
Output is correct |
4 |
Runtime error |
418 ms |
50640 KB |
Execution killed with signal 6 |
5 |
Halted |
0 ms |
0 KB |
- |