Submission #94853

#TimeUsernameProblemLanguageResultExecution timeMemory
94853popovicirobertTeams (CEOI11_tea)C++14
100 / 100
353 ms29560 KiB
#include <bits/stdc++.h> #define lsb(x) (x & (-x)) #define ll long long #define ull unsigned long long #define ld long double // 217 // 44 using namespace std; const int INF = 1e9; const int MAXN = (int) 1e6; pair <int, int> arr[MAXN + 1]; int dp[MAXN + 1], from[MAXN + 1]; int last[MAXN + 1]; inline int check(int n, int len) { int mx = 0; for(int i = 1; i <= n; i++) { if(i - arr[i].first < 0) { dp[i] = -INF; } else { if(i - last[i - arr[i].first] <= len) { dp[i] = dp[last[i - arr[i].first]] + 1; from[i] = last[i - arr[i].first]; } else { dp[i] = -INF; } if(dp[i] < mx && i != n) { dp[i] = -INF; } } last[i] = last[i - 1]; if(dp[i] > -INF) { last[i] = i; } mx = max(mx, dp[i]); } return dp[n]; } int main() { //ifstream cin("A.in"); //ofstream cout("A.out"); int i, n; ios::sync_with_stdio(false); cin.tie(0), cout.tie(0); cin >> n; for(i = 1; i <= n; i++) { cin >> arr[i].first; arr[i].second = i; } sort(arr + 1, arr + n + 1); int ans = check(n, n); int res = arr[n].first - 1; for(int step = 1 << 20; step; step >>= 1) { if(res + step <= n && check(n, res + step) < ans) { res += step; } } check(n, res + 1); cout << ans << "\n"; int pos = n; while(pos > 0) { cout << pos - from[pos] << " "; for(i = from[pos] + 1; i <= pos; i++) { cout << arr[i].second << " "; } cout << "\n"; pos = from[pos]; } //cin.close(); //cout.close(); 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...