Submission #1096079

# Submission time Handle Problem Language Result Execution time Memory
1096079 2024-10-03T17:19:48 Z thangdz2k7 Cipele (COCI18_cipele) C++17
90 / 90
30 ms 2904 KB
// author : thembululquaUwU
// 3.9.2024

#include <bits/stdc++.h>
#define pb push_back
#define fi first
#define se second
#define endl '\n'

using namespace std;
using ll = long long;
using ii = pair <int, int>;
using vi = vector <int>;

const int MaxN = 2e5;
const int mod = 1e9 + 7;

void maxl(auto &a, auto b) {a = max(a, b);}
void minl(auto &a, auto b) {a = min(a, b);}

void solve(){
    int n, m; cin >> n >> m;
    vi a(n), b(m);
    for (auto &p : a) cin >> p;
    for (auto &p : b) cin >> p;
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    if (n > m){
        swap(n, m); swap(a, b);
    }

    int lo = 0, hi = 1e9, ans = hi;
    while (lo <= hi){
        int mid = lo + hi >> 1;
        int l = 0; bool ck = true;
        for (int p : a){
            while (l < m && p - b[l] > mid) ++ l;
            if (l == m || b[l] - p > mid) {
                ck = false;
                break;
            }
            ++ l;
        }
        if (ck) ans = mid, hi = mid - 1;
        else lo = mid + 1;
    }
    cout << ans;
}

int main(){
    if (fopen("pqh.inp", "r")){
        freopen("pqh.inp", "r", stdin);
        freopen("pqh.out", "w", stdout);
    }
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    int t = 1; // cin >> t;
    while (t --) solve();
    return 0;
}

Compilation message

cipele.cpp:18:11: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
   18 | void maxl(auto &a, auto b) {a = max(a, b);}
      |           ^~~~
cipele.cpp:18:20: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
   18 | void maxl(auto &a, auto b) {a = max(a, b);}
      |                    ^~~~
cipele.cpp:19:11: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
   19 | void minl(auto &a, auto b) {a = min(a, b);}
      |           ^~~~
cipele.cpp:19:20: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
   19 | void minl(auto &a, auto b) {a = min(a, b);}
      |                    ^~~~
cipele.cpp: In function 'void solve()':
cipele.cpp:34:22: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   34 |         int mid = lo + hi >> 1;
      |                   ~~~^~~~
cipele.cpp: In function 'int main()':
cipele.cpp:52:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   52 |         freopen("pqh.inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
cipele.cpp:53:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   53 |         freopen("pqh.out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 18 ms 2652 KB Output is correct
2 Correct 30 ms 2900 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 29 ms 2904 KB Output is correct
2 Correct 30 ms 2904 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 3 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 2 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 2 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 604 KB Output is correct
2 Correct 2 ms 596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 348 KB Output is correct
2 Correct 2 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 30 ms 2504 KB Output is correct
2 Correct 19 ms 1884 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 27 ms 2652 KB Output is correct
2 Correct 13 ms 2136 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 28 ms 2392 KB Output is correct
2 Correct 27 ms 2652 KB Output is correct