Submission #24843

# Submission time Handle Problem Language Result Execution time Memory
24843 2017-06-15T08:20:27 Z nibnalin Watching (JOI13_watching) C++14
100 / 100
333 ms 17744 KB
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;

const int maxn = int(2e3)+5, inf = int(1e9)+5;

int n, p, q, A[maxn], nex[maxn][2], memo[maxn][maxn];

bool f(int w)
{
	for(int idx = n-1;idx >= 0;idx--)
	{
		nex[idx][0] = int(lower_bound(A, A+n, A[idx]+w)-A);
		nex[idx][1] = int(lower_bound(A, A+n, A[idx]+min(inf, 2*w))-A);
		for(int pp = 0;pp <= p;pp++)
		{
			memo[idx][pp] = inf;
			if(pp) memo[idx][pp] = min(memo[idx][pp], memo[nex[idx][0]][pp-1]);
			memo[idx][pp] = min(memo[idx][pp], memo[nex[idx][1]][pp]+1);
		}
	}
	//cout << w << " " << memo[0][p] << "\n";

	return (memo[0][p] <= q);
}

int main(void)
{
	scanf("%d%d%d", &n, &p, &q);
	p = min(p, n), q = min(q, n);
	for(int i = 0;i < n;i++) scanf("%d", &A[i]);
	sort(A, A+n);

	int L = 0, R = inf, ans = inf+5;
	while(L <= R)
	{
		int mid = (L+R)/2;
		if(f(mid))
		{
			ans = min(ans, mid);
			R = mid-1;
		}
		else L = mid+1;
	}
	printf("%d\n", ans);
}

Compilation message

watching.cpp: In function 'int main()':
watching.cpp:31:29: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d%d", &n, &p, &q);
                             ^
watching.cpp:33:45: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(int i = 0;i < n;i++) scanf("%d", &A[i]);
                                             ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 17744 KB Output is correct
2 Correct 0 ms 17744 KB Output is correct
3 Correct 0 ms 17744 KB Output is correct
4 Correct 0 ms 17744 KB Output is correct
5 Correct 0 ms 17744 KB Output is correct
6 Correct 0 ms 17744 KB Output is correct
7 Correct 0 ms 17744 KB Output is correct
8 Correct 0 ms 17744 KB Output is correct
9 Correct 0 ms 17744 KB Output is correct
10 Correct 0 ms 17744 KB Output is correct
11 Correct 0 ms 17744 KB Output is correct
12 Correct 0 ms 17744 KB Output is correct
13 Correct 0 ms 17744 KB Output is correct
14 Correct 0 ms 17744 KB Output is correct
15 Correct 0 ms 17744 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 17744 KB Output is correct
2 Correct 0 ms 17744 KB Output is correct
3 Correct 253 ms 17744 KB Output is correct
4 Correct 333 ms 17744 KB Output is correct
5 Correct 23 ms 17744 KB Output is correct
6 Correct 333 ms 17744 KB Output is correct
7 Correct 9 ms 17744 KB Output is correct
8 Correct 26 ms 17744 KB Output is correct
9 Correct 139 ms 17744 KB Output is correct
10 Correct 313 ms 17744 KB Output is correct
11 Correct 19 ms 17744 KB Output is correct
12 Correct 163 ms 17744 KB Output is correct
13 Correct 9 ms 17744 KB Output is correct
14 Correct 13 ms 17744 KB Output is correct
15 Correct 6 ms 17744 KB Output is correct