#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())
#ifdef wiwihorz
#define print(a...) cerr << "Line " << __LINE__ << ": ", kout("[" + string(#a) + "] = ", a)
void vprint(auto L, auto R) {while(L < R) cerr << *L << " \n"[next(L) == R], ++L;}
void kout() { cerr << endl; }
template<class T1, class ... T2> void kout(T1 a, T2 ... e) { cerr << a << " ", kout(e...); }
#else
#define print(...) 0
#define vprint(...) 0
#endif
ll n, val;
vector<ll> a, pre;
pii get_val(int x, int 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;
}
print(i, val, B - cc, r, val2 - val);
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:25:17: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
25 | void vprint(auto L, auto R) {while(L < R) cerr << *L << " \n"[next(L) == R], ++L;}
| ^~~~
ricehub.cpp:25:25: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
25 | void vprint(auto L, auto R) {while(L < R) cerr << *L << " \n"[next(L) == R], ++L;}
| ^~~~
ricehub.cpp: In function 'int besthub(int, int, int*, long long int)':
ricehub.cpp:24:66: warning: 'cc' may be used uninitialized in this function [-Wmaybe-uninitialized]
24 | #define print(a...) cerr << "Line " << __LINE__ << ": ", kout("[" + string(#a) + "] = ", a)
| ^
ricehub.cpp:65:32: note: 'cc' was declared here
65 | ll cost, cnt, val, val2, cc;
| ^~
ricehub.cpp:24:66: warning: 'val2' may be used uninitialized in this function [-Wmaybe-uninitialized]
24 | #define print(a...) cerr << "Line " << __LINE__ << ": ", kout("[" + string(#a) + "] = ", a)
| ^
ricehub.cpp:65:26: note: 'val2' was declared here
65 | ll cost, cnt, val, val2, cc;
| ^~~~
ricehub.cpp:73:26: warning: 'val' may be used uninitialized in this function [-Wmaybe-uninitialized]
73 | ans = max(ans, val + min((B - cc) / r, val2 - val));
| ~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
3 ms |
204 KB |
Output is correct |
5 |
Correct |
3 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
308 KB |
Output is correct |
3 |
Correct |
2 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
2 ms |
204 KB |
Output is correct |
6 |
Correct |
2 ms |
204 KB |
Output is correct |
7 |
Correct |
3 ms |
204 KB |
Output is correct |
8 |
Correct |
3 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
2 ms |
204 KB |
Output is correct |
12 |
Correct |
2 ms |
204 KB |
Output is correct |
13 |
Correct |
2 ms |
204 KB |
Output is correct |
14 |
Correct |
2 ms |
204 KB |
Output is correct |
15 |
Correct |
3 ms |
204 KB |
Output is correct |
16 |
Correct |
3 ms |
204 KB |
Output is correct |
17 |
Correct |
2 ms |
204 KB |
Output is correct |
18 |
Correct |
2 ms |
204 KB |
Output is correct |
19 |
Correct |
3 ms |
204 KB |
Output is correct |
20 |
Correct |
3 ms |
204 KB |
Output is correct |
21 |
Correct |
13 ms |
332 KB |
Output is correct |
22 |
Correct |
13 ms |
332 KB |
Output is correct |
23 |
Correct |
13 ms |
332 KB |
Output is correct |
24 |
Correct |
13 ms |
332 KB |
Output is correct |
25 |
Correct |
13 ms |
328 KB |
Output is correct |
26 |
Correct |
15 ms |
316 KB |
Output is correct |
27 |
Correct |
14 ms |
328 KB |
Output is correct |
28 |
Correct |
17 ms |
320 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
204 KB |
Output is correct |
2 |
Correct |
5 ms |
204 KB |
Output is correct |
3 |
Correct |
25 ms |
332 KB |
Output is correct |
4 |
Correct |
30 ms |
356 KB |
Output is correct |
5 |
Correct |
17 ms |
328 KB |
Output is correct |
6 |
Correct |
16 ms |
328 KB |
Output is correct |
7 |
Correct |
26 ms |
364 KB |
Output is correct |
8 |
Correct |
26 ms |
332 KB |
Output is correct |
9 |
Correct |
15 ms |
332 KB |
Output is correct |
10 |
Correct |
17 ms |
332 KB |
Output is correct |
11 |
Correct |
21 ms |
332 KB |
Output is correct |
12 |
Correct |
22 ms |
344 KB |
Output is correct |
13 |
Correct |
26 ms |
332 KB |
Output is correct |
14 |
Correct |
27 ms |
380 KB |
Output is correct |
15 |
Correct |
13 ms |
336 KB |
Output is correct |
16 |
Correct |
13 ms |
312 KB |
Output is correct |
17 |
Correct |
21 ms |
460 KB |
Output is correct |
18 |
Correct |
22 ms |
348 KB |
Output is correct |
19 |
Correct |
26 ms |
396 KB |
Output is correct |
20 |
Correct |
26 ms |
380 KB |
Output is correct |
21 |
Correct |
131 ms |
616 KB |
Output is correct |
22 |
Correct |
131 ms |
704 KB |
Output is correct |
23 |
Correct |
127 ms |
660 KB |
Output is correct |
24 |
Correct |
132 ms |
636 KB |
Output is correct |
25 |
Correct |
133 ms |
716 KB |
Output is correct |
26 |
Correct |
147 ms |
724 KB |
Output is correct |
27 |
Correct |
136 ms |
696 KB |
Output is correct |
28 |
Correct |
132 ms |
724 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
536 ms |
1904 KB |
Output is correct |
2 |
Correct |
544 ms |
1920 KB |
Output is correct |
3 |
Execution timed out |
1092 ms |
5572 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |