답안 #871812

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
871812 2023-11-11T15:56:18 Z dsyz 쌀 창고 (IOI11_ricehub) C++17
49 / 100
15 ms 3688 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++;
	}
	while(Rptr < R - 1 && abs(X[0] - X[Lptr]) > abs(X[0] - X[Rptr + 1])){
		curcost -= abs(X[0] - X[Lptr]);
		curcost += abs(X[0] - X[Rptr + 1]);
		Lptr++;
		Rptr++;
		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(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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 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 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 448 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 600 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 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 344 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 344 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 344 KB Output isn't correct
28 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 452 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 352 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 1 ms 600 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 352 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 344 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Incorrect 1 ms 348 KB Output isn't correct
19 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 604 KB Output is correct
2 Correct 2 ms 544 KB Output is correct
3 Correct 15 ms 3672 KB Output is correct
4 Correct 9 ms 3676 KB Output is correct
5 Correct 7 ms 2908 KB Output is correct
6 Correct 4 ms 2908 KB Output is correct
7 Correct 14 ms 3420 KB Output is correct
8 Correct 9 ms 3420 KB Output is correct
9 Correct 4 ms 2908 KB Output is correct
10 Correct 4 ms 2908 KB Output is correct
11 Correct 10 ms 3684 KB Output is correct
12 Correct 10 ms 3688 KB Output is correct
13 Correct 5 ms 2908 KB Output is correct
14 Correct 5 ms 2904 KB Output is correct
15 Correct 7 ms 3456 KB Output is correct
16 Correct 7 ms 3420 KB Output is correct
17 Correct 9 ms 3420 KB Output is correct
18 Correct 9 ms 3432 KB Output is correct
19 Correct 8 ms 3676 KB Output is correct
20 Correct 9 ms 3684 KB Output is correct