답안 #155836

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
155836 2019-09-30T18:14:14 Z m1sch3f 쌀 창고 (IOI11_ricehub) C++17
17 / 100
268 ms 1912 KB

#include <bits/stdc++.h>
using namespace std;

// types - only for stuff used a lot 
using ll = long long;
#define vv vector
#define Pp pair

// IO
#define get(x) scanf("%d",&x)
#define getl(x) scanf("%lld",&x);

// Operations
#define pb push_back
#define pob pop_back
#define sz(a) int(a.size()) 
#define re(a,b) a=max(a,b) // relax
#define ri(a,b) a=min(a,b) // relaxi

// Debugging

#ifndef LOCAL
#define cerr if (0) cerr
#else
#define cerr cout
#endif

#define print(arr,n) {for (int _ = 0; _ < n; _++) cerr<<arr[_]<<" "; cerr << endl; }
#define printv(vec)  {for (int _ : vec) cerr<<_<<" "; cerr<<endl;}

const int mod = 1e9+7, oo = 1e9;
const ll loo = 1e18;

// Functions 
ll modpow(ll a, ll b) {
	ll ans = 1; // faster modpow than recursive
	for (; b; b/=2,a=a*a%mod)
		if (b&1) ans = (ans*a)%mod;
	return ans;
}
ll gcd(ll a, ll b) {
	while (a) b%=a,swap(a,b);
	return b;
}
#define bitcount __builtin_popcountll
#define f(i,a,b) for (int i = a; i < b; i++)
#define fr(i,a,b) for (int i = b-1; i >= a; i--)


/* 

   ALRIGHT HACKERS, THIS IS WHERE THE ACTUAL CODE BEGINS

 */

const bool DEBUG = 1;

using pll = pair<ll,ll>;

int besthub(int N, int L, int rem[], ll B) {
	sort(rem,rem+N);
	ll C[N];
	f(i,0,N) C[i] = i?rem[i]+C[i-1]:rem[i];
	vector<int> X(N);
	f(i,0,N) X[i] = rem[i];
	auto sum = [&](int i, int j) {
		if (i>j) return 0LL;
		return C[j]-(i?C[i-1]:0);
	};
	auto fu = [&](int i, ll l) {
		// to the left
		int x = -distance(lower_bound(begin(X),end(X),X[i]-l),begin(X));
		int y = -distance(upper_bound(begin(X),end(X),X[i]+l),begin(X))-1;
		return pll(1LL*(2*i-x-y)*X[i]-sum(x,i-1)+
				sum(i+1,y),y-x+1);
	};
	ll ans = 1;
	f(i,0,N) {
		ll lo = 0, hi = L;		
		while (lo <= hi) {
			ll mid = (lo+hi)>>1;
			if (fu(i,mid).first <= B)
				lo = mid+1;
			else hi = mid-1;
		}
		re(ans,fu(i,hi).second);
	}	
	return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 376 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 256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 256 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 376 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 256 KB Output is correct
10 Correct 2 ms 256 KB Output is correct
11 Incorrect 2 ms 376 KB Output isn't correct
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 3 ms 376 KB Output is correct
4 Correct 3 ms 376 KB Output is correct
5 Incorrect 2 ms 256 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 54 ms 760 KB Output is correct
2 Correct 46 ms 676 KB Output is correct
3 Correct 178 ms 1912 KB Output is correct
4 Correct 268 ms 1912 KB Output is correct
5 Incorrect 64 ms 1144 KB Output isn't correct
6 Halted 0 ms 0 KB -