답안 #213585

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
213585 2020-03-26T08:22:45 Z PeppaPig The Kingdom of JOIOI (JOI17_joioi) C++14
100 / 100
2435 ms 54904 KB
#include <bits/stdc++.h>

using namespace std;

const int N = 2e3+5;

int h, w, mn, mx;
int A[N][N], ans = 1e9;

void solve() {
    int l = 0, r = mx - mn;
    while(l <= r) {
        int mid = (l + r) >> 1;
        int pos = 0, valid = 1;
        for(int i = 1; i <= h; i++) {
            for(int j = 1; j <= w; j++) if(mx - A[i][j] > mid)
                pos = max(pos, j);
            for(int j = 1; j <= w; j++) if(A[i][j] - mn > mid)
                if(j <= pos) valid = 0;
        }
        if(valid) r = mid - 1, ans = min(ans, mid);
        else l = mid + 1;
    }
}

void flip_col() {
    for(int i = 1; i <= h; i++)
        for(int j = 1; j <= w / 2; j++)
            swap(A[i][j], A[i][w - j + 1]);
}

void flip_row() {
    for(int j = 1; j <= w; j++)
        for(int i = 1; i <= h / 2; i++)
            swap(A[i][j], A[h - i + 1][j]);
}

int main() {
    scanf("%d %d", &h, &w);
    mn = 1e9, mx = -1e9;
    for(int i = 1; i <= h; i++) for(int j = 1; j <= w; j++) {
        scanf("%d", A[i] + j);
        mn = min(mn, A[i][j]);
        mx = max(mx, A[i][j]);
    }
    solve();
    flip_col(), solve();
    flip_row(), solve();
    flip_col(), solve();
    printf("%d\n", ans);

    return 0;
}

Compilation message

joioi.cpp: In function 'int main()':
joioi.cpp:39:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d", &h, &w);
     ~~~~~^~~~~~~~~~~~~~~~~
joioi.cpp:42:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", A[i] + j);
         ~~~~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 256 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 420 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 512 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 256 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 420 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 512 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 14 ms 1408 KB Output is correct
17 Correct 23 ms 1664 KB Output is correct
18 Correct 21 ms 1536 KB Output is correct
19 Correct 24 ms 1536 KB Output is correct
20 Correct 22 ms 1408 KB Output is correct
21 Correct 28 ms 1664 KB Output is correct
22 Correct 27 ms 1664 KB Output is correct
23 Correct 30 ms 1664 KB Output is correct
24 Correct 24 ms 1664 KB Output is correct
25 Correct 31 ms 1664 KB Output is correct
26 Correct 28 ms 1664 KB Output is correct
27 Correct 28 ms 1664 KB Output is correct
28 Correct 28 ms 1664 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 256 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 420 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 512 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 14 ms 1408 KB Output is correct
17 Correct 23 ms 1664 KB Output is correct
18 Correct 21 ms 1536 KB Output is correct
19 Correct 24 ms 1536 KB Output is correct
20 Correct 22 ms 1408 KB Output is correct
21 Correct 28 ms 1664 KB Output is correct
22 Correct 27 ms 1664 KB Output is correct
23 Correct 30 ms 1664 KB Output is correct
24 Correct 24 ms 1664 KB Output is correct
25 Correct 31 ms 1664 KB Output is correct
26 Correct 28 ms 1664 KB Output is correct
27 Correct 28 ms 1664 KB Output is correct
28 Correct 28 ms 1664 KB Output is correct
29 Correct 1524 ms 37368 KB Output is correct
30 Correct 1531 ms 37624 KB Output is correct
31 Correct 1768 ms 39160 KB Output is correct
32 Correct 1587 ms 39160 KB Output is correct
33 Correct 1286 ms 34172 KB Output is correct
34 Correct 1707 ms 39288 KB Output is correct
35 Correct 2289 ms 54776 KB Output is correct
36 Correct 1779 ms 49656 KB Output is correct
37 Correct 2435 ms 54904 KB Output is correct