Submission #33326

# Submission time Handle Problem Language Result Execution time Memory
33326 2017-10-23T15:42:11 Z SYury Watching (JOI13_watching) C++11
100 / 100
79 ms 17712 KB
#include<bits/stdc++.h>

#pragma GCC optimize("O3")

using namespace std;
typedef long long int ll;
typedef long double ldb;
typedef unsigned long long uli;

#define X first
#define Y second
#define F(i, l, r) for(auto i = l; i != r; i++)
#define DF(i, l, r) for(auto i = l; i != r; i--)
#define I(i, a) for(auto i : a)
#define pb push_back
#define rs resize
#define mp make_pair
#define asg assign
#define all(x) x.begin(),x.end()
#define ret return
#define cont continue
#define brk break
#define ins insert
#define era erase
#define fi0(x) memset(x, 0, sizeof(x))
#define finf(x) memset(x, 127, sizeof(x))
#define y1 adjf
#define tm dhgdg

const int MAXN = 2e3 + 3;

int n, p, q;
int a[MAXN];
int dp[MAXN][MAXN];
int jump[2][MAXN];

bool can(int w){
	jump[0][n - 1] = jump[1][n - 1] = n - 1;
	int ptr[2] = {n-1, n-1};
	DF(i, n - 2, -1){
		while(ptr[0] > i && a[ptr[0]] - a[i] >= w)ptr[0]--;
		jump[0][i] = ptr[0];
		while(ptr[1] > i && a[ptr[1]] - a[i] >= 2*w)ptr[1]--;
		jump[1][i] = ptr[1];
	}
	F(i, 0, min(p,n)+1)F(j, 0, min(q,n)+1)dp[i][j] = 0;
	F(i, 0, min(p, n) + 1){
		F(j, 0, min(q, n) + 1){
			if(dp[i][j] == n)ret true;
			if(i < min(p, n)){
				dp[i+1][j] = max(dp[i+1][j], jump[0][dp[i][j]]+1);
			}
			if(j < min(q, n)){
				dp[i][j+1] = max(dp[i][j+1], jump[1][dp[i][j]]+1);
			}
		}
	}
	ret false;
}

int main(){
	scanf("%d%d%d", &n, &p, &q);
	F(i, 0, n)scanf("%d", &a[i]);
	sort(a, a + n);
	int l = 0, r = 6e8;
	while(r - l > 1){
		int mid = (l + r) >> 1;
		if(can(mid))r = mid;
		else l = mid;
	}
	printf("%d", r);
	ret 0;
}

Compilation message

watching.cpp: In function 'int main()':
watching.cpp:62: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:63:30: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  F(i, 0, n)scanf("%d", &a[i]);
                              ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 17712 KB Output is correct
2 Correct 0 ms 17712 KB Output is correct
3 Correct 0 ms 17712 KB Output is correct
4 Correct 0 ms 17712 KB Output is correct
5 Correct 0 ms 17712 KB Output is correct
6 Correct 0 ms 17712 KB Output is correct
7 Correct 0 ms 17712 KB Output is correct
8 Correct 0 ms 17712 KB Output is correct
9 Correct 0 ms 17712 KB Output is correct
10 Correct 0 ms 17712 KB Output is correct
11 Correct 0 ms 17712 KB Output is correct
12 Correct 0 ms 17712 KB Output is correct
13 Correct 0 ms 17712 KB Output is correct
14 Correct 0 ms 17712 KB Output is correct
15 Correct 0 ms 17712 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 17712 KB Output is correct
2 Correct 0 ms 17712 KB Output is correct
3 Correct 76 ms 17712 KB Output is correct
4 Correct 23 ms 17712 KB Output is correct
5 Correct 3 ms 17712 KB Output is correct
6 Correct 79 ms 17712 KB Output is correct
7 Correct 0 ms 17712 KB Output is correct
8 Correct 13 ms 17712 KB Output is correct
9 Correct 13 ms 17712 KB Output is correct
10 Correct 19 ms 17712 KB Output is correct
11 Correct 9 ms 17712 KB Output is correct
12 Correct 76 ms 17712 KB Output is correct
13 Correct 0 ms 17712 KB Output is correct
14 Correct 0 ms 17712 KB Output is correct
15 Correct 0 ms 17712 KB Output is correct