Submission #512970

#TimeUsernameProblemLanguageResultExecution timeMemory
512970sidonTeams (CEOI11_tea)C++17
100 / 100
1297 ms83656 KiB
#include <bits/stdc++.h> using namespace std; const int Z = 1e6+1; int N, P[Z]; array<int, 2> A[Z], DP[Z]; int build(int x) { priority_queue<array<int, 2>> b; b.push(DP[0]); for(int i = 1, r = 0; i <= N; i++) { int R = max(-1, i - A[i][0]); while(r < R) b.push(DP[++r]); r = R; while(!empty(b) && (b.top()[1] < i - x || b.top()[1] > R)) b.pop(); if(empty(b)) DP[i] = {-(int)2e9, -1}; else { DP[i] = b.top(); P[i] = DP[i][1]; DP[i] = {DP[i][0] + 1, i}; } } return DP[N][0]; } int main() { cin >> N; for(int i = 1; i <= N; i++) cin >> A[A[i][1] = i][0]; sort(A, A + N + 1); int best = build(1e6), sz = N; for(int j=1<<20; j/=2; ) { if(sz - j < A[N][0]) continue; if(build(sz - j) == best) sz -= j; } build(sz); int curr = P[N]; vector<vector<int>> res = {{}}; for(int i = N + 1; --i; ) { if(curr == i) { res.push_back({}); curr = P[curr]; } res.back().push_back(A[i][1]); } cout << size(res) << '\n'; for(auto &V : res) { cout << size(V); for(auto &i : V) cout << ' ' << i; cout << '\n'; } }
#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...