Submission #982656

#TimeUsernameProblemLanguageResultExecution timeMemory
982656vjudge1Teams (CEOI11_tea)C++17
100 / 100
531 ms106120 KiB
#include <bits/stdc++.h> using namespace std; const int N=200005; int main() { int n; cin >> n; vector<int> a[n + 1]; vector<int> v(n + 1); for(int i = 1;i <= n; i++){ cin >> v[i]; a[v[i]].push_back(i); } sort(v.begin(), v.end()); vector<int> dp(n + 1,-N); vector<int> mx(n + 1); function<int(int)> check = [&](int lim){ dp.assign(n + 1,-N); dp[0] = 0; for(int i = 1;i <= n; i++){ if(i >= v[i] && i - mx[i - v[i]] <= lim) dp[i] = dp[mx[i - v[i]]] + 1; mx[i] = (dp[mx[i - 1]] > dp[i] ? mx[i - 1] : i); } return dp[n]; }; int mx1 = check(n); int l = 0,r = n; while(r - l > 1){ int mid = l + r >>1; if(check(mid) == mx1){ r = mid; } else{ l = mid; } } check(r); vector<vector<int>> ans; int p = n; while(p > 0){ ans.push_back(vector<int>()); int t = mx[p - v[p]]; while(p > t){ ans.back().push_back(a[v[p]].back()); a[v[p]].pop_back(); p--; } } cout << mx1 << "\n"; for(auto &i : ans){ cout << i.size() << ' '; for(int j:i){ cout << j << ' '; } cout << "\n"; } return 0; }

Compilation message (stderr)

tea.cpp: In function 'int main()':
tea.cpp:28:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   28 |         int mid = l + r >>1;
      |                   ~~^~~
#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...