Submission #537049

# Submission time Handle Problem Language Result Execution time Memory
537049 2022-03-14T10:26:23 Z pavement Watching (JOI13_watching) C++17
50 / 100
1000 ms 15948 KB
#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);
}

Compilation message

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 time Memory Grader output
1 Correct 1 ms 596 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 312 KB Output is correct
4 Correct 1 ms 596 KB Output is correct
5 Correct 6 ms 692 KB Output is correct
6 Correct 6 ms 740 KB Output is correct
7 Correct 1 ms 596 KB Output is correct
8 Correct 2 ms 596 KB Output is correct
9 Correct 1 ms 596 KB Output is correct
10 Correct 4 ms 692 KB Output is correct
11 Correct 2 ms 596 KB Output is correct
12 Correct 3 ms 688 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
# Verdict Execution time Memory Grader output
1 Correct 10 ms 8268 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Execution timed out 1093 ms 15948 KB Time limit exceeded
4 Halted 0 ms 0 KB -