답안 #140529

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
140529 2019-08-03T11:33:06 Z meatrow The Kingdom of JOIOI (JOI17_joioi) C++17
15 / 100
13 ms 1528 KB
//#pragma GCC optimize("O3")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,tune=native")
//#pragma GCC optimize ("unroll-loops")
#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using ld = long double;

const int N = 2000;

int a[N][N];
int bot[N];
int b[N];
int mx;

int solve(int h, int w) {
    for (int i = 0; i < h; i++) {
        b[i] = 0;
        for (int j = 0; j < w; j++) {
            if (a[i][j] == mx) {
                b[i] = j;
            }
        }
    }
    int l = -1, r = 1e9;
    while (l + 1 < r) {
        int mid = (l + r) / 2;
        for (int i = 0; i < h; i++) {
            bot[i] = w;
            for (int j = 0; j < w; j++) {
                if (a[i][j] + mid < mx) {
                    bot[i] = j;
                    break;
                }
            }
        }
        //decreasing
        int d = w - 1;
        bool f = true;
        int kek1 = mx;
        int kek2 = 0;
        for (int i = 0; i < h; i++) {
            d = min(d, bot[i] - 1);
            if (d < b[i]) {
                f = false;
                break;
            }
            for (int j = d + 1; j < w; j++) {
                kek1 = min(kek1, a[i][j]);
                kek2 = max(kek2, a[i][j]);
            }
        }
        if (f && kek2 - kek1 <= mid) {
            r = mid;
            continue;
        }
        l = mid;
    }
    return r;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int h, w;
    cin >> h >> w;
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            cin >> a[i][j];
            mx = max(mx, a[i][j]);
        }
    }
    int ans = solve(h, w);
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w / 2; j++) {
            swap(a[i][j], a[i][w - j - 1]);
        }
    }
    ans = min(ans, solve(h, w));
    for (int j = 0; j < w; j++) {
        for (int i = 0; i < h / 2; i++) {
            swap(a[i][j], a[h - i - 1][j]);
        }
    }
    ans = min(ans, solve(h, w));
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w / 2; j++) {
            swap(a[i][j], a[i][w - j - 1]);
        }
    }
    ans = min(ans, solve(h, w));
    cout << ans;
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 504 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 392 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 504 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 392 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 3 ms 504 KB Output is correct
16 Correct 9 ms 1400 KB Output is correct
17 Correct 13 ms 1528 KB Output is correct
18 Correct 12 ms 1528 KB Output is correct
19 Incorrect 13 ms 1528 KB Output isn't correct
20 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 504 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 392 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 3 ms 504 KB Output is correct
16 Correct 9 ms 1400 KB Output is correct
17 Correct 13 ms 1528 KB Output is correct
18 Correct 12 ms 1528 KB Output is correct
19 Incorrect 13 ms 1528 KB Output isn't correct
20 Halted 0 ms 0 KB -