Submission #473457

# Submission time Handle Problem Language Result Execution time Memory
473457 2021-09-15T14:35:45 Z hhhhaura Rice Hub (IOI11_ricehub) C++14
Compilation error
0 ms 0 KB
#define wiwihorz
#include "ricehub.h"
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma loop-opt(on)
 
#define rep(i, a, b) for(int i = a; i <= b; i ++)
#define rrep(i, a, b) for(int i = b; i >= a; i --)
#define all(x) x.begin(), x.end()
#define ceil(a, b) ((a + b - 1) / (b))
 
#define INF 1000000000000000000
#define MOD 1000000007
#define eps (1e-9)
 
using namespace std;
 
#define ll long long int
#define lld long double
#define pii pair<ll, ll> 
#define random mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count())

ll n;
vector<ll> a, pre;
pii get_val(ll x, ll len) {
	ll L, R, ans = 0, cnt = 0;
	L = 0, R = x;
	while(R - L > 1) {
		int mid = (L + R) / 2;
		if(a[x] - a[mid] <= len) R = mid;
		else L = mid;
	}
	cnt += x - R + 1;
	ans += a[x] * (x - R + 1) - (pre[x] - pre[R - 1]);
	L = x, R = n + 1;
	while(R - L > 1) {
		int mid = (L + R) / 2;
		if(a[mid] - a[x] <= len) L = mid;
		else R = mid;
	}
	cnt += L - x;
	ans += pre[L] - pre[x] - (L - x) * a[x];
	return {cnt, ans};
}
int besthub(int R, int L, int X[], ll B) {
	n = R, val = B;
	a.assign(R + 1, 0);
	pre.assign(R + 1, 0);
	rep(i, 1, R) {
		a[i] = X[i - 1];
		pre[i] = pre[i - 1] + X[i - 1];
	}
	ll ans = 0; 
	rep(i, 1, R) {
		ll l = 0, r = L;
		ll cost, cnt, val, val2, cc;
		while(r - l > 1) {
			int mid = (l + r) / 2;
			if(tie(cnt, cost) = get_val(i, mid), 
				cost <= B) val = cnt, l = mid, cc = cost;
			else r = mid, val2 = cnt; 
		}
		ans = max(ans, val + min((B - cc) / r, val2 - val));
	}
	return ans;
}

Compilation message

ricehub.cpp:5: warning: ignoring '#pragma loop ' [-Wunknown-pragmas]
    5 | #pragma loop-opt(on)
      | 
ricehub.cpp: In function 'int besthub(int, int, int*, long long int)':
ricehub.cpp:46:9: error: 'val' was not declared in this scope
   46 |  n = R, val = B;
      |         ^~~