답안 #472424

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
472424 2021-09-13T14:12:35 Z _L__ Cipele (COCI18_cipele) C++17
81 / 90
405 ms 1920 KB
// This code is written by _L__
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template<class T> using ordered_set = tree<T, null_type , less<T> , rb_tree_tag , tree_order_statistics_node_update>;
#define endl '\n'
#define F_word ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
typedef long long ll;
typedef long double ld;
const ll mod = 1e9+7, N = 1e5+300, inf = 1e18;
const ld E = 1e-6;
#define ff first
#define ss second

ll a[N], b[N], n, m;

bool check(ll mid){
    ll cur = -1;
    ll cnt = 0;
    if(n <= m){
        for(int i = 0; i < n; ++i){
            ll x = a[i]-mid;
            ll y = a[i]+mid;
            ll l = lower_bound(b, b+m, x)-b, r = upper_bound(b, b+m, y)-b;--r;
            if(cur+1 <= r){cur = max(cur+1, l); cnt++;}
        }
        return (cnt >= n);
    } else {
        for(int i = 0; i < m; ++i){
            ll x = b[i]-mid;
            ll y = b[i]+mid;
            ll l = lower_bound(a, a+n, x)-a, r = upper_bound(a, a+n, y)-a;--r;
            if(cur+1 <= r){ cur = max(cur+1, l); ++cnt;}
        }
        return (cnt >= m);
    }
}

ll lower(){
    ll l = 0, r = 1e11;
    ll ans = 0;
    while(l <= r){
        ll mid = (l+r)/2;
        if(check(mid)){
            r = mid-1;
            ans = mid;
        } else l = mid+1;
    }
    return ans;
}

int main(void){
    F_word;
    cin >> n >> m;
    for(int i = 0; i < n; ++i) cin >> a[i];
    for(int i = 0; i < m; ++i) cin >> b[i];
    sort(a, a+n); sort(b, b+m);
    cout << lower() << endl;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 369 ms 1764 KB Output is correct
2 Correct 359 ms 1864 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 405 ms 1860 KB Output is correct
2 Correct 371 ms 1920 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 332 KB Output is correct
2 Correct 10 ms 400 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 332 KB Output is correct
2 Correct 10 ms 404 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 332 KB Output is correct
2 Correct 9 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 400 KB Output is correct
2 Correct 10 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 273 ms 1568 KB Output is correct
2 Correct 197 ms 1204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 331 ms 1692 KB Output is correct
2 Correct 228 ms 1452 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 294 ms 1484 KB Output is correct
2 Correct 295 ms 1624 KB Output is correct