Submission #684163

# Submission time Handle Problem Language Result Execution time Memory
684163 2023-01-20T15:03:41 Z sudheerays123 Rice Hub (IOI11_ricehub) C++17
68 / 100
240 ms 1748 KB
#include "ricehub.h"
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ll int
const ll N = 100+5 , INF = 1e9 , MOD = 1e9+7;

int besthub(int R, int L, int X[], long long B){

	ll low = 1 , high = R;
	ll ans;

	function<bool(ll)> check = [&](ll l){

		for(ll i = 1; i <= R-l+1; i++){
			ll j = i+l-1;
			ll mid = (i+j)/2;

			ll cost = 0;
			for(ll k = i; k <= j; k++) cost += abs(X[k]-X[mid]);

			if(cost <= B) return true;
		}

		return false;
	};

	while(low <= high){
		ll mid = (low+high)/2;
		if(check(mid)){
			ans = mid;
			low = mid+1;
		}
		else high = mid-1;
	}

	return ans;
}

Compilation message

ricehub.cpp: In function 'int besthub(int, int, int*, long long int)':
ricehub.cpp:37:9: warning: 'ans' may be used uninitialized in this function [-Wmaybe-uninitialized]
   37 |  return ans;
      |         ^~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 312 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 316 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 316 KB Output is correct
2 Correct 1 ms 316 KB Output is correct
3 Correct 0 ms 312 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 320 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 312 KB Output is correct
18 Correct 0 ms 320 KB Output is correct
19 Correct 0 ms 316 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 2 ms 316 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 320 KB Output is correct
13 Correct 1 ms 316 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 2 ms 312 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 320 KB Output is correct
18 Correct 1 ms 324 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 15 ms 340 KB Output is correct
22 Correct 15 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 2 ms 284 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 54 ms 340 KB Output is correct
28 Correct 53 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 240 ms 504 KB Output is correct
2 Correct 216 ms 512 KB Output is correct
3 Correct 14 ms 1748 KB Output is correct
4 Incorrect 14 ms 1732 KB Output isn't correct
5 Halted 0 ms 0 KB -