Submission #734286

# Submission time Handle Problem Language Result Execution time Memory
734286 2023-05-02T08:31:21 Z LucaIlie The Kingdom of JOIOI (JOI17_joioi) C++17
100 / 100
3832 ms 16204 KB
#include <bits/stdc++.h>

using namespace std;

const int MAX_N = 2000 + 1;
int n, m, minn = 2e9, maxx = 0;
int mat[MAX_N][MAX_N];

bool check( int x ) {
    int last;
    bool sePoate;

    sePoate = true;
    last = n;
    for ( int c = 0; c < m; c++ ) {
        int l = 0;
        while ( l < last && mat[l][c] - minn <= x )
            l++;
        last = l;
        for ( ; l < n; l++ ) {
            if ( maxx - mat[l][c] > x )
                sePoate = false;
        }
    }
    if ( sePoate )
        return true;

    sePoate = true;
    last = n;
    for ( int c = m - 1; c >= 0; c-- ) {
        int l = 0;
        while ( l < last && mat[l][c] - minn <= x )
            l++;
        last = l;
        for ( ; l < n; l++ ) {
            if ( maxx - mat[l][c] > x )
                sePoate = false;
        }
    }
    if ( sePoate )
        return true;

    last = n;
    sePoate = true;
    for ( int c = 0; c < m; c++ ) {
        int l = 0;
        while ( l < last && maxx - mat[l][c] <= x )
            l++;
        last = l;
        for ( ; l < n; l++ ) {
            if ( mat[l][c] - minn > x )
                sePoate = false;
        }
    }
    if ( sePoate )
        return true;

    last = n;
    sePoate = true;
    for ( int c = m - 1; c >= 0; c-- ) {
        int l = 0;
        while ( l < last && maxx - mat[l][c] <= x )
            l++;
        last = l;
        for ( ; l < n; l++ ) {
            if ( mat[l][c] - minn > x )
                sePoate = false;
        }
    }
    if ( sePoate )
        return true;

    return false;

}

int main() {
    cin.tie( NULL );
    ios_base::sync_with_stdio( false );

    cin >> n >> m;
    for ( int l = 0; l < n; l++ ) {
        for ( int c = 0; c < m; c++ ) {
            cin >> mat[l][c];
            minn = min( minn, mat[l][c] );
            maxx = max( maxx, mat[l][c] );
        }
    }

    int l = -1, r = maxx - minn;
    while ( r - l > 1 ) {
        int mid = (l + r) / 2;
        if ( check( mid ) )
            r = mid;
        else
            l = mid;
    }

    cout << r;

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 3 ms 1236 KB Output is correct
17 Correct 6 ms 1236 KB Output is correct
18 Correct 9 ms 1236 KB Output is correct
19 Correct 7 ms 1236 KB Output is correct
20 Correct 6 ms 1108 KB Output is correct
21 Correct 8 ms 1236 KB Output is correct
22 Correct 9 ms 1280 KB Output is correct
23 Correct 7 ms 1236 KB Output is correct
24 Correct 7 ms 1108 KB Output is correct
25 Correct 7 ms 1244 KB Output is correct
26 Correct 8 ms 1236 KB Output is correct
27 Correct 10 ms 1224 KB Output is correct
28 Correct 9 ms 1264 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 3 ms 1236 KB Output is correct
17 Correct 6 ms 1236 KB Output is correct
18 Correct 9 ms 1236 KB Output is correct
19 Correct 7 ms 1236 KB Output is correct
20 Correct 6 ms 1108 KB Output is correct
21 Correct 8 ms 1236 KB Output is correct
22 Correct 9 ms 1280 KB Output is correct
23 Correct 7 ms 1236 KB Output is correct
24 Correct 7 ms 1108 KB Output is correct
25 Correct 7 ms 1244 KB Output is correct
26 Correct 8 ms 1236 KB Output is correct
27 Correct 10 ms 1224 KB Output is correct
28 Correct 9 ms 1264 KB Output is correct
29 Correct 1517 ms 15308 KB Output is correct
30 Correct 1781 ms 16204 KB Output is correct
31 Correct 2229 ms 15960 KB Output is correct
32 Correct 1979 ms 16076 KB Output is correct
33 Correct 1178 ms 14180 KB Output is correct
34 Correct 2091 ms 15928 KB Output is correct
35 Correct 3832 ms 15856 KB Output is correct
36 Correct 2558 ms 16148 KB Output is correct
37 Correct 3582 ms 16028 KB Output is correct