Submission #260475

#TimeUsernameProblemLanguageResultExecution timeMemory
260475tbzardHoliday (IOI14_holiday)C++14
30 / 100
5061 ms5496 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<int, pii> pipii; typedef pair<pii, int> piipi; typedef pair<pii, pii> piipii; #define mp make_pair #define fi first #define se second #define all(a) (a).begin(), (a).end() #define sz(a) (int)(a).size() #define eb emplace_back ll findMaxAttraction(int n, int start, int d, int attraction[]){ long long ans = 0; if(n <= 20){ for(int i=1;i<(1<<n);i++){ vector<int> b; int l = 1e9, r = 0; for(int j=0;j<n;j++){ if((i>>j)&1){ b.eb(j); l = min(l, j); r = max(r, j); } } int cost = 0; if(l <= start && start <= r) cost = min(abs(start-l + (r-l)), abs(r-start + (r-l))); else if(r <= start) cost = start-l; else cost = r-start; if(cost > d) continue; vector<int> c; for(int i=0;i<sz(b);i++){ int val = attraction[b[i]]; c.eb(val); } sort(all(c)); reverse(all(c)); ll res = 0; int cnt = 0; for(int i=0;i<sz(c);i++){ if(cnt < d-cost){ cnt++; res += c[i]; } } ans = max(ans, res); } } else if(start == 0){ multiset<int> mx1, mx2; long long res = 0; for(int i=0;i<n;i++){ mx1.insert(attraction[i]); while(sz(mx2) < d){ if(mx1.empty()) break; int val = *mx1.rbegin(); mx1.erase(--mx1.end()); res += val; mx2.insert(val); } while(sz(mx2) > d){ int val = *mx2.begin(); mx2.erase(mx2.begin()); res -= val; mx1.insert(val); } while(!mx1.empty() && !mx2.empty() && *mx1.rbegin() > *mx2.begin()){ int val1 = *mx1.rbegin(), val2 = *mx2.begin(); mx1.erase(--mx1.end()); mx2.erase(mx2.begin()); res -= val2; res += val1; mx1.insert(val2); mx2.insert(val1); } ans = max(ans, res); d--; if(d < 0) break; } } else{ for(int l=1;l<n;l++){ multiset<int> mx1, mx2; ll res = 0; for(int r=l;r<n;r++){ int cost = 0; if(l <= start && start <= r) cost = min(abs(start-l + (r-l)), abs(r-start + (r-l))); else if(r <= start) cost = start-l; else cost = r-start; mx1.insert(attraction[r]); while(sz(mx2) < d){ if(mx1.empty()) break; int val = *mx1.rbegin(); mx1.erase(--mx1.end()); res += val; mx2.insert(val); } while(sz(mx2) > d){ int val = *mx2.begin(); mx2.erase(mx2.begin()); res -= val; mx1.insert(val); } while(!mx1.empty() && !mx2.empty() && *mx1.rbegin() > *mx2.begin()){ int val1 = *mx1.rbegin(), val2 = *mx2.begin(); mx1.erase(--mx1.end()); mx2.erase(mx2.begin()); res -= val2; res += val1; mx1.insert(val2); mx2.insert(val1); } ans = max(ans, res); } } } return ans; }

Compilation message (stderr)

holiday.cpp: In function 'll findMaxAttraction(int, int, int, int*)':
holiday.cpp:95:21: warning: variable 'cost' set but not used [-Wunused-but-set-variable]
                 int cost = 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...