Submission #155447

# Submission time Handle Problem Language Result Execution time Memory
155447 2019-09-28T07:12:18 Z kungfulon Watching (JOI13_watching) C++14
100 / 100
270 ms 16220 KB
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i = (a);i <= (b);i++)
#define repd(i,a,b) for(int i = (a);i >= (b);i--)
#define PB push_back
#define F first
#define S second
#define Task "watching"
using namespace std;
template <class T> T read(T &a){a = 0;char c = cin.get();bool nega = 0;while(!isdigit(c) && c != '-') c = cin.get();if(c == '-') nega = 1,c = cin.get();a = c - 48;c = cin.get();while(isdigit(c)) a = a * 10 + c - 48,c = cin.get();if(nega) a = -a;return a;}
template <class T> void writep(T a){if(a > 9) writep(a / 10);cout.put(a % 10 + 48);}
template <class T> void write(T a){if(a < 0) cout.put('-'),a = -a;writep(a);cout.put(' ');}
template <class T> void writeln(T a){write(a);cout.put('\n');}
const int N = 2012;
int n,p,q;
int dp[N][N],a[N];
bool check(int w)
{
    if(n <= p + q) return 1;
    int lq = 0,lp = 0;
    rep(i,1,n)
    {
        while(a[i] - a[lp] >= w && lp < i) lp++;
        while(a[i] - a[lq] >= w*2 && lq < i) lq++;
        rep(j,0,p)
        {
            dp[i][j] = dp[max(0,lq-1)][j] + 1;
            if(j)dp[i][j] = min(dp[i][j],dp[max(0,lp-1)][j-1]);
        }
    }
    rep(i,0,p) if(dp[n][i] <= q) return 1;
    return 0;
}
int main()
{
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
//	ifstream cin (Task".inp");
//	ofstream cout (Task".out");
    cin >> n >> p >> q;
    rep(i,1,n) cin >> a[i];
    sort(a+1,a+n+1);
    int l = 0,r = 1000000007;
    while(r - l > 1)
    {
        int mid = (l + r)/2;
        if(check(mid)) r = mid;
        else l = mid;
    }
    cout << r;
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 760 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 380 KB Output is correct
6 Correct 2 ms 380 KB Output is correct
7 Correct 2 ms 760 KB Output is correct
8 Correct 2 ms 760 KB Output is correct
9 Correct 2 ms 760 KB Output is correct
10 Correct 2 ms 760 KB Output is correct
11 Correct 3 ms 760 KB Output is correct
12 Correct 3 ms 760 KB Output is correct
13 Correct 3 ms 760 KB Output is correct
14 Correct 3 ms 760 KB Output is correct
15 Correct 3 ms 760 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 8312 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 3 ms 376 KB Output is correct
4 Correct 3 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 4 ms 376 KB Output is correct
7 Correct 13 ms 8568 KB Output is correct
8 Correct 38 ms 9336 KB Output is correct
9 Correct 121 ms 14328 KB Output is correct
10 Correct 270 ms 16220 KB Output is correct
11 Correct 23 ms 9080 KB Output is correct
12 Correct 148 ms 16120 KB Output is correct
13 Correct 11 ms 8440 KB Output is correct
14 Correct 12 ms 8440 KB Output is correct
15 Correct 12 ms 8568 KB Output is correct