Submission #773354

#TimeUsernameProblemLanguageResultExecution timeMemory
773354NK_Teams (CEOI11_tea)C++17
40 / 100
467 ms84600 KiB
// 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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...