Submission #367091

# Submission time Handle Problem Language Result Execution time Memory
367091 2021-02-16T08:29:10 Z ritul_kr_singh Watching (JOI13_watching) C++17
0 / 100
2 ms 512 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;
    }
    if(x > p){
        y += x-p;
        x = p;
    }
    return x<=p and y<=q;
}

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){
      |            ~~~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 0 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Incorrect 1 ms 364 KB Output isn't correct
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 492 KB Output is correct
4 Correct 1 ms 512 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 1 ms 512 KB Output is correct
7 Incorrect 1 ms 364 KB Output isn't correct
8 Halted 0 ms 0 KB -