Submission #65415

#TimeUsernameProblemLanguageResultExecution timeMemory
65415GoogalTeams (CEOI11_tea)C++14
100 / 100
637 ms90800 KiB
#include <algorithm> #include <iostream> #include <memory.h> #include <bitset> using namespace std; const int NMAX = 1e6 + 1e2; const int INF = 1e9; int n; int dp[NMAX]; int pr[NMAX], opt[NMAX], par[NMAX]; pair < int, int > a[NMAX]; bitset < NMAX > ok; bool check(int x) { ok = 0; ok[0] = 1; for(int i = 1; i <= n; i++) { if(i - a[i].first < 0) { dp[i] = -INF; } else { dp[i] = pr[i - a[i].first] + 1; if(opt[i - a[i].first] >= i - x) { ok[i] = 1; par[i] = opt[i - a[i].first]; } } pr[i] = pr[i - 1]; opt[i] = opt[i - 1]; if(ok[i] == 1 && pr[i] <= dp[i]) { opt[i] = i; pr[i] = dp[i]; } } return (bool)ok[n]; } void printsol(int x) { if(x == 0) return; int p1 = par[x]; printsol(p1); cout << x - p1 << ' '; for(int i = p1 + 1; i <= x; i++) cout << a[i].second << ' '; cout << '\n'; } void bin_src(int &le, int &ri) { while(le != ri) { int mid = (le + ri) / 2; if(check(mid) == false) le = mid + 1; else ri = mid; } } int main() { ios::sync_with_stdio(false); cin >> n; for(int i = 1; i <= n; i++) { cin >> a[i].first; a[i].second = i; } sort(a + 1, a + n + 1); int le = 1; int ri = n; bin_src(le, ri); check(le); cout << dp[n] << '\n'; printsol(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...