Submission #39372

# Submission time Handle Problem Language Result Execution time Memory
39372 2018-01-13T06:41:01 Z 14kg Watching (JOI13_watching) C++11
100 / 100
193 ms 16764 KB
#include <stdio.h>
#include <algorithm>
#define INF 2000000000
#define min2(x,y) (x<y?x:y)

using namespace std;
int n, X, Y, in[2001];
int dp[2001][2001];

bool Can(int len) {
	int *w1, *w2, t1, t2;

	for (int i = 1; i <= n; i++) {
		w1 = lower_bound(in + 1, in + n + 1, in[i] - len + 1);
		w2 = lower_bound(in + 1, in + n + 1, in[i] - len * 2 + 1);
		t1 = w1 - in - 1, t2 = w2 - in - 1;

		dp[i][0] = dp[t2][0] + 1;
		for (int j = 1; j <= X; j++) {
			dp[i][j] = min2(dp[t1][j - 1], dp[t2][j] + 1);
		}
	}
	return dp[n][X] <= Y;
}
int main() {
	int l = 1, r = 1000000000, mid;

	scanf("%d %d %d", &n, &X, &Y), X=min2(X,n), Y=min2(Y,n);
	for (int i = 1; i <= n; i++) scanf("%d", &in[i]);
	sort(in + 1, in + n + 1);

	while (l <= r) {
		mid = (l + r) / 2;
		if (Can(mid)) r = mid - 1;
		else l = mid + 1;
	} printf("%d", r + 1);
}

Compilation message

watching.cpp: In function 'int main()':
watching.cpp:28:57: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d %d", &n, &X, &Y), X=min2(X,n), Y=min2(Y,n);
                                                         ^
watching.cpp:29:50: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for (int i = 1; i <= n; i++) scanf("%d", &in[i]);
                                                  ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 16764 KB Output is correct
2 Correct 0 ms 16764 KB Output is correct
3 Correct 0 ms 16764 KB Output is correct
4 Correct 0 ms 16764 KB Output is correct
5 Correct 0 ms 16764 KB Output is correct
6 Correct 0 ms 16764 KB Output is correct
7 Correct 0 ms 16764 KB Output is correct
8 Correct 0 ms 16764 KB Output is correct
9 Correct 0 ms 16764 KB Output is correct
10 Correct 0 ms 16764 KB Output is correct
11 Correct 0 ms 16764 KB Output is correct
12 Correct 0 ms 16764 KB Output is correct
13 Correct 0 ms 16764 KB Output is correct
14 Correct 0 ms 16764 KB Output is correct
15 Correct 0 ms 16764 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 16764 KB Output is correct
2 Correct 0 ms 16764 KB Output is correct
3 Correct 146 ms 16764 KB Output is correct
4 Correct 189 ms 16764 KB Output is correct
5 Correct 13 ms 16764 KB Output is correct
6 Correct 193 ms 16764 KB Output is correct
7 Correct 9 ms 16764 KB Output is correct
8 Correct 23 ms 16764 KB Output is correct
9 Correct 89 ms 16764 KB Output is correct
10 Correct 173 ms 16764 KB Output is correct
11 Correct 16 ms 16764 KB Output is correct
12 Correct 96 ms 16764 KB Output is correct
13 Correct 9 ms 16764 KB Output is correct
14 Correct 9 ms 16764 KB Output is correct
15 Correct 6 ms 16764 KB Output is correct