제출 #808836

#제출 시각아이디문제언어결과실행 시간메모리
808836htphong0909휴가 (IOI14_holiday)C++17
23 / 100
964 ms5932 KiB
#pragma GCC optimize("O3,unroll-loops") #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") #include <bits/stdc++.h> using namespace std; void File() { #define file "test" freopen(file".in", "r", stdin); freopen(file".out", "w", stdout); } set<pair<int, int>> chosen; set<pair<int, int>, greater<>> have; long long curSum = 0; int lt = 1; int rt = 0; int n, d, start; int du; int arr[100001]; long long ans = -1e18; int cnt = 0; void giveToHave() { cnt++; du++; pair <int, int> temp = *chosen.begin(); have.insert(temp); curSum -= temp.first; chosen.erase(temp); } void giveToChosen() { cnt++; du--; pair <int, int> temp = *have.begin(); chosen.insert(temp); curSum += temp.first; have.erase(temp); } void Add(int x) { cnt++; pair <int, int> temp = *chosen.begin(); if (du > 0) { du--; curSum += arr[x]; chosen.insert(make_pair(arr[x], x)); } else if (arr[x] > temp.first) { curSum -= temp.first; have.insert(temp); chosen.erase(temp); chosen.insert(make_pair(arr[x], x)); curSum += arr[x]; } else have.insert(make_pair(arr[x], x)); } void Del(int x) { if (chosen.find(make_pair(arr[x], x)) != chosen.end()) { chosen.erase(make_pair(arr[x], x)); curSum -= arr[x]; du++; if (!have.empty() && du > 0) giveToChosen(); } else have.erase(make_pair(arr[x], x)); } int calcDis(int l, int r) { cnt++; if (l > r) return 0; if (start <= l) return(l - start + (r - l)); if (start >= r) return(start - r + (r - l)); return (min(start - l, r - start) + (r - l)); } long long cost(int l, int r) { while (lt != l || rt != r) { while (rt < r) { du += calcDis(lt, rt) - calcDis(lt, rt + 1); rt++; Add(rt); while (du < 0 && !chosen.empty()) giveToHave(); while (du > 0 && !have.empty()) giveToChosen(); } while (rt > lt && rt > r) { du += calcDis(lt, rt) - calcDis(lt, rt - 1); Del(rt); rt--; while (du < 0 && !chosen.empty()) giveToHave(); while (du > 0 && !have.empty()) giveToChosen(); } while (lt < rt && lt < l) { du += calcDis(lt, rt) - calcDis(lt + 1, rt); Del(lt); lt++; while (du < 0 && !chosen.empty()) giveToHave(); while (du > 0 && !have.empty()) giveToChosen(); } while (lt > l) { du += calcDis(lt, rt) - calcDis(lt - 1, rt); lt--; Add(lt); while (du < 0 && !chosen.empty()) giveToHave(); while (du > 0 && !have.empty()) giveToChosen(); } } return curSum; } void divide(int l, int r, int gL, int gR) { if (l > r) return; int mid = (l + r) / 2; long long bestCost = -1e18; int bestPos = gL; for (int i = gL; i <= min(mid, gR); i++) { if (cost(i, mid) > bestCost) { bestCost = cost(i, mid); bestPos = i; } } ans = max(ans, bestCost); divide(l, mid - 1, gL, bestPos); divide(mid + 1, r, bestPos, gR); } long long findMaxAttraction(int _n, int _start, int _d, int *attraction) { n = _n; d = _d; start = _start + 1; for (int i = 1; i <= n; i++) arr[i] = attraction[i - 1]; du = d; divide(1, n, 1, n); return ans; } /* int32_t main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); File(); cin >> n >> start >> d; for (int i = 1; i <= n; i++) cin >> arr[i]; cout << findMaxAttraction(n, start, d, arr); cerr << cnt; return 0; }*/

컴파일 시 표준 에러 (stderr) 메시지

holiday.cpp: In function 'void File()':
holiday.cpp:9:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    9 |     freopen(file".in", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
holiday.cpp:10:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   10 |     freopen(file".out", "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...