답안 #524130

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
524130 2022-02-08T16:51:21 Z FireGhost1301 The Kingdom of JOIOI (JOI17_joioi) C++11
0 / 100
1 ms 332 KB
#include <bits/stdc++.h>
using namespace std;

const int N = 2000 + 3;
int n, m, a[N][N];
int mi = INT_MAX, mx = 0;

bool chk(int d) {
    for (int i = 1, p = 1; i <= n; ++i) {
        for (int j = 1; j <= m; ++j) {
            if (a[i][j] + d < mx) p = max(p, j + 1);
        }
        for (int j = 1; j <= m; ++j) {
            if (a[i][j] - d > mi && j < p) return 0;
        }
    }
    return 1;
}

int calc() {
    int l = 0, r = mx - mi - 1, ans = r + 1, mid;
    while (l < r) {
        mid = (l + r) >> 1;
        if (chk(mid)) ans = mid, r = mid - 1;
        else l = mid + 1;
    }
    return ans;
}

void solve() {
    cin >> n >> m;
    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= m; ++j) {
            cin >> a[i][j];
            mx = max(mx, a[i][j]);
            mi = min(mi, a[i][j]);
        }
    }
    int ans = calc();
    reverse(a + 1, a + n + 1);
    ans = min(ans, calc());
    for (int i = 1; i <= n; ++i)
        reverse(a[i] + 1, a[i] + m + 1);
    ans = min(ans, calc());
    reverse(a + 1, a + n + 1);
    ans = min(ans, calc());
    cout << ans;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Incorrect 1 ms 320 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Incorrect 1 ms 320 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Incorrect 1 ms 320 KB Output isn't correct
3 Halted 0 ms 0 KB -