이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2001;
int n, a[maxn], f[maxn][maxn], p, q, Next[maxn][2];
int bs(int x)
{
int l = 1;
int h = n;
while(l <= h)
{
int mid = l + h >> 1;
if(a[mid] < x) l = mid + 1;
else h = mid - 1;
}
return l;
}
bool Check(int gau)
{
for(int i = 1; i <= n; i++)
{
Next[i][0] = bs(a[i] + gau);
Next[i][1] = bs(a[i] + 2 * gau);
}
f[0][0] = 1;
for(int i = 0; i <= p; i++)
{
for(int j = 0; j <= q; j++)
{
if(i == 0 && j == 0) continue;
int x = 0;
if(i > 0)
{
x = max(x, Next[f[i - 1][j]][0]);
}
if(j > 0)
{
x = max(x, Next[f[i][j - 1]][1]);
}
if(x == n + 1) return true;
f[i][j] = x;
}
}
return false;
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
//freopen("test.inp", "r", stdin);
//freopen("test.out", "w", stdout);
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;
int h = 1e9;
while(l <= h)
{
int mid = (l + h) / 2;
if(Check(mid)) h = mid - 1;
else l = mid + 1;
}
cout << l;
}
컴파일 시 표준 에러 (stderr) 메시지
watching.cpp: In function 'int bs(int)':
watching.cpp:15:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
int mid = l + h >> 1;
~~^~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |