Submission #874794

#TimeUsernameProblemLanguageResultExecution timeMemory
874794StefanL2005Rice Hub (IOI11_ricehub)C++14
68 / 100
1063 ms4956 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; } 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; for (int j = left; j <= i; j++) { ll sum2 = Back_Sum[j] - Back_Sum[i] - (i - j) * (X[X.size() - 1] - X[i]); if (sum + sum2 <= B) { part = j; break; } } // functie pentru cautare binara stanga 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; }

Compilation message (stderr)

ricehub.cpp: In function 'int cautare_binara(int, int, int, long long int, std::vector<long long int>&, std::vector<int>&)':
ricehub.cpp:49:13: warning: unused variable 'm' [-Wunused-variable]
   49 |         int m = (c1 + c2) / 2;
      |             ^
ricehub.cpp: In function 'int besthub(int, int, int*, long long int)':
ricehub.cpp:93:48: warning: 'part' may be used uninitialized in this function [-Wmaybe-uninitialized]
   93 |             if (part - 1 >= 0 && X[i] - X[part - 1] < X[m] - X[i])
      |                                           ~~~~~^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...