# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
207536 |
2020-03-07T19:31:44 Z |
robs |
Rice Hub (IOI11_ricehub) |
C++17 |
|
7 ms |
504 KB |
#include "ricehub.h"
#include <bits/stdc++.h>
#define debug(args...) //fprintf(stderr, args)
typedef long long int lli;
using namespace std;
const int maxn = 2e5;
int s[maxn],cs[maxn],I,J,SUM;
int besthub(int R, int L, int X[], long long int B)
{
s[0] = X[0];
for(int x = 1; x < R; x++)
s[x] = s[x-1] + X[x];
cs[R-1] = 0;
// debug("R-1 = %d\n",R-1);
for(int x = R-2; x >= 0; x--)
cs[x] = cs[x+1] + X[R-1] - X[x];
// for(int x = 0; x < R; x++)
// debug("cs[%d] = %d, dist = %d\n",x,cs[x],X[R-1]-X[x]);
debug("\n\n");
int i = 0;
int j = 0;
lli resp = 0;
while(j < R)
{
int med = (i + j) / 2;
lli sumEsq = (cs[i] - cs[med]) - ((med - i)*(X[R-1] - X[med]));
debug("%d - %d:\nsumEsq = %d = (%d-%d) - ((%d-%d)*(%d-%d))\n\n",i,j,sumEsq,cs[i],cs[med],med,i,X[R-1],X[med]);
lli sumDir = (s[j] - s[med]) - ((j - med)*(X[med] - X[0]));
lli sum = sumEsq + sumDir;
lli r = j - i + 1;
debug("%d - %d(%d) %d %d -%d-\n",i,j,sum,sumEsq,sumDir,med);
if(sum <= B)
{
resp = max(resp, r);
j++;
}
else if(i == j)
{
j++;
}
else i++;
}
return resp;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Incorrect |
5 ms |
376 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
376 KB |
Output is correct |
4 |
Correct |
4 ms |
376 KB |
Output is correct |
5 |
Incorrect |
5 ms |
376 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
4 ms |
376 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
7 ms |
504 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |