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