Submission #977579

# Submission time Handle Problem Language Result Execution time Memory
977579 2024-05-08T07:20:46 Z Amaarsaa Rice Hub (IOI11_ricehub) C++14
0 / 100
3 ms 2648 KB
#include<bits/stdc++.h>
#include "ricehub.h"
using namespace std;
using ll = long long;
ll Pre[100005];
ll Sum(ll l, ll r) {
	if ( l == 0) return Pre[r];
	return Pre[r] - Pre[l - 1];
}
int besthub(int R, int L, int X[], long long B)	{
	ll s;
	int i, ans = 1, mn, l, r,lo, hi, mid;
	for (i = 0; i < R; i ++) {
		if ( i == 0) Pre[i] = X[i];
		else Pre[i] = Pre[i - 1] + X[i];
	}
	for (int i = 0; i + 1 < R; i ++) {
		if ( X[i + 1] - X[i] > B) continue;
		lo = 1;
		hi = min(i + 1, R - (i + 1)) + 1;
		while ( lo  < hi ) {
			mid = (lo +hi)/2;
			l = i - mid;
			r = i + mid + 1;
		//	cout << mid << " " <<l << " " << i << " " << i  + 1 << " " << r<<" " <<Sum(i + 1, r)  << " " << Sum(l, i) << endl;
			if ( Sum(i + 1, r) - Sum (l, i) <= B) lo = mid + 1;
			else hi = mid;
		}
		mid = lo  ;
	//	cout << mid << endl;
		
		l = i - mid ;
		r = i + mid + 1;
		s =  Sum(i + 1, r - 1) - Sum(l + 1, i) ;
	//	cout << l << " " << r <<" " << s << endl;
		mn = INT_MAX;
		if ( l >= 0) {
			mn = min(mn, X[i] - X[l]);
		}
		if ( r < R) {
			mn = min(mn, X[r] - X[i + 1]);
		}
		if (mn + s <= B) {
			ans = max(ans, r - l);
		}
		else ans = max(ans, r - l - 1);
	}
	return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2648 KB Output is correct
2 Incorrect 1 ms 2392 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Incorrect 1 ms 2396 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2392 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 2392 KB Output isn't correct
2 Halted 0 ms 0 KB -