답안 #120230

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
120230 2019-06-24T03:20:41 Z joseacaz 쌀 창고 (IOI11_ricehub) C++17
0 / 100
5 ms 1152 KB
#include "ricehub.h"
#include <bits/stdc++.h>
#define MAXN 100005

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

int R, L, X[MAXN];
ll B, dist[MAXN], pre[MAXN], sum[MAXN];

bool solve ( int x )
{
	int mid;
	ll total;

	for ( int i = 1; i + x - 1 <= R; i++ )
	{
		mid = (i + (i + x - 1)) / 2;
		total = ((mid - i) * pre[mid]) - (sum[mid - 1] - sum[i - 1]);
		total+= ((i + x - 1 - mid) * pre[mid]) - (sum[i + x - 1] - sum[mid]);
		if ( total <= B )
			return 1;
	}
	return 0;
}

int besthub ( int _r, int _l, int _x[], ll _b )
{
	R = _r;
	L = _l;
	B = _b;
	for ( int i = 1; i <= R; i++ )
		X[i] = _x[i - 1];
	
	for ( int i = 0; i < R - 1; i++ )
		dist[i] = X[i + 1] - X[i];
	for ( int i = 0; i < R - 1; i++ )
		pre[i] = pre[i - 1] + dist[i];
	for ( int i = 0; i < R - 1; i++ )
		sum[i] = sum[i - 1] + pre[i];
	
	int s = 1, e = R - 1, mid, val, ans;
	while ( s <= e )
	{
		mid = (s + e) / 2;
		val = solve ( mid );
		
		if ( val )
			ans = mid, s = mid + 1;
		else
			e = mid - 1;
	}
	
	return ans;
}

Compilation message

ricehub.cpp: In function 'int besthub(int, int, int*, ll)':
ricehub.cpp:55:9: warning: 'ans' may be used uninitialized in this function [-Wmaybe-uninitialized]
  return ans;
         ^~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 1152 KB Output isn't correct
2 Halted 0 ms 0 KB -