답안 #923732

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
923732 2024-02-07T16:44:12 Z Lalic 구경하기 (JOI13_watching) C++17
100 / 100
529 ms 32156 KB
#include <bits/stdc++.h>
using namespace std;

#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()
#define int long long

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int MAXN = 1e5+10;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3f;
const int MOD = 1e9+7;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

int n, p, q;
vector<int> arr;

bool check(int w){
	vector<vector<int>> dp(n+1, vector<int>(p+1, INF));
	dp[0][0]=0;
	
	int ptr1=0, ptr2=0;
	for(int i=1;i<=n;i++){
		while(arr[ptr1+1]<=arr[i]-w) ptr1++;
		while(arr[ptr2+1]<=arr[i]-2*w) ptr2++;
		
		for(int j=0;j<=p;j++){
			if(j) dp[i][j]=min(dp[i][j], dp[ptr1][j-1]);
			dp[i][j]=min(dp[i][j], dp[ptr2][j]+1);
		}
	}
	
	int mn=INF;
	for(int i=0;i<=p;i++) mn=min(mn, dp[n][i]);
	
	return mn<=q;
}

void solve(){
	cin >> n >> p >> q; p=min(p, n);
	arr.resize(n+1); arr[0]=-INF;
	for(int i=1;i<=n;i++) cin >> arr[i];
	sort(arr.begin()+1, arr.end());
	
	int l=1, r=5e8, best=-1;
	while(l<=r){
		int mid=(l+r)>>1;
		if(check(mid)){
			best=mid;
			r=mid-1;
		}
		else l=mid+1;
	}
	
	cout << best << "\n";
}

int32_t main(){
	ios_base::sync_with_stdio(false); cin.tie(NULL);
		
	int tt=1;
	//cin >> tt;
	while(tt--) solve();
	return 0;
}

# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 456 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 464 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 0 ms 456 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 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 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 604 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 373 ms 24176 KB Output is correct
4 Correct 529 ms 32000 KB Output is correct
5 Correct 17 ms 1884 KB Output is correct
6 Correct 523 ms 32156 KB Output is correct
7 Correct 4 ms 600 KB Output is correct
8 Correct 28 ms 2568 KB Output is correct
9 Correct 185 ms 12500 KB Output is correct
10 Correct 493 ms 30380 KB Output is correct
11 Correct 20 ms 1996 KB Output is correct
12 Correct 242 ms 16012 KB Output is correct
13 Correct 4 ms 612 KB Output is correct
14 Correct 5 ms 844 KB Output is correct
15 Correct 5 ms 900 KB Output is correct