Submission #871822

# Submission time Handle Problem Language Result Execution time Memory
871822 2023-11-11T16:19:05 Z dsyz Rice Hub (IOI11_ricehub) C++17
100 / 100
24 ms 2676 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){
	if(R <= 5000){
		ll maximum = 0;
		for(ll pos = 0;pos < R;pos++){
			ll Lptr = pos;
			ll Rptr = pos;
			ll curcost = 0;
			while(Lptr > 0 && curcost + abs(X[pos] - X[Lptr - 1]) <= B){
				curcost += abs(X[pos] - X[Lptr - 1]);
				Lptr--;
			}
			while(Rptr < R - 1 && curcost + abs(X[pos] - X[Rptr + 1]) <= B){
				curcost += abs(X[pos] - X[Rptr + 1]);
				Rptr++;
			}
			while(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;
	}else{
		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 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
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 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 344 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 1 ms 444 KB Output is correct
25 Correct 1 ms 344 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
# 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 1 ms 456 KB Output is correct
4 Correct 1 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 1 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 1 ms 344 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 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 1 ms 348 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 2 ms 348 KB Output is correct
20 Correct 1 ms 452 KB Output is correct
21 Correct 2 ms 344 KB Output is correct
22 Correct 3 ms 348 KB Output is correct
23 Correct 24 ms 460 KB Output is correct
24 Correct 22 ms 348 KB Output is correct
25 Correct 23 ms 532 KB Output is correct
26 Correct 22 ms 348 KB Output is correct
27 Correct 17 ms 348 KB Output is correct
28 Correct 17 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 348 KB Output is correct
2 Correct 2 ms 348 KB Output is correct
3 Correct 11 ms 2652 KB Output is correct
4 Correct 12 ms 2668 KB Output is correct
5 Correct 5 ms 2652 KB Output is correct
6 Correct 5 ms 2652 KB Output is correct
7 Correct 11 ms 2652 KB Output is correct
8 Correct 10 ms 2652 KB Output is correct
9 Correct 5 ms 2652 KB Output is correct
10 Correct 5 ms 2652 KB Output is correct
11 Correct 11 ms 2652 KB Output is correct
12 Correct 11 ms 2676 KB Output is correct
13 Correct 6 ms 2648 KB Output is correct
14 Correct 6 ms 2652 KB Output is correct
15 Correct 9 ms 2648 KB Output is correct
16 Correct 9 ms 2652 KB Output is correct
17 Correct 10 ms 2652 KB Output is correct
18 Correct 11 ms 2664 KB Output is correct
19 Correct 10 ms 2676 KB Output is correct
20 Correct 11 ms 2652 KB Output is correct