Submission #236768

# Submission time Handle Problem Language Result Execution time Memory
236768 2020-06-03T09:11:06 Z srvlt Rice Hub (IOI11_ricehub) C++14
100 / 100
41 ms 2688 KB
#include "ricehub.h"
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
 
#define ll long long
#define ull unsigned long long
#define db long double
#define pb push_back
#define ppb pop_back
#define F first
#define S second
#define mp make_pair
#define all(x) (x).begin(), (x).end()

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef vector <int> vi;
typedef vector <ll> vll;

typedef tree <pii, null_type, less <pii>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

const int max_N = 100003;
const ll INF = 1e18;
int n, x[max_N];

struct Set {
	deque <int> d;
	ll s = 0;
	void pb(int x) {
		d.pb(x);
		s += x;
	}
	void push_front(int x) {
		d.push_front(x);
		s += x;
	}
	int pop_front() {
		int x = d.front();
		s -= x;
		d.pop_front();
		return x;
	}
	ll sz() {
		return d.size();
	}
	void clear() {
		d.clear();
		s = 0;
	}
};

Set F, S;

void add(int x) {
	S.pb(x);
	if (F.sz() - S.sz() < 1) {
		F.pb(S.pop_front());
	}
}

void pop() {
	F.pop_front();
	if (F.sz() - S.sz() < 1) {
		F.pb(S.pop_front());
	}
}

ll get() {
	ll val = F.d.back();
	return (F.sz() * val - F.s) + (S.s - S.sz() * val);
}

ll f(int num) {
	F.clear(), S.clear();
	ll res = INF;
	for (int i = 1; i <= n; i++) {
		add(x[i]);
		if (i > num) {
			pop();
		}
		if (i >= num) {
			res = min(res, get());
		}
	}
	return res;
}

int besthub(int R, int L, int X[], ll B) {
	n = R;
	for (int i = 0; i < n; i++) {
		x[i + 1] = X[i];
	}
	int l = 1, r = R + 1;
	while (l < r - 1) {
		int mid = l + r >> 1;
		if (f(mid) <= B) {
			l = mid;
		}	else {
			r = mid;
		}
	}
	return l;
}

Compilation message

ricehub.cpp: In function 'int besthub(int, int, int*, long long int)':
ricehub.cpp:99:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   int mid = l + r >> 1;
             ~~^~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 4 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 4 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 4 ms 384 KB Output is correct
13 Correct 4 ms 384 KB Output is correct
14 Correct 4 ms 384 KB Output is correct
15 Correct 4 ms 384 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 4 ms 384 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
19 Correct 5 ms 384 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 5 ms 384 KB Output is correct
22 Correct 5 ms 384 KB Output is correct
23 Correct 5 ms 384 KB Output is correct
24 Correct 5 ms 384 KB Output is correct
25 Correct 4 ms 384 KB Output is correct
26 Correct 5 ms 384 KB Output is correct
27 Correct 5 ms 384 KB Output is correct
28 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
19 Correct 5 ms 512 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 6 ms 384 KB Output is correct
22 Correct 6 ms 384 KB Output is correct
23 Correct 6 ms 384 KB Output is correct
24 Correct 6 ms 512 KB Output is correct
25 Correct 6 ms 512 KB Output is correct
26 Correct 6 ms 384 KB Output is correct
27 Correct 6 ms 384 KB Output is correct
28 Correct 6 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 640 KB Output is correct
2 Correct 13 ms 640 KB Output is correct
3 Correct 37 ms 2560 KB Output is correct
4 Correct 37 ms 2560 KB Output is correct
5 Correct 27 ms 1152 KB Output is correct
6 Correct 29 ms 1152 KB Output is correct
7 Correct 39 ms 2304 KB Output is correct
8 Correct 34 ms 2304 KB Output is correct
9 Correct 26 ms 1152 KB Output is correct
10 Correct 25 ms 1152 KB Output is correct
11 Correct 40 ms 2560 KB Output is correct
12 Correct 39 ms 2688 KB Output is correct
13 Correct 26 ms 1152 KB Output is correct
14 Correct 29 ms 1272 KB Output is correct
15 Correct 31 ms 2048 KB Output is correct
16 Correct 30 ms 2048 KB Output is correct
17 Correct 38 ms 2408 KB Output is correct
18 Correct 34 ms 2408 KB Output is correct
19 Correct 37 ms 2432 KB Output is correct
20 Correct 41 ms 2536 KB Output is correct