Submission #874964

#TimeUsernameProblemLanguageResultExecution timeMemory
874964StefanL2005Rice Hub (IOI11_ricehub)C++14
68 / 100
96 ms5980 KiB
#include <bits/stdc++.h> #include "ricehub.h" using namespace std; #define ll long long int search_end(int c1, int c2, int i, ll B, vector<ll> &Front_Sum, vector<ll> &Back_Sum, vector<int> &X, int CASE) { int ans = i; while (c1 <= c2) { int m = (c1 + c2) / 2; switch(CASE) { case 1:{ if (Front_Sum[m] - Front_Sum[i] - (m - i) * (X[i] - X[0]) > B) c2 = m - 1; else { ans = m; c1 = m + 1; } break; } case 2:{ if (Back_Sum[m] - Back_Sum[i] - (i - m) * (X[X.size() - 1] - X[i]) > B) c1 = m + 1; else { ans = m; c2 = m - 1; } break; } } } return ans; } int cautare_binara(int c1, int c2, int i, ll B, vector<ll> &Back_Sum, vector<int> &X) { int ans = i; while (c1 <= c2) { int m = (c1 + c2) / 2; ll sum2 = Back_Sum[m] - Back_Sum[i] - (i - m) * (X[X.size() - 1] - X[i]); if (sum2 > B) c1 = m + 1; else { ans = m; c2 = m - 1; } } return ans; } int besthub(int R, int L, int V[], ll B) { vector<int> X(R); vector<int> Best(R); vector<ll> Front_Sum(R, 0); vector<ll> Back_Sum(R, 0); for (int i = 0; i < R; i++) X[i] = V[i]; for (int i = 1; i < R; i++) Front_Sum[i] = Front_Sum[i - 1] + X[i] - X[0]; for (int i = R - 2; i >= 0; i--) Back_Sum [i]= Back_Sum[i + 1] + X[R - 1] - X[i]; for (int i = 0; i < R; i++) { int left = search_end(0, i, i, B, Front_Sum, Back_Sum, X, 2); int right = search_end(i, R - 1, i, B, Front_Sum, Back_Sum, X, 1); int c1 = i, c2 = right, ans = 1; while (c1 <= c2) { int m = (c1 + c2) / 2; ll sum = Front_Sum[m] - Front_Sum[i] - (m - i) * (X[i] - X[0]); int part = cautare_binara(left, i, i, B - sum, Back_Sum, X); ans = max(ans, m - part + 1); if (part - 1 >= 0 && X[i] - X[part - 1] < X[m] - X[i]) c2 = m - 1; else c1 = m + 1; } Best[i] = ans; } int Max = Best[0]; for (int i = 0; i < R; i++) Max = max(Max, Best[i]); return Max; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...