Submission #722385

# Submission time Handle Problem Language Result Execution time Memory
722385 2023-04-11T21:27:32 Z hyakup Watching (JOI13_watching) C++17
100 / 100
124 ms 16056 KB
#include <bits/stdc++.h>
using namespace std;
 
const int maxn = 2010;
 
int pos[maxn];
 
int dp[maxn][maxn];
int n, p, q; 
 
bool check( int x ){
    
    for( int j = 0; j < maxn; j++ ) dp[0][j] = 0;
    
    int k1 = 0, k2 = 0;
    
    for( int i = 1; i <= n; i++ ){
        
        while( pos[k1 + 1] < pos[i] - x + 1 ) k1++;
        while( pos[k2 + 1] < pos[i] - 2*x + 1 ) k2++;
        
        dp[i][0] = dp[k2][0] + 1;
        
        for( int j = 1; j <= p; j++ ){
            
            dp[i][j] = min( dp[k1][j - 1], dp[k2][j] + 1 );
        }
    }
    
    if( dp[n][p] <= q ) return true;
    return false;
}
 
int bs(){
    
    int ini = 1, fim = 1000000010;
    
    while( ini < fim ){
        
        int mid = ( ini + fim )/2;
        
        if( check(mid) ) fim = mid;
        else ini = mid + 1;
    }
    
    return fim;
}
 
int main(){
    
    cin >> n >> p >> q;
    
    if( p + q >= n ){
        
        cout << 1;
        
        return 0;
    }
    
    for( int i = 1; i <= n; i++ ) cin >> pos[i];
    
    sort( pos, pos + n + 1 );
    
    int resp = bs();
    
    cout << resp;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 724 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 312 KB Output is correct
6 Correct 1 ms 312 KB Output is correct
7 Correct 1 ms 724 KB Output is correct
8 Correct 1 ms 724 KB Output is correct
9 Correct 1 ms 724 KB Output is correct
10 Correct 1 ms 724 KB Output is correct
11 Correct 1 ms 724 KB Output is correct
12 Correct 1 ms 724 KB Output is correct
13 Correct 1 ms 724 KB Output is correct
14 Correct 1 ms 696 KB Output is correct
15 Correct 1 ms 724 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 8276 KB Output is correct
2 Correct 1 ms 312 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 320 KB Output is correct
5 Correct 1 ms 328 KB Output is correct
6 Correct 1 ms 324 KB Output is correct
7 Correct 6 ms 8404 KB Output is correct
8 Correct 13 ms 9296 KB Output is correct
9 Correct 55 ms 14152 KB Output is correct
10 Correct 124 ms 16056 KB Output is correct
11 Correct 11 ms 9044 KB Output is correct
12 Correct 71 ms 15956 KB Output is correct
13 Correct 5 ms 8404 KB Output is correct
14 Correct 6 ms 8404 KB Output is correct
15 Correct 6 ms 8404 KB Output is correct