Submission #860876

# Submission time Handle Problem Language Result Execution time Memory
860876 2023-10-14T16:59:15 Z Huseyn123 Rice Hub (IOI11_ricehub) C++17
100 / 100
20 ms 5724 KB
#include "ricehub.h"
#include <bits/stdc++.h>
#define MAX 200001
#define INF LLONG_MAX
#define MOD 1000000007
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define ins insert
#define ff first
#define ss second
#define gett(x,m) get<m>(x)
#define all(a) a.begin(),a.end()
#define lb(a,b) lower_bound(all(a),b)
#define ub(a,b) upper_bound(all(a),b)
#define sortv(a) sort(all(a))
#define sorta(a,sz) sort(a,a+sz)
#define inputar(a,b){\
    for(int i=0;i<b;i++){\
        cin >> a[i];\
    }\
}
#define inputvec(a,b){\
    for(int i=0;i<b;i++){\
        ll num;\
        cin >> num;\
        a.pb(num);\
    }\
}
#define outputar(a,b){\
    for(int i=0;i<b;i++){\
        cout << a[i] << " ";\
    }\
    cout << "\n";\
}
#define outputvec(a){\
    for(auto x:a){\
        cout << x << " ";\
    }\
    cout << "\n";\
}
#define reset(a,n,v){\
    for(int i=0;i<n;i++){\
        a[i]=v;\
    }\
}
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef tuple<ll,ll,ll> tll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef double db;
typedef long double ldb;
inline void USACO(string filename){
  freopen((filename+".in").c_str(),"r",stdin);
  freopen((filename+".out").c_str(),"w",stdout);
}
ll Y[MAX],Y1[MAX],n;
ll b;
ll f(ll h,ll x,ll y){
	ll res=0;
	ll h1=Y[h];
	if(x>0){
		h1-=Y[x-1];
	}
	ll h2=Y[y]-Y[h];
	res+=(h-x+1)*Y1[h]+h2-(y-h)*Y1[h]-h1;
	return res;
}
bool f1(ll h,ll h3){
	if(h3%2==0){
		if(h-h3/2+1>=0 && h+h3/2<n && f(h,h-h3/2+1,h+h3/2)<=b){
			//cout << h << " " << h3 << " " << 1 << "\n";
			return true;
		}
		if(h-h3/2>=0 && h+h3/2-1<n && f(h,h-h3/2,h+h3/2-1)<=b){
			//cout << h << " " << h3 << " " << 2 << "\n";
			return true;
		}
	}
	else{
		if(h-h3/2>=0 && h+h3/2<n && f(h,h-h3/2,h+h3/2)<=b){
			//cout << h << " " << h3 << " " << 3 << "\n";
			return true;
		}
	}
	return false;
}
int besthub(int R, int L, int X[], long long B)
{
	b=B;
	n=R;
	for(int i=0;i<R;i++){
		Y[i]=X[i];
		Y1[i]=X[i];
	}
	for(int i=1;i<R;i++){
		Y[i]+=Y[i-1];
	}
	int res=0;
	for(int i=0;i<R;i++){
		int l,r; 
		l=0,r=R; 
		while(l<r){
			ll mid=(l+r+1)/2;
			if(f1(i,mid)){
				l=mid;
			}
			else{
				r=mid-1;
			}
		}
		res=max(res,l);
		//cout << i << " " << l << "\n";
	}
	return res;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 1 ms 4444 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 1 ms 4444 KB Output is correct
20 Correct 1 ms 4444 KB Output is correct
21 Correct 1 ms 4444 KB Output is correct
22 Correct 1 ms 4444 KB Output is correct
23 Correct 1 ms 4444 KB Output is correct
24 Correct 1 ms 4444 KB Output is correct
25 Correct 1 ms 4444 KB Output is correct
26 Correct 1 ms 4444 KB Output is correct
27 Correct 1 ms 4696 KB Output is correct
28 Correct 1 ms 4444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4440 KB Output is correct
5 Correct 1 ms 4696 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 1 ms 4444 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 1 ms 4440 KB Output is correct
20 Correct 1 ms 4444 KB Output is correct
21 Correct 2 ms 4444 KB Output is correct
22 Correct 1 ms 4440 KB Output is correct
23 Correct 1 ms 4444 KB Output is correct
24 Correct 1 ms 4444 KB Output is correct
25 Correct 1 ms 4444 KB Output is correct
26 Correct 1 ms 4444 KB Output is correct
27 Correct 2 ms 4444 KB Output is correct
28 Correct 2 ms 4444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 4700 KB Output is correct
2 Correct 5 ms 4700 KB Output is correct
3 Correct 19 ms 4700 KB Output is correct
4 Correct 19 ms 4700 KB Output is correct
5 Correct 9 ms 4956 KB Output is correct
6 Correct 9 ms 4956 KB Output is correct
7 Correct 19 ms 5468 KB Output is correct
8 Correct 19 ms 5492 KB Output is correct
9 Correct 8 ms 4956 KB Output is correct
10 Correct 8 ms 4956 KB Output is correct
11 Correct 20 ms 5548 KB Output is correct
12 Correct 20 ms 5676 KB Output is correct
13 Correct 9 ms 4952 KB Output is correct
14 Correct 9 ms 5212 KB Output is correct
15 Correct 15 ms 5468 KB Output is correct
16 Correct 15 ms 5504 KB Output is correct
17 Correct 18 ms 5464 KB Output is correct
18 Correct 17 ms 5668 KB Output is correct
19 Correct 19 ms 5468 KB Output is correct
20 Correct 19 ms 5724 KB Output is correct