답안 #973974

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
973974 2024-05-02T14:08:56 Z vjudge1 Cipele (COCI18_cipele) C++14
0 / 90
1000 ms 348 KB
#include <bits/stdc++.h>

#define abs(x) (x < 0 ? -x : x)

int read(int x = 0, int f = 0, char ch = getchar())
{
    while ('0' > ch or ch > '9')
        f = ch == '-', ch = getchar();
    while ('0' <= ch and ch <= '9')
        x = x * 10 + (ch ^ 48), ch = getchar();
    return f ? -x : x;
}

const int N = 1e5 + 5;

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

int judge(int x, int res = 0)
{
    for (int i = 0, now = 0; i < n; i++)
    {
        while (now < m and b[now] < a[i] - x)
            now++;
        if (now < m and abs(b[now] - a[i]) <= x)
            res++, now++;
    }
    return res;
}

int main()
{
#ifndef ONLINE_JUDGE
    freopen("cipele.in", "r", stdin);
    freopen("cipele.out", "w", stdout);
#endif // !ONLINE_JUDGE
    n = read(), m = read();
    for (int i = 0; i < n; i++)
        a[i] = read();
    for (int i = 0; i < m; i++)
        b[i] = read();
    std::sort(a, a + n), std::sort(b, b + m);
    for (int L = 0, R = 1e9, mid; L <= R;)
        if (judge(mid = (L + R) >> 1) == std::min(n, m))
            ans = mid, R = mid - 1;
        else
            L = mid + 1;
    return printf("%d", ans), 0;
}

Compilation message

cipele.cpp: In function 'int main()':
cipele.cpp:34:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   34 |     freopen("cipele.in", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
cipele.cpp:35:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   35 |     freopen("cipele.out", "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1059 ms 348 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1069 ms 348 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1033 ms 348 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1042 ms 348 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1022 ms 344 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1045 ms 348 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1040 ms 344 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1053 ms 348 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1040 ms 348 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1066 ms 348 KB Time limit exceeded
2 Halted 0 ms 0 KB -