Submission #1003143

# Submission time Handle Problem Language Result Execution time Memory
1003143 2024-06-20T06:42:48 Z coolboy19521 Rice Hub (IOI11_ricehub) C++17
0 / 100
3 ms 600 KB
#include "bits/stdc++.h"
#include "ricehub.h"
#define i64 long long
 
using namespace std;
 
const int sz = 2e5 + 10;
 
int a[sz];
int n;
i64 b;
 
bool che(int x) {
	int ra = x / 2;
	int ps = ra;
	i64 sm = 0;
	for (int i = 0; i < x; i ++) {
		sm += abs(a[i] - a[ps]);
	}
	// cout << x << ' ' << ps << ' ' << sm << '\n';
	if (sm <= b) {
		return true;
	}
	ps ++;
	for (; ps < n - ra + !(x % 2); ps ++) {
		int pps = ps - 1; // previous ps
		sm -= abs(a[pps - ra] - a[pps]); // delete leftmost
		sm += abs(a[ps + ra - !(x % 2)] - a[ps]); // add rightmost
		// cout << x << ' ' << ps << ' ' << sm << '\n';
		if (sm <= b) {
			return true;
		}
	}
	return false;
}
 
int besthub(int R, int L, int X[], long long B)
{
	int le, ri;
	le = 0, ri = R + 1;
 
	for (int i = 0; i < R; i ++) {
		a[i] = X[i];
	}
 
	b = B;
	n = R;
 
	while (1 < ri - le) {
		int mi = le + (ri - le) / 2;

		if (che(mi)) {
			le = mi;
		} else {
			ri = mi;
		}
	}
 
	return le;
}
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 600 KB Output isn't correct
2 Halted 0 ms 0 KB -