답안 #646126

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
646126 2022-09-28T18:13:53 Z Hacv16 Cipele (COCI18_cipele) C++17
90 / 90
46 ms 2744 KB
#include<bits/stdc++.h>
using namespace std;

#define pb push_back
#define sc second
#define fr first
#define all(x) x.begin(), x.end()
#define sz(x) (ll) x.size()
#define dbg(x) cerr << #x << ": [ " << x << " ]\n"

typedef long long ll;
typedef pair<int, int> pii;

const int MAX = 2e6 + 15;
const int INF = 0x3f3f3f3f;

ll n, m;
vector<ll> l, r;

bool f(ll x){
    ll shoes = 0;

    for(ll i = 0, j = 0; i < n, j < m; i++, j++){
        while(j < m && abs(r[j] - l[i]) > x) j++;
        if(j != m) shoes++;

        if(shoes >= n) return true;
    }
    
    return false;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin >> n >> m;

    for(int i = 0; i < n; i++){
        ll x; cin >> x; l.pb(x);
    }

    for(int i = 0; i < m; i++){
        ll x; cin >> x; r.pb(x);
    }

    if(n > m) swap(l, r), swap(n, m); //always make l the smaller one

    sort(all(l)); sort(all(r));

    ll l = 0, r = INF, ans = INF; 

    while(l <= r){
        ll mid = (l + r) >> 1;
        if(f(mid)) ans = mid, r = mid - 1;
        else l = mid + 1;
    }

    cout << ans << '\n';

    return 0;
}

Compilation message

cipele.cpp: In function 'bool f(ll)':
cipele.cpp:23:28: warning: left operand of comma operator has no effect [-Wunused-value]
   23 |     for(ll i = 0, j = 0; i < n, j < m; i++, j++){
      |                          ~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 2640 KB Output is correct
2 Correct 37 ms 2744 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 37 ms 2580 KB Output is correct
2 Correct 36 ms 2640 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 2 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 2 ms 428 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 452 KB Output is correct
2 Correct 3 ms 428 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 340 KB Output is correct
2 Correct 2 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 428 KB Output is correct
2 Correct 3 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 46 ms 2380 KB Output is correct
2 Correct 24 ms 1572 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 37 ms 2536 KB Output is correct
2 Correct 17 ms 2000 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 35 ms 2340 KB Output is correct
2 Correct 33 ms 2452 KB Output is correct