Submission #169977

# Submission time Handle Problem Language Result Execution time Memory
169977 2019-12-23T13:23:14 Z anubhavdhar Rice Hub (IOI11_ricehub) C++14
100 / 100
25 ms 1988 KB
#include<bits/stdc++.h>
 
#define ll long long int
#define ff first 
#define ss second
#define FOR(i,N) for(i=0;i<N;i++)
#define FORe(i,N) for(i=1;i<=N;i++)
#define FORr (i,a,b) for(i=a;i<b;i++)
#define vi vector <ll>
#define ii pair<ll,ll>
#define vii vector<ii>
#define mp make_pair
#define pb push_back
 
#include "ricehub.h"
 
using namespace std;
 
/*
const ll MAXN = 1e5+ 4;
const ll LOGN = 17;
const ll ROOTN = 320;
const ll MOD = 1e9+7;
const ll INF = 1e17+8;
*/
 
long long cost(int N,int X[],int num)
{
	//cout<<"getting in for num = "<<num<<endl;
	ll i,j,k,sum = 0,ans;
	FOR(i,num)
		sum += X[i] - X[0];
	ans = sum;
	//cout<<"precomputed ans = "<<ans<<endl;
	i = 0;
	j = num - 1;
	k = 1;
	while(k < N)
	{
		//cout<<"entered while loop for i = "<<i<<"; j = "<<j<<"; k = "<<k<<endl;
		sum += (k - i)*(X[k] - X[k-1]) - (j - k + 1)*(X[k] - X[k-1]);
		if (k > j)
		{
			j++;
			i++;
			sum -= X[k]-X[i-1];
		}
		while(j < N-1 and i < k and (X[j+1] - X[k]) < (X[k] - X[i]))
		{
			sum += (X[j+1] - X[k]) - (X[k] - X[i]);
			j++;
			i++;
		}
		//cout<<"calculated sum = "<<sum<<endl;
		ans = min(sum,ans);
		k++;
	}
	return ans;
}
 
int besthub(int R,int L,int X[],long long B)
{
	ll hi = R,lo = 1,mid = 0;
	if (cost(R,X,R) <= B)
		return R;
	while(lo < hi-1)
	{
		mid = (hi+lo)/2;
		if (cost(R,X,mid) > B)
			hi = mid;
		else
			lo = mid;
	}
	return lo;
}
/*
int main()
{
	
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	
	ll L,B,R;
	cin>>R>>L;
	ll i,X[R];
	FOR(i,R)
		cin>>X[i];
	cin>>B;
	cout<<besthub(R,L,X,B);
	return 0;
}
*/
# Verdict Execution time Memory Grader output
1 Correct 2 ms 504 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 252 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 256 KB Output is correct
9 Correct 2 ms 256 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 256 KB Output is correct
12 Correct 2 ms 256 KB Output is correct
13 Correct 2 ms 256 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 380 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 256 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 2 ms 256 KB Output is correct
25 Correct 3 ms 376 KB Output is correct
26 Correct 2 ms 380 KB Output is correct
27 Correct 2 ms 316 KB Output is correct
28 Correct 2 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 504 KB Output is correct
2 Correct 2 ms 504 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Correct 2 ms 380 KB Output is correct
8 Correct 2 ms 256 KB Output is correct
9 Correct 2 ms 256 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 256 KB Output is correct
15 Correct 2 ms 380 KB Output is correct
16 Correct 2 ms 380 KB Output is correct
17 Correct 2 ms 380 KB Output is correct
18 Correct 3 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 3 ms 376 KB Output is correct
22 Correct 3 ms 376 KB Output is correct
23 Correct 3 ms 376 KB Output is correct
24 Correct 3 ms 376 KB Output is correct
25 Correct 3 ms 380 KB Output is correct
26 Correct 3 ms 380 KB Output is correct
27 Correct 3 ms 380 KB Output is correct
28 Correct 3 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 504 KB Output is correct
2 Correct 6 ms 504 KB Output is correct
3 Correct 18 ms 1784 KB Output is correct
4 Correct 24 ms 1988 KB Output is correct
5 Correct 12 ms 888 KB Output is correct
6 Correct 16 ms 888 KB Output is correct
7 Correct 15 ms 1528 KB Output is correct
8 Correct 21 ms 1528 KB Output is correct
9 Correct 12 ms 764 KB Output is correct
10 Correct 11 ms 888 KB Output is correct
11 Correct 20 ms 1784 KB Output is correct
12 Correct 25 ms 1784 KB Output is correct
13 Correct 19 ms 988 KB Output is correct
14 Correct 20 ms 888 KB Output is correct
15 Correct 15 ms 1400 KB Output is correct
16 Correct 20 ms 1400 KB Output is correct
17 Correct 18 ms 1656 KB Output is correct
18 Correct 23 ms 1784 KB Output is correct
19 Correct 19 ms 1656 KB Output is correct
20 Correct 25 ms 1784 KB Output is correct