답안 #380775

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
380775 2021-03-23T01:59:42 Z mariowong 구경하기 (JOI13_watching) C++14
50 / 100
1000 ms 28092 KB
#include <bits/stdc++.h>
using namespace std;

int l,r,mid,n,p,q,a[2005],dp[2005][2005];
vector <int> v;
deque <int> dq; 
int main(){
	ios::sync_with_stdio(false);
	cin >> n >> p >> q;
	for (int i=1;i<=n;i++){
		cin >> a[i];
	}
	sort(a+1,a+1+n);
	for (int i=1;i<=n;i++){
		for (int j=i;j<=n;j++){
			v.push_back(a[j]-a[i]+1);
			v.push_back((a[j]-a[i]+1)/2+(a[j]-a[i]+1)%2);
		}
	}
	sort(v.begin(),v.end());
	l=0; r=(int)v.size()-1;
	while (l < r){
		mid=(l+r)/2;
		for (int i=0;i<=min(n,q);i++){ //used how many large
			for (int j=1;j<=n;j++){
				dp[i][j]=1e9;
			}
		}
		for (int i=0;i<=min(n,q);i++){ //used how many large
			if (i > 0){
				dq.push_back(0);
				for (int j=1;j<=n;j++){
					while (!dq.empty() && a[j]-a[dq.front()+1]+1 > 2*v[mid]) dq.pop_front();
					if (dq.empty()){
						l=mid+1;
						while (!dq.empty()) dq.pop_front();
						goto out;
					}
					else
					dp[i][j]=dp[i-1][dq.front()];
					while (!dq.empty() && dp[i-1][j] <= dp[i-1][dq.back()]) dq.pop_back();
					dq.push_back(j);
				}
				while (!dq.empty()) dq.pop_back();
			}
			dq.push_back(0);
			for (int j=1;j<=n;j++){
				while (!dq.empty() && a[j]-a[dq.front()+1]+1 > v[mid]) dq.pop_front();
				if (!dq.empty())
				dp[i][j]=min(dp[i][j],dp[i][dq.front()]+1);
				while (!dq.empty() && dp[i][j] <= dp[i][dq.back()]) dq.pop_back();
				dq.push_back(j);
			}
			while (!dq.empty()) dq.pop_back();
		}
	/*	cout << l << " " << r << "\n";
		for (int i=1;i<=min(n,q);i++){ //used how many large
			for (int j=1;j<=n;j++){
				cout << dp[i][j] << " ";
			}
			cout << "\n";
		}*/
		if (dp[min(n,q)][n] <= p)
		r=mid;
		else
		l=mid+1;
		out:;
	}
	cout << v[l] << "\n";
	return 0;
}	
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 492 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 492 KB Output is correct
5 Correct 4 ms 876 KB Output is correct
6 Correct 4 ms 876 KB Output is correct
7 Correct 1 ms 492 KB Output is correct
8 Correct 2 ms 492 KB Output is correct
9 Correct 1 ms 492 KB Output is correct
10 Correct 3 ms 748 KB Output is correct
11 Correct 2 ms 492 KB Output is correct
12 Correct 3 ms 620 KB Output is correct
13 Correct 1 ms 492 KB Output is correct
14 Correct 1 ms 492 KB Output is correct
15 Correct 2 ms 492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 396 ms 16860 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Execution timed out 1090 ms 28092 KB Time limit exceeded
4 Halted 0 ms 0 KB -