# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
74572 | wzy | 구경하기 (JOI13_watching) | C++11 | 477 ms | 32172 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define pii pair<int,int>
#define F first
#define S second
#define pb push_back
#define int long long
int n , p , q;
vector<int> v;
int dp[2002][2002];
deque<int> small, large;
bool can(int mid){
for(int i = 0 ; i <= n ; i++){
for(int j = 0 ; j <= n; j ++) dp[i][j] = 2000000000;
}
for(int i = 0 ; i < n; i ++){
if(v[i] - v[0] + 1 <= mid) dp[i][1] = 0;
if(v[i] - v[0] + 1 <= 2*mid) dp[i][0] = 1;
}
while(small.size()) small.pop_back();
while(large.size()) large.pop_back();
small.push_front(0) , large.push_front(0);
for(int i = 1 ; i < n ; i++){
while(large.size() && v[i] - v[large.front()] + 1 > 2*mid){
large.pop_front();
}
while(small.size() && v[i] - v[small.front()] + 1 > mid){
small.pop_front();
}
for(int j = 0 ; j <= min(p , i+1) ; j++){
if(j) dp[i][j] = min(dp[i][j] , dp[i][j-1]);
if(j && small.size() && small.front() > 0) dp[i][j] = min(dp[i][j] , dp[small.front() - 1][j-1]);
if(large.size() && large.front() > 0) dp[i][j] = min(dp[i][j] , dp[large.front() - 1][j] + 1);
dp[i][j] = min(dp[i][j] , 1 + dp[i-1][j]);
}
large.push_back(i);
small.push_back(i);
}
for(int i = 0 ; i <= p ; i++){
if(dp[n-1][i] <= q) return true;
}
return false;
}
int32_t main(){
scanf("%lld%lld%lld" , &n , &p , &q);
v.resize(n);
for(int i = 0 ; i < n; i ++) scanf("%lld" , &v[i]);
sort(v.begin() , v.end());
int l = 1 , r = 1000000000;
int ansj = 1000000000;
while(l<=r){
int mid = (l+r)/2;
if(can(mid)){
ansj = mid;
r = mid - 1;
}
else{
l = mid + 1;
}
}
printf("%lld\n" , ansj);
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |