답안 #132766

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
132766 2019-07-19T13:49:28 Z miguel 구경하기 (JOI13_watching) C++14
0 / 100
6 ms 380 KB
#include<bits/stdc++.h>
//#include<gondola.h>
using namespace std;
#define rc(x) return cout<<x<<endl,0
#define pb push_back
#define dbg(x) cout << #x << '=' << x << '\n';
#define ll long long
#define int ll
#define sz size()
#define x first
#define y second
#define pi pair <int, int>
#define pii pair <int, pi>
#define vi vector <int>
const ll mod = 998244353;
int n, p, q;
vector <int> w;

bool check(int d){
    int a=p, b=q, cnt=0, cur=0;
    while(a+b){
        bool ctrl=1;
        if(b){
            if((*upper_bound(w.begin(), w.end(), w[cur]+d-1))<=w[cur]+2*d-1){
                b--;
                ctrl=0;
                cur=upper_bound(w.begin(), w.end(), w[cur]+2*d-1)-w.begin();
            }
        }
        if(a && ctrl){
            a--;
            ctrl=0;
            cur=upper_bound(w.begin(), w.end(), w[cur]+d-1)-w.begin();
        }
        if(b && ctrl){
            b--;
            ctrl=0;
            cur=upper_bound(w.begin(), w.end(), w[cur]+2*d-1)-w.begin();
        }
        if(cur>=n) return 1;
    }
    return 0;
}

int32_t main(){
    ios_base :: sync_with_stdio(0); cin.tie(); cout.tie();
    cin>>n>>p>>q;
    for(int i=1; i<=n; i++){
        int x;
        cin>>x;
        w.pb(x);
    }
    int l=0, r=1e9+1;
    sort(w.begin(), w.end());
    //w.pb(1000000001);
    while(r-l>1){
        int mid=(l+r)>>1;
        if(check(mid)) r=mid;
        else l=mid;
    }
    cout<<r;
}

Compilation message

watching.cpp: In function 'bool check(long long int)':
watching.cpp:20:19: warning: unused variable 'cnt' [-Wunused-variable]
     int a=p, b=q, cnt=0, cur=0;
                   ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 380 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Incorrect 2 ms 376 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 6 ms 376 KB Output is correct
6 Correct 6 ms 376 KB Output is correct
7 Incorrect 2 ms 376 KB Output isn't correct
8 Halted 0 ms 0 KB -