Submission #986794

#TimeUsernameProblemLanguageResultExecution timeMemory
986794LOLOLOTeams (CEOI11_tea)C++17
0 / 100
96 ms49340 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define f first #define s second #define pb push_back #define ep emplace #define eb emplace_back #define lb lower_bound #define ub upper_bound #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() #define uniquev(v) sort(all(v)), (v).resize(unique(all(v)) - (v).begin()) #define mem(f,x) memset(f , x , sizeof(f)) #define sz(x) (int)(x).size() #define __lcm(a, b) (1ll * ((a) / __gcd((a), (b))) * (b)) #define mxx *max_element #define mnn *min_element #define cntbit(x) __builtin_popcountll(x) #define len(x) (int)(x.length()) const int N = 1e6 + 10; vector <int> pos[N]; int a[N], dp[N], pr[N], n; pair <int, int> b[N]; vector < vector <int>> bin(int lim) { vector < vector <int>> A, B; B.clear(); int lst = n; while (lst) { int nxt = -1; for (int j = lst - 1; j >= max(0, lst - lim); j--) { if (dp[j] + 1 == dp[lst] && lst - j >= b[lst].f) { nxt = j; break; } } if (nxt == -1) return B; vector <int> v; for (int j = nxt + 1; j <= lst; j++) { v.pb(b[j].s); } lst = nxt; A.pb(v); } return A; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n; for (int i = 1; i <= n; i++) { cin >> a[i]; pos[a[i]].pb(i); } int sz = 0; for (int i = 1; i <= n; i++) { for (auto x : pos[i]) { sz++; b[sz] = {i, x}; } } dp[0] = pr[0] = 0; for (int i = 1; i <= n; i++) { if (i < b[i].f) { dp[i] = -1; } else { dp[i] = pr[i - b[i].f] + 1; } pr[i] = dp[i] > dp[pr[i - 1]] ? i : pr[i - 1]; } int l = 0, r = n, m, ans = n; while (l <= r) { m = (l + r) / 2; vector < vector <int>> save = bin(m); if (sz(save)) { ans = m; r = m - 1; } else { l = m + 1; } } cout << dp[n] << '\n'; vector < vector <int>> save = bin(ans); for (auto x : save) { cout << sz(x) << " "; for (auto k : x) cout << k << " "; 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...