Submission #1117026

# Submission time Handle Problem Language Result Execution time Memory
1117026 2024-11-22T18:48:32 Z Zflop Rice Hub (IOI11_ricehub) C++14
0 / 100
109 ms 3720 KB
#include <bits/stdc++.h>
using namespace std;
 
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
const int NMAX = (int)1e5 * 2;
int pref_val[NMAX],suf_val[NMAX];
int besthub(int R, int L, int X[], long long B) {
	int ans = 0;
	for (int i = 0; i < R;++i) {
		pref_val[i] = X[i];
		if (i) {
			pref_val[i] += pref_val[i - 1];
			} 
		}
	for (int i = R - 1; i >= 0;--i) {
		suf_val[i] = suf_val[i + 1] + L - X[i];
		}
	
	auto f = [&] (int li,int ri,int to_left){
		int k = ri - li + 1;
		int aux = B;
		if (to_left >= li) return k;
		aux = aux - ((suf_val[li - to_left] - suf_val[li]) - (L - X[li]) * to_left);
		if (aux < 0) return -1;
		k += to_left;
		
		int l = 0,r = R - ri;
		int len = 0;
		while (l <= r) {
			int mid = (l + r) / 2;
			if (pref_val[ri + mid] - pref_val[ri] - X[ri] * mid <= aux) {
				len = mid;
				l = mid + 1;
				}
			else 
				r = mid - 1;
			}
		k += len;
		return k;
		};
	for (int i = 0; i < R;++i) {
		int j = i;
		while (X[j] == X[j + 1]) ++j;
		int l = 0,r = i;
		while (l < r) {
			int mid = (l + r) / 2;
			int a = f(i,j,mid);
			int b = f(i,j,mid + 1);
			ans = max({ans,a,b});
			if (a > b)
				r = mid;
			else 
				l = mid + 1;
			}
		//cout << ans << '\n';
	}
	
	return ans;
	}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2384 KB Output is correct
2 Correct 1 ms 2384 KB Output is correct
3 Incorrect 1 ms 2384 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2552 KB Output is correct
2 Correct 1 ms 2384 KB Output is correct
3 Correct 1 ms 2384 KB Output is correct
4 Incorrect 1 ms 2552 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2384 KB Output is correct
2 Correct 1 ms 2384 KB Output is correct
3 Correct 2 ms 2552 KB Output is correct
4 Incorrect 1 ms 2384 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 2640 KB Output is correct
2 Correct 4 ms 2640 KB Output is correct
3 Correct 101 ms 3664 KB Output is correct
4 Incorrect 109 ms 3720 KB Output isn't correct
5 Halted 0 ms 0 KB -