답안 #367090

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
367090 2021-02-16T08:19:07 Z ritul_kr_singh 구경하기 (JOI13_watching) C++17
0 / 100
1 ms 384 KB
//#pragma GCC optimize("Ofast,unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define sp << " " <<
#define nl << "\n"

int n, p, q;
int a[2000];

bool possible(int w){
    vector<array<int, 2>> res = {{a[0], a[0]}};

    for(int i=1; i<n; ++i){
        if(res.back()[0] + w - 1 < a[i]){
            res.push_back({a[i], a[i]});
        }else res.back()[1] = a[i];
    }

    int x = 0, y = 0;

    for(int i=0; i<res.size(); ++i){
        if(i+1 < res.size() and res[i+1][1]-res[i][0]+1<=2*w){
            y += 1;
            i += 1;
        }else x += 1;
    }

    if(y > q){
        x += 2*(y-q);
        y = q;
    }
    return x <= p;
}

signed main(){
    ios_base::sync_with_stdio(false); cin.tie(nullptr);
    cin >> n >> p >> q;
    for(int i=0; i<n; ++i) cin >> a[i];
    sort(a, a+n);

    int low = 1, high = 1e9;
    while(low < high){
        int mid = (low+high)/2;
        if(possible(mid)) high = mid;
        else low = mid+1;
    }
    cout << low nl;
}

Compilation message

watching.cpp: In function 'bool possible(long long int)':
watching.cpp:22:19: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::array<long long int, 2> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   22 |     for(int i=0; i<res.size(); ++i){
      |                  ~^~~~~~~~~~~
watching.cpp:23:16: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::array<long long int, 2> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   23 |         if(i+1 < res.size() and res[i+1][1]-res[i][0]+1<=2*w){
      |            ~~~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Incorrect 1 ms 384 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Incorrect 1 ms 364 KB Output isn't correct
3 Halted 0 ms 0 KB -