답안 #171102

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
171102 2019-12-27T11:28:09 Z ZwariowanyMarcin 구경하기 (JOI13_watching) C++14
100 / 100
95 ms 8696 KB
#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define ss(x) (int) x.size()
#define pb push_back
#define ll long long
#define cat(x) cerr << #x << " = " << x << endl
#define FOR(i, n) for(int i = 0; i < n; ++i)

using namespace std;

const int nax = 2005;

int n;
int p, q;
int a[nax];
int dp[nax][nax];
int go[nax][2];

bool ok(int x) {
	if(n <= p + q) return 1;
	
	for(int i = 1; i <= n; ++i) {
		go[i][0] = upper_bound(a + 1, a + n + 1, a[i] + x - 1) - a - 1;
		go[i][1] = upper_bound(a + 1, a + n + 1, a[i] + x + x - 1) - a - 1;
	}
	for(int i = 0; i <= p; ++i)
		for(int j = 0; j <= q; ++j)
			dp[i][j] = 0;
	
	dp[0][0] = 0;
	for(int i = 0; i <= p; ++i)
		for(int j = 0; j <= q; ++j) {
			if(dp[i][j] == n) return 1;
			dp[i + 1][j] = max(dp[i + 1][j], go[dp[i][j] + 1][0]);
			dp[i][j + 1] = max(dp[i][j + 1], go[dp[i][j] + 1][1]);
		}
	return 0;
}			
	

int main() {
	scanf("%d %d %d", &n, &p, &q);
	for(int i = 1; i <= n; ++i)
		scanf("%d", a + i);
	sort(a + 1, a + n + 1);
	int l = 1;
	int r = 1000000001;
	while(l < r) {
		int m = (l + r) / 2;
		if(ok(m))
			r = m;
		else
			l = m + 1;
	}
	printf("%d", l);
	
	return 0;
}

Compilation message

watching.cpp: In function 'int main()':
watching.cpp:44: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:46:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", a + i);
   ~~~~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 632 KB Output is correct
12 Correct 3 ms 504 KB Output is correct
13 Correct 3 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 504 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 3 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 0 ms 376 KB Output is correct
7 Correct 6 ms 504 KB Output is correct
8 Correct 18 ms 1272 KB Output is correct
9 Correct 22 ms 3796 KB Output is correct
10 Correct 34 ms 8696 KB Output is correct
11 Correct 17 ms 1144 KB Output is correct
12 Correct 95 ms 8188 KB Output is correct
13 Correct 8 ms 376 KB Output is correct
14 Correct 9 ms 504 KB Output is correct
15 Correct 9 ms 504 KB Output is correct