Submission #468181

# Submission time Handle Problem Language Result Execution time Memory
468181 2021-08-27T01:53:47 Z pdstiago Watching (JOI13_watching) C++14
0 / 100
123 ms 262148 KB
#include <bits/stdc++.h>
using namespace std;
 
#define MOD 1000000007
#define mxn 2005
#define mxm 200005
#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, dp[mxn][mxm];

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;
        }
    }
    if(dp[i][ss+b]!=-1){
        return dp[i][ss+b];
    }
    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;
        memset(dp, -1, sizeof(dp));
        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:70:13: warning: 'resp' may be used uninitialized in this function [-Wmaybe-uninitialized]
   70 |     cout << resp;
      |             ^~~~
# Verdict Execution time Memory Grader output
1 Runtime error 117 ms 262148 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 123 ms 262148 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -