제출 #136652

#제출 시각아이디문제언어결과실행 시간메모리
136652junodeveloper구경하기 (JOI13_watching)C++14
100 / 100
346 ms16248 KiB
#include <bits/stdc++.h>
#define sz(x) ((int)x.size())
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
int n, P, Q, a[2010], trans[2010][2], dp[2010][2010];
bool f(int w) {
	int i,j=1,k=1;
	for(i=1;i<=n;i++) {
		while(j<=n&&a[j]<a[i]+w)j++;
		while(k<=n&&a[k]<a[i]+2*w)k++;
		trans[i][0]=j,trans[i][1]=k;
	}
	int res=1e9;
	for(i=n;i>=1;i--) {
		for(j=0;j<=Q;j++) {
			dp[i][j]=1e9;
			dp[i][j]=min(dp[i][j], dp[trans[i][0]][j]+1);
			if(j>0) dp[i][j]=min(dp[i][j], dp[trans[i][1]][j-1]);
			if(i==1)res=min(res,dp[i][j]);
		}
	}
	return res<=P;
}
int main() {
	scanf("%d%d%d",&n,&P,&Q);
	P=min(P,n), Q=min(Q,n);
	int i;
	for(i=1;i<=n;i++)scanf("%d",a+i);
	sort(a+1,a+n+1);
	int lo=0,hi=1e9;
	while(lo<hi) {
		int mid=(lo+hi)/2;
		if(f(mid)) hi=mid;
		else lo=mid+1;
	}
	printf("%d", lo);
	return 0;
}

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

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,&P,&Q);
  ~~~~~^~~~~~~~~~~~~~~~~~~
watching.cpp:34:24: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(i=1;i<=n;i++)scanf("%d",a+i);
                   ~~~~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...