이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define v(a) vector<a>
#define all(x) x.begin(), x.end()
#define trace2(x,y) cout<<"> "<<#x<<" : "<<x<<" | "<<#y<<" : "<<y<<endl
#define trace3(x,y,z) cout<<"> "<<#x<<" : "<<x<<" | "<<#y<<" : "<<y<<" | "<<#z<<" : "<<z<<endl
v(v(ll)) dp;
v(ll) arr;
ll n, p, q;
ll trav(ll idx, ll cur, ll k){
if(idx >= n) return 1;
if(cur < 0) return 1e9;
if(dp[idx][cur] != -1) return dp[idx][cur];
ll nextP = upper_bound(arr.begin()+idx, arr.end(), arr[idx]+k)-arr.begin();
ll nextQ = upper_bound(arr.begin()+idx, arr.end(), arr[idx]+2*k)-arr.begin();
// trace2(nextP, nextQ);
// trace2(idx, k);
ll ret = 1e9;
ret = min(trav(nextP, cur, k)+1, trav(nextQ, cur-1, k));
return dp[idx][cur] = ret;
}
ll binsearch(ll l, ll r){
if(l <= r){
ll mid = (l+r)/2;
ll temp = trav(0, q, mid);
for(int i = 0; i < n; i++){
dp[i].clear();
dp[i].assign(q+1, -1);
}
if(temp <= p){
return min(mid, binsearch(l, mid-1));
}
return binsearch(mid+1, r);
}
}
int main(){
cin >> n >> p >> q;
arr.resize(n);
for(int i = 0; i < n; i++) cin >> arr[i];
if(p+q >= n) cout << 1 << endl;
else {
dp.resize(n);
for(int i = 0; i < n; i++) dp[i].assign(q+1, -1);
sort(arr.begin(), arr.end());
cout << binsearch(1, 1e9);
}
}
컴파일 시 표준 에러 (stderr) 메시지
watching.cpp: In function 'long long int binsearch(long long int, long long int)':
watching.cpp:39:1: warning: control reaches end of non-void function [-Wreturn-type]
39 | }
| ^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |