Submission #595061

# Submission time Handle Problem Language Result Execution time Memory
595061 2022-07-13T10:16:46 Z piOOE The Kingdom of JOIOI (JOI17_joioi) C++17
100 / 100
3381 ms 19944 KB
#include <bits/stdc++.h>

using namespace std;

using ll = long long;

const int N = 2001;

int a[N][N], n, m, mx;
bool t[N][N];

void mirror() {
    for (int i = 0; i < n; ++i) {
        reverse(a[i], a[i] + m);
    }
}

void rotate180() {
    for (int j = 0; j < m; ++j) {
        for (int i = 0; i < n / 2; ++i) {
            swap(a[i][j], a[n - i - 1][j]);
        }
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> n >> m;
    mx = -1;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < m; ++j) {
            cin >> a[i][j];
            mx = max(mx, a[i][j]);
        }
    }
    auto check = [&](int mid) -> bool {
        for (int _ = 0; _ < 2; ++_) {
            for (int iter = 0; iter < 2; ++iter) {
                memset(t, 0, sizeof(t));
                int pos = m;
                for (int i = 0; i < n; ++i) {
                    for (int j = 0; j < pos; ++j) {
                        if (mx - a[i][j] <= mid) {
                            t[i][j] = true;
                        } else {
                            pos = j;
                            break;
                        }
                    }
                }
                int Max = -1, Min = mx;
                for (int i = 0; i < n; ++i) {
                    for (int j = 0; j < m; ++j) {
                        if (!t[i][j]) {
                            Max = max(a[i][j], Max);
                            Min = min(a[i][j], Min);
                        }
                    }
                }
                if (Max == -1 || Max - Min <= mid) {
                    return true;
                }
                rotate180();
            }
            mirror();
        }
        return false;
    };
    int l = -1, r = mx;
    while (l + 1 < r) {
        int mid = (l + r) >> 1;
        if (check(mid)) {
            r = mid;
        } else {
            l = mid;
        }
    }
    cout << r;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 4180 KB Output is correct
2 Correct 3 ms 4188 KB Output is correct
3 Correct 11 ms 4172 KB Output is correct
4 Correct 11 ms 4164 KB Output is correct
5 Correct 10 ms 4180 KB Output is correct
6 Correct 11 ms 4180 KB Output is correct
7 Correct 9 ms 4164 KB Output is correct
8 Correct 13 ms 4180 KB Output is correct
9 Correct 15 ms 4180 KB Output is correct
10 Correct 12 ms 4284 KB Output is correct
11 Correct 11 ms 4280 KB Output is correct
12 Correct 16 ms 4180 KB Output is correct
13 Correct 10 ms 4172 KB Output is correct
14 Correct 11 ms 4180 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 4180 KB Output is correct
2 Correct 3 ms 4188 KB Output is correct
3 Correct 11 ms 4172 KB Output is correct
4 Correct 11 ms 4164 KB Output is correct
5 Correct 10 ms 4180 KB Output is correct
6 Correct 11 ms 4180 KB Output is correct
7 Correct 9 ms 4164 KB Output is correct
8 Correct 13 ms 4180 KB Output is correct
9 Correct 15 ms 4180 KB Output is correct
10 Correct 12 ms 4284 KB Output is correct
11 Correct 11 ms 4280 KB Output is correct
12 Correct 16 ms 4180 KB Output is correct
13 Correct 10 ms 4172 KB Output is correct
14 Correct 11 ms 4180 KB Output is correct
15 Correct 4 ms 4296 KB Output is correct
16 Correct 8 ms 5264 KB Output is correct
17 Correct 20 ms 5436 KB Output is correct
18 Correct 18 ms 5448 KB Output is correct
19 Correct 25 ms 5440 KB Output is correct
20 Correct 17 ms 5328 KB Output is correct
21 Correct 29 ms 5444 KB Output is correct
22 Correct 21 ms 5336 KB Output is correct
23 Correct 30 ms 5436 KB Output is correct
24 Correct 31 ms 5332 KB Output is correct
25 Correct 23 ms 5432 KB Output is correct
26 Correct 20 ms 5332 KB Output is correct
27 Correct 26 ms 5332 KB Output is correct
28 Correct 32 ms 5448 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 4180 KB Output is correct
2 Correct 3 ms 4188 KB Output is correct
3 Correct 11 ms 4172 KB Output is correct
4 Correct 11 ms 4164 KB Output is correct
5 Correct 10 ms 4180 KB Output is correct
6 Correct 11 ms 4180 KB Output is correct
7 Correct 9 ms 4164 KB Output is correct
8 Correct 13 ms 4180 KB Output is correct
9 Correct 15 ms 4180 KB Output is correct
10 Correct 12 ms 4284 KB Output is correct
11 Correct 11 ms 4280 KB Output is correct
12 Correct 16 ms 4180 KB Output is correct
13 Correct 10 ms 4172 KB Output is correct
14 Correct 11 ms 4180 KB Output is correct
15 Correct 4 ms 4296 KB Output is correct
16 Correct 8 ms 5264 KB Output is correct
17 Correct 20 ms 5436 KB Output is correct
18 Correct 18 ms 5448 KB Output is correct
19 Correct 25 ms 5440 KB Output is correct
20 Correct 17 ms 5328 KB Output is correct
21 Correct 29 ms 5444 KB Output is correct
22 Correct 21 ms 5336 KB Output is correct
23 Correct 30 ms 5436 KB Output is correct
24 Correct 31 ms 5332 KB Output is correct
25 Correct 23 ms 5432 KB Output is correct
26 Correct 20 ms 5332 KB Output is correct
27 Correct 26 ms 5332 KB Output is correct
28 Correct 32 ms 5448 KB Output is correct
29 Correct 2149 ms 19112 KB Output is correct
30 Correct 1662 ms 19896 KB Output is correct
31 Correct 1802 ms 19884 KB Output is correct
32 Correct 2165 ms 19896 KB Output is correct
33 Correct 1777 ms 17980 KB Output is correct
34 Correct 1888 ms 19944 KB Output is correct
35 Correct 3381 ms 19892 KB Output is correct
36 Correct 2191 ms 19808 KB Output is correct
37 Correct 2313 ms 19900 KB Output is correct