Submission #205421

#TimeUsernameProblemLanguageResultExecution timeMemory
205421mode149256Rice Hub (IOI11_ricehub)C++14
100 / 100
21 ms1528 KiB
/*input */ #include <bits/stdc++.h> #include "ricehub.h" using namespace std; typedef long long ll; typedef long double ld; typedef complex<ld> cd; typedef pair<int, int> pi; typedef pair<ll, ll> pl; typedef pair<ld, ld> pd; typedef vector<int> vi; typedef vector<vi> vii; typedef vector<ld> vd; typedef vector<ll> vl; typedef vector<vl> vll; typedef vector<pi> vpi; typedef vector<vpi> vpii; typedef vector<pl> vpl; typedef vector<cd> vcd; typedef vector<pd> vpd; typedef vector<bool> vb; typedef vector<vb> vbb; typedef std::string str; typedef std::vector<str> vs; #define x first #define y second #define debug(...) cout<<"["<<#__VA_ARGS__<<": "<<__VA_ARGS__<<"]\n" const int MOD = 1000000007; const ll INF = std::numeric_limits<ll>::max(); const int MX = 100101; const ld PI = 3.14159265358979323846264338327950288419716939937510582097494L; template<typename T> pair<T, T> operator+(const pair<T, T> &a, const pair<T, T> &b) { return pair<T, T>(a.x + b.x, a.y + b.y); } template<typename T> pair<T, T> operator-(const pair<T, T> &a, const pair<T, T> &b) { return pair<T, T>(a.x - b.x, a.y - b.y); } template<typename T> T operator*(const pair<T, T> &a, const pair<T, T> &b) { return (a.x * b.x + a.y * b.y); } template<typename T> T operator^(const pair<T, T> &a, const pair<T, T> &b) { return (a.x * b.y - a.y * b.x); } template<typename T> void print(vector<T> vec, string name = "") { cout << name; for (auto u : vec) cout << u << ' '; cout << '\n'; } int besthub(int R, int L, int X[], ll B) { vl pref(R, 0); for (int i = 0; i < R; ++i) pref[i] = (i ? pref[i - 1] : 0) + X[i]; auto sum = [&](int a, int b) -> ll { return pref[b] - (a ? pref[a - 1] : 0); }; auto galima = [&](int K) -> bool { // printf("in galima, K = %d\n", K); for (int i = K - 1; i < R; ++i) { int l = i - K + 1; int r = i; int m = (l + r) / 2; if (K & 1) { ll mid = X[m]; ll reik = mid * (K / 2) - sum(l, m - 1); reik += sum(m + 1, r) - mid * (K / 2); // printf("i = %d, mid = %lld, reik = %lld\n", i, mid, reik); if (reik <= B) return true; } else { // K = 4 // K/2 = 2 // 0 1 2 3 ll mid = (X[m] + X[m + 1]); ll reik = mid * (K / 2) - 2 * sum(l, m); reik += 2 * sum(m + 1, r) - mid * (K / 2); if (reik <= 2 * B) return true; } } return false; }; int l = 1; int h = R; int m; // for (int i = 0; i < R; ++i) // printf("%d ", X[i]); // printf("\n"); // printf("B = %lld\n", B); while (l < h) { m = (l + h + 1) / 2; // printf("l = %d, m = %d, r = %d, galima = %d\n", // l, m, h, int(galima(m))); if (galima(m)) l = m; else h = m - 1; } return l; } /* Look for: * special cases (n=1?) * overflow (ll vs int?) * the exact constraints (multiple sets are too slow for n=10^6 :( ) * array bounds */
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...