이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ll int
const ll N = 2000+5 , INF = 1e9+5 , MOD = 1e9+7;
vector<ll> a(N);
ll n,p,q;
bool check(ll dist){
vector<vector<ll>> dp(n+5,vector<ll>(p+5,INF));
// dp[i][j] = min large cameras needed for 1 to i and having j small cameras
for(ll i = 0; i <= p; i++) dp[0][i] = 0;
dp[1][0] = 1;
for(ll i = 1; i <= p; i++) dp[1][i] = 0;
for(ll i = 2; i <= n; i++){
for(ll j = 0; j <= p; j++){
ll low1 = 1 , high1 = i;
ll ind1 = i;
while(low1 <= high1){
ll mid = (low1+high1)/2;
if(a[i]-a[mid] < dist){
ind1 = mid;
high1 = mid-1;
}
else low1 = mid+1;
}
if(j) dp[i][j] = min(dp[i][j],dp[ind1-1][j-1]);
ll low2 = 1 , high2 = i;
ll ind2 = i;
while(low2 <= high2){
ll mid = (low2+high2)/2;
if(a[i]-a[mid] < 2*dist){
ind2 = mid;
high2 = mid-1;
}
else low2 = mid+1;
}
dp[i][j] = min(dp[i][j],dp[ind2-1][j]+1);
}
}
ll ans = INF;
for(ll i = 0; i <= p; i++) ans = min(ans,dp[n][i]);
return (ans <= q);
}
void solve(){
cin >> n >> p >> q;
for(ll i = 1; i <= n; i++) cin >> a[i];
if(p >= n || q >= n){
cout << "1";
return;
}
sort(a.begin()+1,a.begin()+n+1);
ll low = 1 , high = a[n];
ll ans;
while(low <= high){
ll mid = (low+high)/2;
if(check(mid)){
ans = mid;
high = mid-1;
}
else low = mid+1;
}
cout << ans;
}
int main(){
fast;
ll tc = 1;
// cin >> tc;
while(tc--) solve();
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
watching.cpp: In function 'void solve()':
watching.cpp:80:10: warning: 'ans' may be used uninitialized in this function [-Wmaybe-uninitialized]
80 | cout << ans;
| ^~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |