이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
const int maxn=2e3+5;
int n,p,q;
int a[maxn];
int dp[maxn][maxn];
bool check(int w){
for(int i = 0;i <= n;i++) for(int j = 0;j <= q;j++) dp[i][j] = 1e9;
dp[0][0] = 0;
int pos = 1;
int idx = 1;
for(int i = 1;i <= n;i++){
while(a[i] - w >= a[pos]) pos++;
while(a[i] - 2*w >= a[idx]) idx++;
for(int j = 0;j <= q;j++){
if(j) dp[i][j] = dp[idx-1][j-1];
dp[i][j] = min(dp[i][j],dp[pos-1][j] + 1);
}
}
bool tr = 0;
for(int i = 0;i <= q;i++) tr |= (dp[n][i] <= p);
return tr;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n >> p >> q;
for(int i = 1;i <= n;i++) cin >> a[i];
if(p + q >= n) return cout<<1,0;
sort(a + 1,a + n + 1);
int l = 1,r = 1e9,md,ans;
while(l <= r){
md = (l + r) >> 1;
if(check(md)) ans=md,r=md-1;
else l=md+1;
}
cout<<ans;
}
컴파일 시 표준 에러 (stderr) 메시지
watching.cpp: In function 'int main()':
watching.cpp:44:8: warning: 'ans' may be used uninitialized in this function [-Wmaybe-uninitialized]
44 | cout<<ans;
| ^~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |