답안 #837426

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
837426 2023-08-25T10:46:23 Z unnick The Kingdom of JOIOI (JOI17_joioi) C++14
100 / 100
2765 ms 22140 KB
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

vector<int> alts;
vector<bool> arr;
int w,h;

bool valid(int lb, int ub, bool dx, bool dy) {
    for (int y = 0; y < h; y++) {
        for (int x = 0; x < w; x++) {
            // if (alts[x+y*w] > lb && alts[x+y*w] < ub) return false;
            arr[x+y*w] = (alts[x+y*w] > ub);
        }
    }
    for (int y = dy?h-1:0; y < h && y >= 0; y += dy?-1:1) {
        for (int x = dx?w-1:0; x < w && x >= 0; x += dx?-1:1) {
            bool tmp = arr[x+y*w];
            if (dx?x<w-1:x>0) tmp = tmp || arr[x+(dx?1:-1)+y*w];
            if (dy?y<h-1:y>0) tmp = tmp || arr[x+(y+(dy?1:-1))*w];
            if (tmp && alts[x+y*w] < lb) return false;
            arr[x+y*w] = tmp;
        }
    }
    return true;
}

int main() {
    cin >> h >> w;
    int la = 2000000000, ha = 0;
    for (int y = 0; y < h; y++) {
        for (int x = 0; x < w; x++) {
            int tmp;
            cin >> tmp;
            alts.push_back(tmp);
            la = min(la, tmp);
            ha = max(ha, tmp);
        }
    }
    arr.resize(w*h);
    int l = 0, h = ha-la;
    while (l+1<h) {
        int m = (l+h)/2;
        bool b = valid(ha-m, la+m, false, false) || valid(ha-m, la+m, true, false) || valid(ha-m, la+m, false, true) || valid(ha-m, la+m, true, true);
        if (b) {
            h = m;
        } else {
            l = m;
        }
    }
    cout << h << "\n";
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 292 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 296 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 304 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 300 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 292 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 296 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 304 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 300 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 7 ms 724 KB Output is correct
17 Correct 19 ms 852 KB Output is correct
18 Correct 16 ms 852 KB Output is correct
19 Correct 19 ms 948 KB Output is correct
20 Correct 20 ms 916 KB Output is correct
21 Correct 32 ms 1076 KB Output is correct
22 Correct 25 ms 1040 KB Output is correct
23 Correct 24 ms 1080 KB Output is correct
24 Correct 19 ms 980 KB Output is correct
25 Correct 30 ms 1028 KB Output is correct
26 Correct 27 ms 1024 KB Output is correct
27 Correct 29 ms 1084 KB Output is correct
28 Correct 30 ms 980 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 292 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 296 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 304 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 300 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 7 ms 724 KB Output is correct
17 Correct 19 ms 852 KB Output is correct
18 Correct 16 ms 852 KB Output is correct
19 Correct 19 ms 948 KB Output is correct
20 Correct 20 ms 916 KB Output is correct
21 Correct 32 ms 1076 KB Output is correct
22 Correct 25 ms 1040 KB Output is correct
23 Correct 24 ms 1080 KB Output is correct
24 Correct 19 ms 980 KB Output is correct
25 Correct 30 ms 1028 KB Output is correct
26 Correct 27 ms 1024 KB Output is correct
27 Correct 29 ms 1084 KB Output is correct
28 Correct 30 ms 980 KB Output is correct
29 Correct 1330 ms 19380 KB Output is correct
30 Correct 1464 ms 19388 KB Output is correct
31 Correct 1770 ms 19328 KB Output is correct
32 Correct 1520 ms 19344 KB Output is correct
33 Correct 1157 ms 19488 KB Output is correct
34 Correct 1685 ms 19344 KB Output is correct
35 Correct 2270 ms 21992 KB Output is correct
36 Correct 1797 ms 19968 KB Output is correct
37 Correct 2765 ms 22140 KB Output is correct