Submission #156463

# Submission time Handle Problem Language Result Execution time Memory
156463 2019-10-06T02:05:12 Z wilwxk Watching (JOI13_watching) C++14
100 / 100
181 ms 8692 KB
#include <bits/stdc++.h>
using namespace std;

const int MAXN=2e3+3;
int v[MAXN], chega[MAXN][2];
int dp[MAXN][MAXN];
int n, x, y;

bool testa(int k) {
	int p=1, p2=1;
	for(int i=1; i<=n; i++) {
		while(p<=n&&v[p]-v[i]<=k-1) p++;
		while(p2<=n&&v[p2]-v[i]<=2*k-1) p2++;
		chega[i][0]=p;
		chega[i][1]=p2;
	}
	chega[0][0]=chega[0][1]=1;
	chega[n+1][0]=chega[n+1][1]=n+1;
	for(int i=0; i<=x; i++) {
		for(int j=0; j<=y; j++) {
			dp[i][j]=1;
			if(i!=0) dp[i][j]=max(dp[i][j], chega[dp[i-1][j]][0]);
			if(j!=0) dp[i][j]=max(dp[i][j], chega[dp[i][j-1]][1]);
			// printf("%d %d >> %d\n", i, j, dp[i][j]);
		}
	}
	return dp[x][y]>n;
}

int main() {
	scanf("%d %d %d", &n, &x, &y);

	if(x+y>=n) {
		printf("1\n");
		return 0;
	}
	for(int i=1; i<=n; i++) scanf("%d", &v[i]);
	sort(v+1, v+1+n);
	for(int i=1; i<=n; i++) {

	}


	// testa(4);
	int respf=0;
	for(int i=1e9; i>0; i/=2) while(!testa(respf+i)) respf+=i;

	printf("%d\n", respf+1);
}

Compilation message

watching.cpp: In function 'int main()':
watching.cpp:31:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d %d", &n, &x, &y);
  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
watching.cpp:37:31: 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", &v[i]);
                          ~~~~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 248 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 1 ms 256 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 3 ms 376 KB Output is correct
9 Correct 9 ms 376 KB Output is correct
10 Correct 3 ms 376 KB Output is correct
11 Correct 3 ms 636 KB Output is correct
12 Correct 3 ms 504 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 412 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 4 ms 376 KB Output is correct
8 Correct 24 ms 1244 KB Output is correct
9 Correct 26 ms 3704 KB Output is correct
10 Correct 39 ms 8692 KB Output is correct
11 Correct 32 ms 1144 KB Output is correct
12 Correct 181 ms 8096 KB Output is correct
13 Correct 3 ms 376 KB Output is correct
14 Correct 3 ms 512 KB Output is correct
15 Correct 3 ms 376 KB Output is correct