# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
871819 |
2023-11-11T16:14:48 Z |
dsyz |
Rice Hub (IOI11_ricehub) |
C++17 |
|
12 ms |
2916 KB |
#include <bits/stdc++.h>
#include "ricehub.h"
using namespace std;
using ll = long long;
#define MAXN (1000005)
int besthub(int R, int L, int X[], long long B){
ll maximum = 0;
ll Lptr = 0;
ll Rptr = 0;
ll curcost = 0;
while(Lptr > 0 && curcost + abs(X[0] - X[Lptr - 1]) <= B){
curcost += abs(X[0] - X[Lptr - 1]);
Lptr--;
}
while(Rptr < R - 1 && curcost + abs(X[0] - X[Rptr + 1]) <= B){
curcost += abs(X[0] - X[Rptr + 1]);
Rptr++;
}
maximum = max(maximum,Rptr - Lptr + 1);
for(ll pos = 1;pos < R;pos++){
if(Rptr >= pos){
curcost += ((pos - Lptr) * abs(X[pos] - X[pos - 1]));
curcost -= ((Rptr - pos + 1) * abs(X[pos] - X[pos - 1]));
}else{
curcost += ((pos - Lptr) * abs(X[pos] - X[pos - 1]));
while(Rptr < pos){
Rptr++;
curcost += abs(X[pos] - X[Rptr]);
}
}
while(Lptr < pos && curcost > B){
curcost -= abs(X[pos] - X[Lptr]);
Lptr++;
}
while(Rptr < R - 1 && curcost + abs(X[pos] - X[Rptr + 1]) <= B){
curcost += abs(X[pos] - X[Rptr + 1]);
Rptr++;
}
while(Lptr + 1 <= pos && Rptr < R - 1 && abs(X[pos] - X[Lptr]) > abs(X[pos] - X[Rptr + 1])){
curcost -= abs(X[pos] - X[Lptr]);
curcost += abs(X[pos] - X[Rptr + 1]);
Lptr++;
Rptr++;
while(Rptr < R - 1 && curcost + abs(X[pos] - X[Rptr + 1]) <= B){
curcost += abs(X[pos] - X[Rptr + 1]);
Rptr++;
}
}
maximum = max(maximum,Rptr - Lptr + 1);
}
return maximum;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
504 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
440 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
600 KB |
Output is correct |
20 |
Correct |
0 ms |
344 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
26 |
Correct |
0 ms |
348 KB |
Output is correct |
27 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
28 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
19 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
344 KB |
Output is correct |
2 |
Correct |
2 ms |
348 KB |
Output is correct |
3 |
Correct |
9 ms |
2648 KB |
Output is correct |
4 |
Correct |
10 ms |
2648 KB |
Output is correct |
5 |
Correct |
4 ms |
2916 KB |
Output is correct |
6 |
Correct |
5 ms |
2664 KB |
Output is correct |
7 |
Correct |
8 ms |
2688 KB |
Output is correct |
8 |
Correct |
10 ms |
2676 KB |
Output is correct |
9 |
Correct |
4 ms |
2652 KB |
Output is correct |
10 |
Correct |
4 ms |
2652 KB |
Output is correct |
11 |
Correct |
9 ms |
2648 KB |
Output is correct |
12 |
Correct |
12 ms |
2648 KB |
Output is correct |
13 |
Correct |
5 ms |
2652 KB |
Output is correct |
14 |
Correct |
5 ms |
2544 KB |
Output is correct |
15 |
Correct |
7 ms |
2632 KB |
Output is correct |
16 |
Correct |
7 ms |
2648 KB |
Output is correct |
17 |
Correct |
8 ms |
2652 KB |
Output is correct |
18 |
Correct |
9 ms |
2652 KB |
Output is correct |
19 |
Correct |
9 ms |
2532 KB |
Output is correct |
20 |
Correct |
9 ms |
2652 KB |
Output is correct |