Submission #817006

# Submission time Handle Problem Language Result Execution time Memory
817006 2023-08-09T08:21:51 Z RecursiveCo Watching (JOI13_watching) C++14
0 / 100
1 ms 344 KB
// CF template, version 3.0

#include <bits/stdc++.h>

using namespace std;

#define improvePerformance ios_base::sync_with_stdio(false); cin.tie(0)
#define getTest int t; cin >> t
#define eachTest for (int _var=0;_var<t;_var++)
#define get(name) int (name); cin >> (name)
#define out(o) cout << (o)
#define getList(cnt, name) vector<int> (name); for (int _=0;_<(cnt);_++) { get(a); (name).push_back(a); }
#define sortl(name) sort((name).begin(), (name).end())
#define rev(name) reverse((name).begin(), (name).end())
#define forto(name, var) for (int (var) = 0; (var) < (name); (var)++)
#define decision(b) if (b){out("YES");}else{out("NO");}

#define int long long int

signed main() {
    improvePerformance;

    get(n);
    get(p);
    get(q);
    getList(n, nums);
    sortl(nums);
    int l = 1;
    int r = 2e9;
    while (r - l >= 1) {
        int middle = (l + r) / 2;
        int small = p;
        int large = q;
        int ptr = 0;
        bool can = true;

        while (ptr < n) {
            if (small + large == 0) {
                can = false;
                break;
            }
            int newptr = ptr;
            while (newptr < n && nums[newptr] < nums[ptr] + middle) newptr++;
            if (newptr == n) {
                break;
            }
            if (nums[newptr] < nums[ptr] + 2 * middle && large) {
                large--;
                while (newptr < n && nums[newptr] < nums[ptr] + 2 * middle) newptr++;
                ptr = newptr;
            } else {
                small--;
                ptr = newptr;
            }
        }

        if (!can) l = middle + 1;
        else r = middle;
    }
    out(l);
}

Compilation message

watching.cpp: In function 'int main()':
watching.cpp:10:23: warning: unnecessary parentheses in declaration of 'n' [-Wparentheses]
   10 | #define get(name) int (name); cin >> (name)
      |                       ^
watching.cpp:23:5: note: in expansion of macro 'get'
   23 |     get(n);
      |     ^~~
watching.cpp:10:23: warning: unnecessary parentheses in declaration of 'p' [-Wparentheses]
   10 | #define get(name) int (name); cin >> (name)
      |                       ^
watching.cpp:24:5: note: in expansion of macro 'get'
   24 |     get(p);
      |     ^~~
watching.cpp:10:23: warning: unnecessary parentheses in declaration of 'q' [-Wparentheses]
   10 | #define get(name) int (name); cin >> (name)
      |                       ^
watching.cpp:25:5: note: in expansion of macro 'get'
   25 |     get(q);
      |     ^~~
watching.cpp:12:40: warning: unnecessary parentheses in declaration of 'nums' [-Wparentheses]
   12 | #define getList(cnt, name) vector<int> (name); for (int _=0;_<(cnt);_++) { get(a); (name).push_back(a); }
      |                                        ^
watching.cpp:26:5: note: in expansion of macro 'getList'
   26 |     getList(n, nums);
      |     ^~~~~~~
watching.cpp:10:23: warning: unnecessary parentheses in declaration of 'a' [-Wparentheses]
   10 | #define get(name) int (name); cin >> (name)
      |                       ^
watching.cpp:12:76: note: in expansion of macro 'get'
   12 | #define getList(cnt, name) vector<int> (name); for (int _=0;_<(cnt);_++) { get(a); (name).push_back(a); }
      |                                                                            ^~~
watching.cpp:26:5: note: in expansion of macro 'getList'
   26 |     getList(n, nums);
      |     ^~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Incorrect 0 ms 212 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Incorrect 1 ms 340 KB Output isn't correct
8 Halted 0 ms 0 KB -