제출 #51471

#제출 시각아이디문제언어결과실행 시간메모리
51471MoesashiMinamoto구경하기 (JOI13_watching)C++14
100 / 100
137 ms16380 KiB
#include <bits/stdc++.h>

using namespace std;

int n, p, q;

int a[2003];
int dp[2003][2003];
int js[2003], jb[2003];

void jump(int w)
{
	for (int i = 0; i < n; i++)
	{
		js[i] = upper_bound(a, a+n, a[i]+w-1) - a;
		jb[i] = upper_bound(a, a+n, a[i]+2*w-1) - a;
	}
}

bool chec(int w)
{
	jump(w);
	memset(dp, -1, sizeof(dp));
	dp[0][0] = 0;
	for (int i = 0; i <= q; i++)
	{
		for (int j = 0; j <= p; j++)
		{
			if (dp[i][j] != -1)
			{
				if (dp[i][j] == n) return true;
				dp[i][j+1] = max(dp[i][j+1], js[dp[i][j]]);
				dp[i+1][j] = max(dp[i+1][j], jb[dp[i][j]]);
			}
		}
	}
	return false;
}

signed main()
{
	scanf("%d%d%d", &n, &p, &q);
	for (int i = 0; i < n; i++)
	{
		scanf("%d", &a[i]);
	}
	sort(a, a+n);
	if (p + q >= n) 
	{
		printf("1");
		return 0;
	}
	long long it = 0;
	for (int i = 33; i >= 0; i--)
	{
		if (it + (1ll << i) <= 1000000000)
		{
			long long cur = it + (1ll << i);
			if (!chec(cur))
			{
				it = cur;
			}
		}
	}
	printf("%lld", it+1);
}

컴파일 시 표준 에러 (stderr) 메시지

watching.cpp: In function 'int main()':
watching.cpp:42: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:45:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &a[i]);
   ~~~~~^~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...