제출 #537049

#제출 시각아이디문제언어결과실행 시간메모리
537049pavement구경하기 (JOI13_watching)C++17
50 / 100
1093 ms15948 KiB
#include <bits/stdc++.h>
using namespace std;

int a[2005], dp[2005][2005];

int main() {
	int n, p, q;
	scanf("%d%d%d", &n, &p, &q);
	q = min(q, n);
	for (int i = 0; i < n; i++) scanf("%d", &a[i]);
	sort(a, a + n);
	int lo = 1, hi = a[n - 1] - a[0] + 1, ans = -1;
	while (lo <= hi) {
		int mid = (lo + hi) / 2;
		dp[0][0] = 1;
		for (int i = 1; i <= q; i++) dp[0][i] = 0;
		for (int i = 1; i < n; i++) {
			for (int j = 0; j <= q; j++) {
				int dpp = lower_bound(a, a + i + 1, a[i] - mid + 1) - a - 1,
					dpq = lower_bound(a, a + i + 1, a[i] - 2 * mid + 1) - a - 1;
				if (dpq < 0 && j) dp[i][j] = 0;
				else if (dpp < 0) dp[i][j] = 1;
				else if (j) dp[i][j] = min(dp[dpp][j] + 1, dp[dpq][j - 1]);
				else dp[i][j] = dp[dpp][0] + 1;
			}
		}
		if (dp[n - 1][q] <= p) ans = mid, hi = mid - 1;
		else lo = mid + 1;
	}
	printf("%d\n", ans);
}

컴파일 시 표준 에러 (stderr) 메시지

watching.cpp: In function 'int main()':
watching.cpp:8:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    8 |  scanf("%d%d%d", &n, &p, &q);
      |  ~~~~~^~~~~~~~~~~~~~~~~~~~~~
watching.cpp:10:35: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   10 |  for (int i = 0; i < n; i++) scanf("%d", &a[i]);
      |                              ~~~~~^~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...