Submission #143934

# Submission time Handle Problem Language Result Execution time Memory
143934 2019-08-15T13:16:12 Z WhipppedCream Watching (JOI13_watching) C++17
50 / 100
1000 ms 16308 KB
#include <bits/stdc++.h>
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
using namespace std;
#define X first
#define Y second
#define pb push_back
typedef pair<int, int> ii;
typedef long long ll;

int n;

const int maxn = 2005;

int arr[maxn];

int dp[maxn][maxn];

int w;

int solve(int p, int q)
{
	if(dp[p][q] != -1) return dp[p][q];
	int ans = 0;
	if(p> 0)
	{
		int lst = solve(p-1, q);
		if(lst == n)
		{
			return dp[p][q] = n;
		}
		int rng = arr[lst+1]+w-1;
		int val = upper_bound(arr+1, arr+n+1, rng)-arr-1;
		ans = max(ans, val);
	}
	if(q> 0)
	{
		int lst = solve(p, q-1);
		if(lst == n)
		{
			return dp[p][q] = n;
		}
		int rng = arr[lst+1]+2*w-1;
		int val = upper_bound(arr+1, arr+n+1, rng)-arr-1;
		ans = max(ans, val);
	}
	return dp[p][q] = ans;
}

int main()
{
	int p, q;
	scanf("%d %d %d", &n, &p, &q);
	for(int i = 1; i<= n; i++) scanf("%d", &arr[i]);
	sort(arr+1, arr+n+1);
	n = unique(arr+1, arr+n+1)-(arr+1);
	if(p+q>= n)
	{
		printf("1\n"); return 0;
	}
	int lo = 1, hi = arr[n]-arr[1]+1;
	while(lo< hi)
	{
		int mid = (lo+hi)/2;
		memset(dp, -1, sizeof dp);
		w = mid;
		if(solve(p, q) == n) hi = mid;
		else lo = mid+1;
	}
	printf("%d\n", lo);
}

Compilation message

watching.cpp: In function 'int main()':
watching.cpp:53:7: 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:54:34: 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", &arr[i]);
                             ~~~~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 48 ms 16308 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 42 ms 15992 KB Output is correct
4 Correct 2 ms 296 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 43 ms 16092 KB Output is correct
8 Correct 45 ms 15992 KB Output is correct
9 Correct 43 ms 15992 KB Output is correct
10 Correct 45 ms 15992 KB Output is correct
11 Correct 51 ms 16092 KB Output is correct
12 Correct 46 ms 15984 KB Output is correct
13 Correct 33 ms 16096 KB Output is correct
14 Correct 31 ms 15992 KB Output is correct
15 Correct 36 ms 16032 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 43 ms 16140 KB Output is correct
2 Correct 2 ms 396 KB Output is correct
3 Correct 3 ms 376 KB Output is correct
4 Correct 3 ms 376 KB Output is correct
5 Correct 3 ms 372 KB Output is correct
6 Correct 3 ms 476 KB Output is correct
7 Correct 43 ms 15992 KB Output is correct
8 Correct 228 ms 16156 KB Output is correct
9 Correct 228 ms 16152 KB Output is correct
10 Correct 249 ms 16208 KB Output is correct
11 Correct 155 ms 16204 KB Output is correct
12 Execution timed out 1041 ms 16124 KB Time limit exceeded
13 Halted 0 ms 0 KB -