답안 #468186

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
468186 2021-08-27T02:30:11 Z pdstiago 구경하기 (JOI13_watching) C++14
0 / 100
1000 ms 460 KB
#include <bits/stdc++.h>
using namespace std;
 
#define MOD 1000000007
#define mxn 2005
#define mxm 1005
#define f first
#define s second
#define pb push_back
#define es " "
#define endl '\n'
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define ll long long
#define fastio ios_base::sync_with_stdio(0), cin.tie(0)
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
typedef pair<ll, ll> pii;
typedef pair<pii, int> pip;
 
int n, p, g, pos1[mxn], pos2[mxn];
vector<int> v;
 
int solve(int i, int ss, int b){
    if(ss<0 || b<0){
        return 0;
    }
    if(i>=n){
        return 1;
    }
    return max(solve(pos1[i]+1, ss-1, b), solve(pos2[i]+1, ss, b-1));
}
 
int main(){
    fastio;
    cin >> n >> p >> g;
    for(int i=1; i<=n; i++){
        int x;
        cin >> x;
        v.pb(x);
    }
    sort(all(v));
    int ini=1, fim=1000000000, meio, resp=1;
    while(ini<=fim){
        meio=(ini+fim)>>1;
        memset(pos1, 0, sizeof(pos1));
        memset(pos2, 0, sizeof(pos2));
        for(int i=0; i<sz(v); i++){
            for(int j=sz(v)-1; j>=i; j--){
                if(v[j]-v[i]+1<=2*meio){
                    if(v[j]-v[i]+1<=meio){
                        pos1[i]=j;
                        break;
                    }else{
                        pos2[i]=max(pos2[i], j);
                    }
                }
            }
        }
        if(solve(0, p, g)){
            resp=meio;
            fim=meio-1;
        }else{
            ini=meio+1;
        }
    }
    cout << resp;
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Execution timed out 1091 ms 204 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 86 ms 332 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Execution timed out 1092 ms 460 KB Time limit exceeded
4 Halted 0 ms 0 KB -