답안 #136652

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
136652 2019-07-26T03:03:49 Z junodeveloper 구경하기 (JOI13_watching) C++14
100 / 100
346 ms 16248 KB
#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;
}

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,&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);
                   ~~~~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 888 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 764 KB Output is correct
5 Correct 3 ms 760 KB Output is correct
6 Correct 3 ms 764 KB Output is correct
7 Correct 3 ms 760 KB Output is correct
8 Correct 3 ms 760 KB Output is correct
9 Correct 3 ms 760 KB Output is correct
10 Correct 3 ms 760 KB Output is correct
11 Correct 3 ms 760 KB Output is correct
12 Correct 3 ms 760 KB Output is correct
13 Correct 3 ms 760 KB Output is correct
14 Correct 2 ms 760 KB Output is correct
15 Correct 3 ms 760 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 8440 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 261 ms 16136 KB Output is correct
4 Correct 23 ms 8952 KB Output is correct
5 Correct 344 ms 16120 KB Output is correct
6 Correct 346 ms 16136 KB Output is correct
7 Correct 12 ms 8444 KB Output is correct
8 Correct 138 ms 14456 KB Output is correct
9 Correct 31 ms 9340 KB Output is correct
10 Correct 25 ms 9080 KB Output is correct
11 Correct 325 ms 16248 KB Output is correct
12 Correct 177 ms 16120 KB Output is correct
13 Correct 13 ms 8568 KB Output is correct
14 Correct 12 ms 8568 KB Output is correct
15 Correct 12 ms 8568 KB Output is correct