# pragma GCC optimize("O3")
# include <bits/stdc++.h>
std::pair<int,int> DR[] = {{-1,0},{0,1},{1,0},{0,-1},{-1,1},{-1,-1},{1,1},{1,-1}};
# define ll long long
# define clock (clock() * 1000.0 / CLOCKS_PER_SEC)
# define rc(s) return cout << s,0
# define rcg(s) cout << s;exit(0)
# define _ ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
# define db(x) cerr << #x << " = " << x << '\n'
# define pb push_back
# define mp make_pair
# define all(s) s.begin(),s.end()
# define sz(x) (int)((x).size())
# define int ll
using namespace std;
int dp[2005][2005];
int n,p,q;
int a[2005];
const int mx = 1e18;
int check(int w)
{
for(int i = 0;i <= n;i++)
{
for(int j = 0;j <= p;j++)
{
dp[i][j] = 1e18;
}
}
for(int j = 0;j <= p;j++) dp[0][j] = 0;
for(int i = 1;i <= n;i++)
{
int x = lower_bound(a + 1,a + 1 + n,a[i] - w + 1) - a;
int y = lower_bound(a + 1,a + 1 + n,a[i] - 2*w + 1) - a;
for(int j = p;j >= 0;j--)
{
dp[i][j] = min((j > 0 ? dp[x - 1][j - 1] : mx),dp[y - 1][j] + 1);
}
}
return (dp[n][p] <= q);
}
int32_t main(){_
//freopen("input","r",stdin);
cin >> n >> p >> q;
p = min(p,n);
for(int i = 1;i <= n;i++) cin >> a[i];
int l = 1;
int r = 1e9;
sort(a + 1,a + 1 + n);
while(l < r)
{
int mid = l + r >> 1;
if(check(mid)) r = mid;
else l = mid + 1;
}
rc(l);
}
Compilation message
watching.cpp: In function 'int32_t main()':
watching.cpp:55:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
int mid = l + r >> 1;
~~^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
888 KB |
Output is correct |
2 |
Correct |
3 ms |
888 KB |
Output is correct |
3 |
Correct |
3 ms |
888 KB |
Output is correct |
4 |
Correct |
3 ms |
1000 KB |
Output is correct |
5 |
Correct |
2 ms |
1000 KB |
Output is correct |
6 |
Correct |
4 ms |
1000 KB |
Output is correct |
7 |
Correct |
3 ms |
1000 KB |
Output is correct |
8 |
Correct |
3 ms |
1000 KB |
Output is correct |
9 |
Correct |
3 ms |
1000 KB |
Output is correct |
10 |
Correct |
3 ms |
1000 KB |
Output is correct |
11 |
Correct |
4 ms |
1000 KB |
Output is correct |
12 |
Correct |
3 ms |
1000 KB |
Output is correct |
13 |
Correct |
2 ms |
1000 KB |
Output is correct |
14 |
Correct |
3 ms |
1000 KB |
Output is correct |
15 |
Correct |
3 ms |
1000 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
15 ms |
8628 KB |
Output is correct |
2 |
Correct |
3 ms |
8628 KB |
Output is correct |
3 |
Correct |
363 ms |
32100 KB |
Output is correct |
4 |
Correct |
473 ms |
32108 KB |
Output is correct |
5 |
Correct |
34 ms |
32108 KB |
Output is correct |
6 |
Correct |
489 ms |
32280 KB |
Output is correct |
7 |
Correct |
16 ms |
32280 KB |
Output is correct |
8 |
Correct |
43 ms |
32280 KB |
Output is correct |
9 |
Correct |
197 ms |
32280 KB |
Output is correct |
10 |
Correct |
428 ms |
32280 KB |
Output is correct |
11 |
Correct |
32 ms |
32280 KB |
Output is correct |
12 |
Correct |
221 ms |
32280 KB |
Output is correct |
13 |
Correct |
20 ms |
32280 KB |
Output is correct |
14 |
Correct |
21 ms |
32280 KB |
Output is correct |
15 |
Correct |
21 ms |
32280 KB |
Output is correct |