답안 #48678

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
48678 2018-05-17T20:37:29 Z Pajaraja 구경하기 (JOI13_watching) C++17
50 / 100
1000 ms 15612 KB
#include <bits/stdc++.h>
#define MAXN 2007
using namespace std;
int n,p,q,a[MAXN],dp[MAXN][MAXN];
int provera(int x)
{
	int t1=0,t2=0,t3=1;
	for(int i=1;i<=q;i++) dp[i][0]=1000000000;
	dp[0][0]=0;
	while(t3<=n)
	{
		while(t1<t3 && a[t3]-a[t1+1]>=2*x) t1++;
		while(t2<t3 && a[t3]-a[t2+1]>=x) t2++;
		for(int i=0;i<=q;i++) 
		{
			dp[i][t3]=1000000000;
			if(i>0) dp[i][t3]=min(dp[i-1][t1],dp[i][t3]);
			dp[i][t3]=min(dp[i][t2]+1,dp[i][t3]);
		}
		t3++;
	}
	for(int i=0;i<=q;i++) if(dp[i][n]<=p) return true;
	return false;
}
/*int binarna(int l,int r)
{
	if(l==r) return l;
	int s=(l+r)/2;
	if(provera(s)) return binarna(l,s);
	return binarna(s+1,r);
}*/
int main()
{
	scanf("%d%d%d",&n,&p,&q);
	if(p+q>=n) {printf("1"); return 0;}
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);
	sort(a+1,a+n+1);
	a[0]=-1000000000;
	int l=1,r=(a[n]-a[1])/2;
	while(l!=r)
	{
		int s=(l+r)/2;
		if(provera(s)) r=s;
		else l=s+1;
	}
	printf("%d",l);
}

Compilation message

watching.cpp: In function 'int main()':
watching.cpp:34: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:36:29: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(int i=1;i<=n;i++) scanf("%d",&a[i]);
                        ~~~~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 428 KB Output is correct
4 Correct 2 ms 428 KB Output is correct
5 Correct 2 ms 460 KB Output is correct
6 Correct 2 ms 464 KB Output is correct
7 Correct 2 ms 516 KB Output is correct
8 Correct 2 ms 516 KB Output is correct
9 Correct 2 ms 516 KB Output is correct
10 Correct 2 ms 700 KB Output is correct
11 Correct 2 ms 700 KB Output is correct
12 Correct 2 ms 724 KB Output is correct
13 Correct 2 ms 724 KB Output is correct
14 Correct 7 ms 740 KB Output is correct
15 Correct 2 ms 740 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 740 KB Output is correct
2 Correct 2 ms 740 KB Output is correct
3 Correct 2 ms 740 KB Output is correct
4 Correct 2 ms 740 KB Output is correct
5 Correct 2 ms 740 KB Output is correct
6 Correct 2 ms 740 KB Output is correct
7 Correct 5 ms 748 KB Output is correct
8 Correct 268 ms 6556 KB Output is correct
9 Correct 28 ms 6556 KB Output is correct
10 Correct 23 ms 6556 KB Output is correct
11 Execution timed out 1028 ms 15612 KB Time limit exceeded
12 Halted 0 ms 0 KB -