답안 #472413

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
472413 2021-09-13T13:58:48 Z _L__ Cipele (COCI18_cipele) C++17
81 / 90
334 ms 2108 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

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

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 >> l[i];
    for(int i = 0; i < m; ++i) cin >> r[i];
    sort(l, l+n); sort(r, r+m);
    cout << lower() << endl;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 314 ms 1868 KB Output is correct
2 Correct 334 ms 2108 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 333 ms 2108 KB Output is correct
2 Correct 334 ms 1988 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 332 KB Output is correct
2 Correct 9 ms 460 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 11 ms 332 KB Output is correct
2 Correct 9 ms 428 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 332 KB Output is correct
2 Correct 9 ms 464 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 416 KB Output is correct
2 Correct 9 ms 464 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 253 ms 1620 KB Output is correct
2 Correct 197 ms 1260 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 307 ms 1828 KB Output is correct
2 Correct 190 ms 1400 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 260 ms 1572 KB Output is correct
2 Correct 304 ms 1644 KB Output is correct