Submission #312906

# Submission time Handle Problem Language Result Execution time Memory
312906 2020-10-14T15:34:38 Z limabeans Watching (JOI13_watching) C++17
50 / 100
547 ms 262148 KB
#include <bits/stdc++.h>
using namespace std;

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl





using ll = long long;

const int inf = 1e9;
const int maxn = 1e5 + 5;


int n,p,q;
int a[maxn];


int dp[2001][maxn]; //dp[i][j]: min big cameras for first i events, given we use j small cameras

bool test(int len) {
    int l=1;
    int r=1;
    for (int i=1; i<=n; i++) {
	while (a[l] < a[i]-len+1) l++;
	while (a[r] < a[i]-2*len+1) r++;
	
	for (int j=0; j<=p; j++) {
	    dp[i][j] = inf;
	    if (j>0) {
		dp[i][j] = min(dp[i][j], dp[l-1][j-1]);
	    }
	    dp[i][j] = min(dp[i][j], dp[r-1][j] + 1);
	}
    }

    return dp[n][p] <= q;
}

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);  cout.tie(0);

    cin>>n>>p>>q;
    for (int i=1; i<=n; i++) {
	cin>>a[i];
    }
    sort(a+1,a+1+n);

    int lo=0;
    int hi=1e9;

    while (hi-lo>1) {
	int mid=(lo+hi)/2;
	if (test(mid)) {
	    hi=mid;
	} else {
	    lo=mid;
	}
    }

    cout<<hi<<endl;
    
    
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 768 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 544 ms 39416 KB Output is correct
5 Correct 1 ms 768 KB Output is correct
6 Correct 547 ms 39424 KB Output is correct
7 Correct 1 ms 896 KB Output is correct
8 Correct 1 ms 768 KB Output is correct
9 Correct 1 ms 768 KB Output is correct
10 Correct 1 ms 768 KB Output is correct
11 Correct 1 ms 896 KB Output is correct
12 Correct 1 ms 896 KB Output is correct
13 Correct 1 ms 768 KB Output is correct
14 Correct 1 ms 768 KB Output is correct
15 Correct 1 ms 768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 9856 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 192 ms 21752 KB Output is correct
4 Runtime error 253 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
5 Halted 0 ms 0 KB -