#include <bits/stdc++.h>
#include "ricehub.h"
using namespace std;
int findResp(int& R, int& L, int X[], long long& B, int i)
{
int p = i; int q = i+1;
long long sum = 0; int respi = 0;
while (p >= 0 && q < R)
{
long long desq = abs(X[i] - X[p]); long long ddir = abs(X[q] - X[i]);
if (desq < ddir)
{
if (sum + desq > B) break;
sum += desq;
p--;
respi++;
}
else
{
if (sum + ddir > B) break;
sum += ddir;
q++;
respi++;
}
}
while (p >= 0)
{
long long desq = abs(X[i] - X[p]);
if (sum + desq > B) break;
sum += desq;
p--;
respi++;
}
while (q < R)
{
long long ddir = abs(X[q] - X[i]);
if (sum + ddir > B) break;
sum += ddir;
q++;
respi++;
}
// cerr << i << " " << sum << " " << respi << '\n';
return respi;
}
int besthub(int R, int L, int X[], long long B)
{
int resp = 0;
int p = 0; int q = 0; long long sum = 0;
for (int i = 0; i < R; i++)
{
// cerr << p << " " << q << " " << sum << '\n';
while (sum > B)
{
long long desq = abs(X[i] - X[p]); long long ddir = abs(X[q] - X[i]);
if (desq >= ddir) {sum -= desq; p++;}
else {sum -= ddir; q--;}
}
while (p >= 0 && q < R)
{
long long desq = (p > 0) ? abs(X[i] - X[p-1]) : (long long)(1e18 + 10);
long long ddir = (q < R-1) ? abs(X[q+1] - X[i]) : (long long)(1e18 + 10);
if (desq < ddir)
{
if (sum + desq > B) break;
sum += desq;
p--;
}
else
{
if (sum + ddir > B) break;
sum += ddir;
q++;
}
}
while (p >= 0)
{
long long desq = (p > 0) ? abs(X[i] - X[p-1]) : (long long)(1e18 + 10);
if (sum + desq > B) break;
sum += desq;
p--;
}
while (q < R)
{
long long ddir = (q < R-1) ? abs(X[q+1] - X[i]) : (long long)(1e18 + 10);
if (sum + ddir > B) break;
sum += ddir;
q++;
}
resp = max(resp, (q - p + 1));
if (p <= i && i+1 < R) sum += (long long)((min(i, q) - p + 1) * (abs(X[i+1] - X[i])));
if (q > i && i+1 < R) sum -= (long long)((q - max(i, p-1)) * (abs(X[i+1] - X[i])));
}
return resp;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
15 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
16 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
340 KB |
Output is correct |
2 |
Correct |
2 ms |
340 KB |
Output is correct |
3 |
Correct |
11 ms |
612 KB |
Output is correct |
4 |
Correct |
11 ms |
1740 KB |
Output is correct |
5 |
Correct |
5 ms |
840 KB |
Output is correct |
6 |
Correct |
6 ms |
840 KB |
Output is correct |
7 |
Correct |
10 ms |
1364 KB |
Output is correct |
8 |
Correct |
10 ms |
1400 KB |
Output is correct |
9 |
Correct |
6 ms |
796 KB |
Output is correct |
10 |
Correct |
5 ms |
724 KB |
Output is correct |
11 |
Correct |
15 ms |
1860 KB |
Output is correct |
12 |
Incorrect |
12 ms |
1744 KB |
Output isn't correct |
13 |
Halted |
0 ms |
0 KB |
- |