# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1123142 | hainam2k9 | 구경하기 (JOI13_watching) | C++20 | 260 ms | 16196 KiB |
#include <bits/stdc++.h>
#define tt cin.tie(0), cout.tie(0), ios_base::sync_with_stdio(0)
#define fo freopen((NAME+".INP").c_str(), "r", stdin), freopen((NAME+".OUT").c_str(), "w", stdout)
#define ll long long
#define ull unsigned long long
#define i128 __int128
#define db long double
#define sz(a) ((int)(a).size())
#define pb emplace_back
#define pf emplace_front
#define pob pop_back
#define pof pop_front
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define ins emplace
using namespace std;
const int MOD = 1e9+7, MAXN = 1e5+5;
const string NAME = "";
int n,p,q,a[2005],dp[2005][2005];
inline int Front(int i, queue<int>& q){
if(q.empty()) return i;
return q.front();
}
void Print(queue<int> q){
while(!q.empty()) cout << q.front() << " ", q.pop();
cout << "\n";
}
bool check(int mid){
memset(dp,0,sizeof(dp));
queue<int> small,large;
for(int i = 1; i<=n; ++i){
while(!small.empty()&&a[i]-a[small.front()]+1>mid) small.pop();
while(!large.empty()&&a[i]-a[large.front()]+1>mid<<1) large.pop();
dp[i][0]=dp[Front(i,large)-1][0]+1;
for(int j = 1; j<=p; ++j)
dp[i][j]=min(dp[Front(i,small)-1][j-1],dp[Front(i,large)-1][j]+1);
small.push(i), large.push(i);
}
return dp[n][p]<=q;
}
int bs(int l, int r){
int rs=1;
while(l<=r){
int mid=(l+r)>>1;
if(check(mid)) rs=mid, r=mid-1;
else l=mid+1;
}
return rs;
}
int main()
{
tt;
if(fopen((NAME + ".INP").c_str(), "r")) fo;
cin >> n >> p >> q;
for(int i = 1; i<=n; ++i) cin >> a[i];
if(p+q>=n){
cout << 1;
return 0;
}
sort(a+1,a+n+1);
cout << bs(1,1e9);
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |