Submission #468180

# Submission time Handle Problem Language Result Execution time Memory
468180 2021-08-27T01:49:32 Z pdstiago Watching (JOI13_watching) C++14
0 / 100
1000 ms 460 KB
#include <bits/stdc++.h>
using namespace std;
 
#define MOD 1000000007
#define mxn 105
#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, v[mxn], p, g;

int solve(int i, int ss, int b, int last, int maxx){
    if(ss<0 || b<0){
        return 0;
    }
    if(ss+b<=0 && i<=n){
        return 0;
    }
    if(i>n){
        if(ss+b>=0 && last>n){
            return 1;
        }else{
            return 0;
        }
    }
    int ans=0;
    if(v[i]-v[last]+1<=2*maxx){
        if(v[i]-v[last]+1<=maxx){
            ans=max(ans, solve(i+1, ss-1, b, i+1, maxx));
        }else{
            ans=max(ans, solve(i+1, ss, b-1, i+1, maxx));
        }
    }
    ans=max(ans, solve(i+1, ss, b, last, maxx));
    return ans;
}

int main(){
    fastio;
    cin >> n >> p >> g;
    for(int i=1; i<=n; i++){
        cin >> v[i];
    }
    sort(v+1, v+1+n);
    int ini=1, fim=1000000000, meio, resp;
    while(ini<=fim){
        meio=(ini+fim)>>1;
        if(solve(1, p, g, 1, meio)){
            resp=meio;
            fim=meio-1;
        }else{
            ini=meio+1;
        }
    }
    cout << resp;
    return 0;
}

Compilation message

watching.cpp: In function 'int main()':
watching.cpp:66:13: warning: 'resp' may be used uninitialized in this function [-Wmaybe-uninitialized]
   66 |     cout << resp;
      |             ^~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 312 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Execution timed out 1080 ms 204 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 460 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -