답안 #384335

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
384335 2021-04-01T12:10:24 Z AdiZer0 Cipele (COCI18_cipele) C++17
90 / 90
69 ms 2560 KB
#include <bits/stdc++.h>

#define pb push_back
#define whole(x) x.begin(), x.end()
#define sz(x) (int)x.size()

using namespace std;

typedef long long ll;
typedef long double ld;

const int N = (int)1e5 + 7;
const int INF = (int)1e9 + 7;
const ll linf = (ll)1e18 + 1;

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

bool ok(int mx) { 
    int p = 1;
    for (int i = 1; i <= n; ++i) { 
        while (p <= m && abs(a[i] - b[p]) > mx) ++p;
        if (abs(a[i] - b[p]) > mx) ++p;
        if (p > m) return false;
        ++p;
    }
    return true;
}

int main() {
    scanf ("%d %d", &n, &m);
    for (int i = 1; i <= n; ++i) scanf ("%d", a + i);
    for (int i = 1; i <= m; ++i) scanf ("%d", b + i);
    if (n > m) { 
        for (int i = 1; i <= n; ++i) swap(a[i], b[i]);
        swap(n, m);
    }
    sort(a + 1, a + n + 1); 
    sort(b + 1, b + m + 1);
    int l = 0, r = (int)1e9;
    while (r - l > 1) { 
        int mid = l + r >> 1;
        if (ok(mid)) r = mid;
        else l = mid;
    }
    if (ok(l)) printf ("%d\n", l);
    else printf ("%d\n", r);
    return 0;
}

Compilation message

cipele.cpp: In function 'int main()':
cipele.cpp:42:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   42 |         int mid = l + r >> 1;
      |                   ~~^~~
cipele.cpp:31:11: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   31 |     scanf ("%d %d", &n, &m);
      |     ~~~~~~^~~~~~~~~~~~~~~~~
cipele.cpp:32:40: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   32 |     for (int i = 1; i <= n; ++i) scanf ("%d", a + i);
      |                                  ~~~~~~^~~~~~~~~~~~~
cipele.cpp:33:40: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   33 |     for (int i = 1; i <= m; ++i) scanf ("%d", b + i);
      |                                  ~~~~~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 36 ms 2284 KB Output is correct
2 Correct 52 ms 2540 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 56 ms 2284 KB Output is correct
2 Correct 69 ms 2560 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 364 KB Output is correct
2 Correct 4 ms 492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 364 KB Output is correct
2 Correct 4 ms 492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 492 KB Output is correct
2 Correct 4 ms 492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 364 KB Output is correct
2 Correct 4 ms 492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 364 KB Output is correct
2 Correct 3 ms 620 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 56 ms 2156 KB Output is correct
2 Correct 31 ms 1772 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 61 ms 2156 KB Output is correct
2 Correct 27 ms 2156 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 49 ms 2156 KB Output is correct
2 Correct 46 ms 2540 KB Output is correct