답안 #43670

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
43670 2018-03-19T09:54:54 Z baactree 쌀 창고 (IOI11_ricehub) C++14
0 / 100
8 ms 732 KB
#include "ricehub.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll b;
int r, l, x[100005];
bool possi(ll lcnt,ll rcnt) {
	ll ret = 0x3f3f3f3f3f3f3f3f;
	deque<int> le, ri;
	ll sum = 0;
	for (int i = 0; i < r; i++) {
		if (le.size() < lcnt) {
			le.push_back(i);
			sum -= x[i];
		}
		else if (ri.size() < rcnt) {
			ri.push_back(i);
			sum += x[i];
		}
		else {
			sum += x[le.front()];
			le.pop_front();
			sum -= x[ri.front()];
			sum -= x[ri.front()];
			le.push_back(ri.front());
			ri.pop_front();
			ri.push_back(i);
			sum += x[i];
		}
		if (le.size() == lcnt && ri.size() == rcnt) {
			ret = min(ret, sum + lcnt * x[i] - rcnt * x[i]);
		}
	}
	return ret <= b;
}
int besthub(int R, int L, int X[], long long B)
{
	r = R; l = L; b = B;
	for (int i = 0; i < r; i++) 
		x[i] = X[i];
	sort(x, x + r);
	int le, ri, mid, ans;
	ans = 1;
	le = 2;
	ri = r;
	while (le <= ri) {
		mid = (le + ri) / 2;
		if (possi(mid/2,mid-mid/2)) {
			ans = mid;
			le = mid + 1;
		}
		else
			ri = mid - 1;
	}
	return ans;
}

Compilation message

ricehub.cpp: In function 'bool possi(ll, ll)':
ricehub.cpp:12:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   if (le.size() < lcnt) {
                 ^
ricehub.cpp:16:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   else if (ri.size() < rcnt) {
                      ^
ricehub.cpp:30:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   if (le.size() == lcnt && ri.size() == rcnt) {
                 ^
ricehub.cpp:30:38: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   if (le.size() == lcnt && ri.size() == rcnt) {
                                      ^
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 248 KB Output is correct
2 Incorrect 1 ms 352 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 404 KB Output is correct
2 Correct 1 ms 404 KB Output is correct
3 Correct 1 ms 460 KB Output is correct
4 Correct 2 ms 532 KB Output is correct
5 Correct 2 ms 532 KB Output is correct
6 Incorrect 1 ms 532 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 604 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 8 ms 732 KB Output isn't correct
2 Halted 0 ms 0 KB -