Submission #468185

# Submission time Handle Problem Language Result Execution time Memory
468185 2021-08-27T02:12:47 Z pdstiago Watching (JOI13_watching) C++14
0 / 100
1000 ms 332 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;
vector<int> v;
 
int solve(int i, int ss, int b, int maxx){
    if(ss<0 || b<0){
        return 0;
    }
    if(i>=n){
        return 1;
    }
    auto it1=upper_bound(v.begin()+i, v.end(), v[i]+maxx-1);
    auto it2=upper_bound(v.begin()+i, v.end(), v[i]+2*maxx-1);
    it1--;
    it2--;
    int pos1=it1-v.begin(), pos2=it2-v.begin();
    return max(solve(pos1+1, ss-1, b, maxx), solve(pos2+1, ss, b-1, maxx));
}
 
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;
    while(ini<=fim){
        meio=(ini+fim)>>1;
        if(solve(0, p, g, meio)){
            resp=meio;
            fim=meio-1;
        }else{
            ini=meio+1;
        }
    }
    cout << resp;
    return 0;
}

Compilation message

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