답안 #734287

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
734287 2023-05-02T08:31:45 Z LucaIlie The Kingdom of JOIOI (JOI17_joioi) C++17
60 / 100
4000 ms 16096 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( 0 );
    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) >> 1;
        if ( check( mid ) )
            r = mid;
        else
            l = mid;
    }

    cout << r;

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 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 1 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 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 1 ms 340 KB Output is correct
14 Correct 0 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 7 ms 1236 KB Output is correct
18 Correct 6 ms 1232 KB Output is correct
19 Correct 7 ms 1236 KB Output is correct
20 Correct 6 ms 1108 KB Output is correct
21 Correct 9 ms 1236 KB Output is correct
22 Correct 9 ms 1160 KB Output is correct
23 Correct 8 ms 1208 KB Output is correct
24 Correct 7 ms 1108 KB Output is correct
25 Correct 7 ms 1236 KB Output is correct
26 Correct 8 ms 1288 KB Output is correct
27 Correct 8 ms 1196 KB Output is correct
28 Correct 9 ms 1236 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 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 1 ms 340 KB Output is correct
14 Correct 0 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 7 ms 1236 KB Output is correct
18 Correct 6 ms 1232 KB Output is correct
19 Correct 7 ms 1236 KB Output is correct
20 Correct 6 ms 1108 KB Output is correct
21 Correct 9 ms 1236 KB Output is correct
22 Correct 9 ms 1160 KB Output is correct
23 Correct 8 ms 1208 KB Output is correct
24 Correct 7 ms 1108 KB Output is correct
25 Correct 7 ms 1236 KB Output is correct
26 Correct 8 ms 1288 KB Output is correct
27 Correct 8 ms 1196 KB Output is correct
28 Correct 9 ms 1236 KB Output is correct
29 Correct 1869 ms 15152 KB Output is correct
30 Correct 2028 ms 16096 KB Output is correct
31 Correct 2691 ms 16076 KB Output is correct
32 Correct 2265 ms 15980 KB Output is correct
33 Correct 1588 ms 14060 KB Output is correct
34 Correct 2352 ms 15980 KB Output is correct
35 Execution timed out 4085 ms 15948 KB Time limit exceeded
36 Halted 0 ms 0 KB -