답안 #537050

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
537050 2022-03-14T10:27:00 Z pavement 구경하기 (JOI13_watching) C++17
50 / 100
1000 ms 15868 KB
#include <bits/stdc++.h>
using namespace std;

#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")

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);
}

Compilation message

watching.cpp: In function 'int main()':
watching.cpp:11:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   11 |  scanf("%d%d%d", &n, &p, &q);
      |  ~~~~~^~~~~~~~~~~~~~~~~~~~~~
watching.cpp:13:35: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 |  for (int i = 0; i < n; i++) scanf("%d", &a[i]);
      |                              ~~~~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 596 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 596 KB Output is correct
5 Correct 5 ms 740 KB Output is correct
6 Correct 4 ms 724 KB Output is correct
7 Correct 1 ms 596 KB Output is correct
8 Correct 2 ms 704 KB Output is correct
9 Correct 1 ms 596 KB Output is correct
10 Correct 3 ms 724 KB Output is correct
11 Correct 2 ms 596 KB Output is correct
12 Correct 3 ms 724 KB Output is correct
13 Correct 1 ms 596 KB Output is correct
14 Correct 1 ms 596 KB Output is correct
15 Correct 1 ms 596 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 8344 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Execution timed out 1101 ms 15868 KB Time limit exceeded
4 Halted 0 ms 0 KB -