Submission #819345

# Submission time Handle Problem Language Result Execution time Memory
819345 2023-08-10T09:35:38 Z vjudge1 Cipele (COCI18_cipele) C++17
18 / 90
34 ms 2248 KB
#include <cstdio>
#include <algorithm>
using namespace std;
const int mxn = 100000;
int n, m, i, j, *a = new int[mxn], *b = new int[mxn], l[mxn], r[mxn], dp[mxn][2];
int main() {
    scanf("%d%d", &n, &m);
    for (i = 0; i < n; i++) scanf("%d", a + i);
    for (i = 0; i < m; i++) scanf("%d", b + i);
    sort(a, a + n);
    sort(b, b + m);
    if (n == m) {
        for (i = 0; i < n; i++) {
            if (j < abs(a[i] - b[i])) j = abs(a[i] - b[i]);
        }
        printf("%d", j);
        return 0;
    }
    if (n > m) {
        swap(a, b);
        swap(m, n);
    }
    // printf("n = %d, m = %d\n", n, m);
    for (i = j = 0; i < n; i++) {
        while (j < m && b[j] < a[i]) j++;
        l[i] = j - 1; r[i] = j;
        // printf("l[%d] = %d, r[%d] = %d\n", i, l[i], i, r[i]);
    }
    dp[0][0] = l[0] < 0 ? 0 : a[0] - b[l[0]];
    dp[0][1] = b[r[0]] - a[0];
    for (i = 1; i < n; i++) {
        if (l[i] == r[i - 1]) {
            dp[i][0] = max(dp[i - 1][0], a[i] - b[l[i]]);
            dp[i][1] = max(min(dp[i - 1][0], dp[i - 1][1]), b[r[i]] - a[i]);
        }
        else if (l[i] == l[i - 1]) {
            dp[i][0] = max(dp[i - 1][1], a[i] - b[l[i]]);
            dp[i][1] = max(dp[i - 1][0], b[r[i]] - a[i]);
        }
        else {
            dp[i][0] = max(min(dp[i - 1][0], dp[i - 1][1]), a[i] - b[l[i]]);
            dp[i][1] = max(min(dp[i - 1][0], dp[i - 1][1]), b[r[i]] - a[i]);
        }
    }
    printf("%d", min(*dp[n - 1], dp[n - 1][1]));
    return 0;
}

Compilation message

cipele.cpp: In function 'int main()':
cipele.cpp:7:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    7 |     scanf("%d%d", &n, &m);
      |     ~~~~~^~~~~~~~~~~~~~~~
cipele.cpp:8:34: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    8 |     for (i = 0; i < n; i++) scanf("%d", a + i);
      |                             ~~~~~^~~~~~~~~~~~~
cipele.cpp:9:34: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    9 |     for (i = 0; i < m; i++) scanf("%d", b + i);
      |                             ~~~~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 17 ms 980 KB Output is correct
2 Correct 29 ms 1008 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 30 ms 1140 KB Output is correct
2 Correct 30 ms 1076 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Incorrect 2 ms 340 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Incorrect 2 ms 340 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 24 ms 1888 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 34 ms 2248 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 27 ms 1868 KB Output isn't correct
2 Halted 0 ms 0 KB -