이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define DEBUG false
using namespace std;
const int N = 2e3+10;
int n,P,Q,dp[N][N];
main(){
ios_base::sync_with_stdio(0); cin.tie(0);
cin >> n >> P >> Q;
vector<int> a(n+1, 0);
for(int i=1; i<=n; i++){
cin >> a[i];
}
sort(a.begin(), a.end());
if(P+Q >= n){
cout << "1\n";
return 0;
}
int l = 1, r = 1e9, ans = -1, lim = min(P, Q), chk = max(P, Q);
int code = (P < Q);
while(l <= r){
int mid = (l+r)/2;
for(int i=1, j1, j2; i<=n; i++){
if(code == 0){
j1 = lower_bound(a.begin()+1, a.end(), a[i]-2*mid+1)-a.begin();
j2 = lower_bound(a.begin()+1, a.end(), a[i]-mid+1)-a.begin();
}else{
j1 = lower_bound(a.begin()+1, a.end(), a[i]-mid+1)-a.begin();
j2 = lower_bound(a.begin()+1, a.end(), a[i]-2*mid+1)-a.begin();
}
for(int q=0; q<=lim; q++){
dp[i][q] = 1e9;
if(q > 0)
dp[i][q] = dp[j1-1][q-1];
dp[i][q] = min(dp[i][q], dp[j2-1][q]+1);
}
}
if(dp[n][lim] <= chk){
ans = mid;
r = mid-1;
}else{
l = mid+1;
}
}
cout << ans << "\n";
}
컴파일 시 표준 에러 (stderr) 메시지
watching.cpp:8:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
8 | main(){
| ^~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |