이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
#define FF first
#define SS second
#define all(a) a.begin(), a.end()
#define mod (ll)(1000000007)
const int inf=1e9;
int main(){
ios_base::sync_with_stdio(0);cin.tie(0);
int n, p, q;
cin>>n>>p>>q;
if(q+p>=n)
return cout<<1, 0;
// p -> w
// q -> 2*w
vector<int>A(n);
for(int i=0;i<n;i++){
cin>>A[i];
}
sort(all(A));
int l=0, r=1e9, ans;
while(l<=r){
int md=(l+r)/2;
vector<vector<int>>Mn(n, vector<int>(q+1, inf));
for(int i=0;i<n;i++){
int fir2=-1, fir1=-1;
for(int j=i;j>=0;j--){
if(A[i]-A[j]+1>2*md){
fir2=j;
break;
}
}
for(int j=i;j>=0;j--){
if(A[i]-A[j]+1>md){
fir1=j;
break;
}
}
Mn[i][0]=(fir1==-1?0:Mn[fir1][0])+1;
for(int j=1;j<=q;j++){
Mn[i][j]=min({Mn[i][j], (fir2==-1?0:Mn[fir2][j-1]), (fir1==-1?0:Mn[fir1][j])+1});
}
}
int mn=inf;
for(int i=0;i<=q;i++){
mn=min(mn, Mn[n-1][i]);
}
if(mn<=p)
ans=md, r=md-1;
else
l=md+1;
}
cout<<ans;
}
컴파일 시 표준 에러 (stderr) 메시지
watching.cpp: In function 'int main()':
watching.cpp:55:11: warning: 'ans' may be used uninitialized in this function [-Wmaybe-uninitialized]
55 | cout<<ans;
| ^~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |