답안 #942091

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
942091 2024-03-10T08:39:14 Z dshfjka 구경하기 (JOI13_watching) C++14
100 / 100
274 ms 30300 KB
#include <bits/stdc++.h>
#define LL long long
using namespace std;
int main()
{
	LL n,p,q;
	scanf("%lld %lld %lld",&n,&p,&q);
	LL arr[n+5];
	for(LL a=1;a<=n;a++)scanf("%lld",&arr[a]);
	sort(arr+1,arr+n+1);
	LL left=1,right=1e9,ans=-1;
	LL all=p+q;
	if(p+q>=n)
	{
		printf("1\n");
		exit(0);
	}
	while(left<=right)
	{
		LL mid=(left+right)/2;
	//	printf("mid=%lld\n",mid);
		LL dp[n+5][p+5];
		// now, p , minimum q
		for(LL a=0;a<=n+1;a++)for(LL b=0;b<=p;b++)dp[a][b]=1e9;
		LL lastp=1,lastq=1;
		dp[1][0]=0;
		for(LL a=1;a<=n;a++)
		{
			while(lastp!=n+1 && arr[lastp]-arr[a]+1<=mid)lastp++;
			while(lastq!=n+1 && arr[lastq]-arr[a]+1<=2*mid)lastq++;
			for(LL b=p;b>=0;b--)
			{
			//	printf("%lld %lld\n",a,b);
			//	if(dp[a][b]>=2500)continue;
				dp[lastp][b+1]=min(dp[lastp][b+1],dp[a][b]);
				dp[lastq][b]=min(dp[lastq][b],dp[a][b]+1);
			//	printf("dp[%lld][%lld] = %lld\n",lastp,b+1,dp[lastp][b+1]);
			//	printf("dp[%lld][%lld] = %lld\n",lastq,b,dp[lastq][b]);
			}
		}
		bool bisa=false;
		for(LL b=0;b<=p;b++)
		{
			if(dp[n+1][b]<=q){
				bisa=1;
				break;
			}
		}
		if(bisa){
			ans=mid;
			right=mid-1;
		}
		else left=mid+1;
	}
	printf("%lld\n",ans);
}

Compilation message

watching.cpp: In function 'int main()':
watching.cpp:12:5: warning: unused variable 'all' [-Wunused-variable]
   12 |  LL all=p+q;
      |     ^~~
watching.cpp:7:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    7 |  scanf("%lld %lld %lld",&n,&p,&q);
      |  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
watching.cpp:9:27: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    9 |  for(LL a=1;a<=n;a++)scanf("%lld",&arr[a]);
      |                      ~~~~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 432 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 464 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 3 ms 600 KB Output is correct
8 Correct 16 ms 2396 KB Output is correct
9 Correct 92 ms 12328 KB Output is correct
10 Correct 274 ms 30300 KB Output is correct
11 Correct 12 ms 1880 KB Output is correct
12 Correct 133 ms 15960 KB Output is correct
13 Correct 2 ms 604 KB Output is correct
14 Correct 3 ms 720 KB Output is correct
15 Correct 3 ms 604 KB Output is correct