답안 #364482

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
364482 2021-02-09T10:16:43 Z Rainbowbunny 구경하기 (JOI13_watching) C++17
100 / 100
73 ms 8684 KB
#include <iostream>
#include <algorithm>

int n, p, q;
int a[2005], nextsmall[2005], nextlarge[2005], dp[2005][2005];

bool Check(int value)
{
	for(int i = 0; i < n; i++)
	{
		nextsmall[i] = std::upper_bound(a, a + n + 1, a[i] + value - 1) - a;
		nextlarge[i] = std::upper_bound(a, a + n + 1, a[i] + value * 2 - 1) - a;
	}
	for(int i = 0; i <= p; i++)
	{
		if(i > 0)
		{
			dp[i][0] = nextsmall[dp[i - 1][0]];
			if(dp[i][0] == n)
			{
				return true;
			}
		}
		else
		{
			dp[i][0] = 0;
		}
		for(int j = 1; j <= q; j++)
		{
			dp[i][j] = 0;
			if(i)
			{
				dp[i][j] = std::max(dp[i][j], nextsmall[dp[i - 1][j]]);
			}
			dp[i][j] = std::max(dp[i][j], nextlarge[dp[i][j - 1]]);
			if(dp[i][j] == n)
			{
				return true;
			}
		}
	}
	return false;
}

int main()
{
	std::ios_base::sync_with_stdio(false);
	std::cin.tie(0);
	std::cout.tie(0);
	std::cin >> n >> p >> q;
	p = std::min(p, n);
	q = std::min(q, n);
	for(int i = 0; i < n; i++)
	{
		std::cin >> a[i];
	}
	a[n] = 2e9;
	std::sort(a, a + n);	
	int l = 1, r = 1e9 / 2;
	while(l < r)
	{
		int mid = (l + r) >> 1;
		if(Check(mid))
		{
			r = mid;
		}
		else
		{
			l = mid + 1;
		}
	}
	std::cout << l;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 492 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 748 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 620 KB Output is correct
12 Correct 1 ms 620 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 400 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 41 ms 4076 KB Output is correct
4 Correct 22 ms 8556 KB Output is correct
5 Correct 6 ms 364 KB Output is correct
6 Correct 6 ms 364 KB Output is correct
7 Correct 4 ms 492 KB Output is correct
8 Correct 14 ms 1260 KB Output is correct
9 Correct 16 ms 3820 KB Output is correct
10 Correct 26 ms 8684 KB Output is correct
11 Correct 12 ms 1132 KB Output is correct
12 Correct 73 ms 8044 KB Output is correct
13 Correct 6 ms 492 KB Output is correct
14 Correct 6 ms 492 KB Output is correct
15 Correct 7 ms 492 KB Output is correct