답안 #28765

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
28765 2017-07-16T23:10:41 Z h0ngjun7 쌀 창고 (IOI11_ricehub) C++14
0 / 100
3 ms 5020 KB
#include "ricehub.h"

int besthub(int R, int L, int X[], long long B)
{
	int l = 0, r = R, ans = 0;
	while (l <= r) {
		int m = (l + r) / 2;
		long long dist = 0;
		int left, right, mid, ok = 0;
		int ln = 0, rn = 0;
		for (int i = 0; i < R && !ok; i++) {
			if (i + 1 == m) {
				left = (i + 1) - m, right = i;
				mid = (left + right) / 2;
				for (int j = left; j < mid; j++) dist += X[mid] - X[j], ln++;
				for (int j = mid + 1; j <= right; j++) dist += X[j] - X[mid], rn++;
				if (dist <= B) ok = 1;
			}
			else if (i + 1 > m) {
				dist -= X[left + 1] - X[left]; left++;
				dist += 1LL * (X[mid + 1] - X[mid]) * (ln - rn); mid++;
				dist += X[right + 1] - X[right]; right++;
				if (dist <= B) ok = 1;
			}
		}
		if (ok) {
			if (ans < m) ans = m;
			l = m + 1;
		}
		else r = m - 1;
	}
	return ans;
}

Compilation message

ricehub.cpp: In function 'int besthub(int, int, int*, long long int)':
ricehub.cpp:21:59: warning: 'mid' may be used uninitialized in this function [-Wmaybe-uninitialized]
     dist += 1LL * (X[mid + 1] - X[mid]) * (ln - rn); mid++;
                                                           ^
ricehub.cpp:22:45: warning: 'right' may be used uninitialized in this function [-Wmaybe-uninitialized]
     dist += X[right + 1] - X[right]; right++;
                                             ^
ricehub.cpp:20:42: warning: 'left' may be used uninitialized in this function [-Wmaybe-uninitialized]
     dist -= X[left + 1] - X[left]; left++;
                                          ^
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 5020 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 5020 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 5020 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 5020 KB Output isn't correct
2 Halted 0 ms 0 KB -