Submission #338318

#TimeUsernameProblemLanguageResultExecution timeMemory
338318lohachoTeams (CEOI11_tea)C++14
20 / 100
689 ms200552 KiB
#include <bits/stdc++.h> using namespace std; int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); int N; cin >> N; vector<pair<int, int>> a(N); for(int i = 0; i < N; ++i){ cin >> a[i].first; a[i].second = i; } sort(a.begin(), a.end()); reverse(a.begin(), a.end()); vector<vector<int>> dp(N, vector<int>(3, -(int)1e9)); vector<vector<int>> look(N); vector<int> nnow = {1, -a[0].first, -2}; dp[a[0].first - 1] = nnow; for(int i = 0; i < N; ++i){ for(auto&j:look[i]){ vector<int> now = {dp[j][0] + 1, -max(-dp[j][1], i - j), j - 1}; dp[i] = max(dp[i], now); } if(i){ vector<int> now = {dp[i - 1][0], -(-dp[i - 1][1] + (i == dp[i - 1][0] * -dp[i - 1][1])), i - 1}; dp[i] = max(dp[i], now); } if(i < N - 1 && i + a[i + 1].first < N){ look[i + a[i + 1].first].push_back(i); } } vector<vector<int>> teams; vector<int> pmin; for(int i = N - 1; i >= 0;){ if(dp[i][2] < i - 1){ ++dp[i][2]; vector<int> np(i - dp[i][2]); for(int j = i; j > dp[i][2]; --j){ np[i - j] = a[j].second; } teams.push_back(np); i = dp[i][2]; } else{ pmin.push_back(a[i].second); --i; } } priority_queue<pair<int, int>> pq; for(int i = 0; i < (int)teams.size(); ++i){ pq.push({-(int)teams[i].size(), i}); } for(auto&i:pmin){ int top = pq.top().second; pq.pop(); teams[top].push_back(i); pq.push({-(int)teams[top].size(), top}); } cout << (int)teams.size() << '\n'; for(auto&i:teams){ cout << (int)i.size() << ' '; for(auto&j:i){ cout << j + 1 << ' '; } cout << '\n'; } 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...