답안 #734282

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
734282 2023-05-02T08:24:18 Z LucaIlie The Kingdom of JOIOI (JOI17_joioi) C++17
60 / 100
4000 ms 54796 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], lin[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 >> 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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 304 KB Output is correct
3 Correct 1 ms 312 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 304 KB Output is correct
6 Correct 0 ms 304 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 1 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 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 304 KB Output is correct
3 Correct 1 ms 312 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 304 KB Output is correct
6 Correct 0 ms 304 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 1 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 1 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 9 ms 1216 KB Output is correct
17 Correct 16 ms 1476 KB Output is correct
18 Correct 14 ms 1508 KB Output is correct
19 Correct 15 ms 1468 KB Output is correct
20 Correct 14 ms 1356 KB Output is correct
21 Correct 20 ms 1620 KB Output is correct
22 Correct 21 ms 1596 KB Output is correct
23 Correct 19 ms 1552 KB Output is correct
24 Correct 17 ms 1464 KB Output is correct
25 Correct 22 ms 1564 KB Output is correct
26 Correct 23 ms 1524 KB Output is correct
27 Correct 22 ms 1596 KB Output is correct
28 Correct 20 ms 1516 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 304 KB Output is correct
3 Correct 1 ms 312 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 304 KB Output is correct
6 Correct 0 ms 304 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 1 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 1 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 9 ms 1216 KB Output is correct
17 Correct 16 ms 1476 KB Output is correct
18 Correct 14 ms 1508 KB Output is correct
19 Correct 15 ms 1468 KB Output is correct
20 Correct 14 ms 1356 KB Output is correct
21 Correct 20 ms 1620 KB Output is correct
22 Correct 21 ms 1596 KB Output is correct
23 Correct 19 ms 1552 KB Output is correct
24 Correct 17 ms 1464 KB Output is correct
25 Correct 22 ms 1564 KB Output is correct
26 Correct 23 ms 1524 KB Output is correct
27 Correct 22 ms 1596 KB Output is correct
28 Correct 20 ms 1516 KB Output is correct
29 Correct 2252 ms 37144 KB Output is correct
30 Correct 2473 ms 37308 KB Output is correct
31 Correct 2874 ms 39028 KB Output is correct
32 Correct 2589 ms 38996 KB Output is correct
33 Correct 2032 ms 34044 KB Output is correct
34 Correct 2694 ms 39168 KB Output is correct
35 Correct 3864 ms 54620 KB Output is correct
36 Correct 3145 ms 49492 KB Output is correct
37 Execution timed out 4016 ms 54796 KB Time limit exceeded
38 Halted 0 ms 0 KB -