Submission #366416

# Submission time Handle Problem Language Result Execution time Memory
366416 2021-02-14T07:18:29 Z dolphingarlic The Kingdom of JOIOI (JOI17_joioi) C++14
100 / 100
3412 ms 53228 KB
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;

int n, m, mx, grid[2000][2000], tmp[2000][2000];

void rotate() {
    for (int i = 0; i < n; i++) for (int j = 0; j < m; j++)
        tmp[j][n - i - 1] = grid[i][j];
    swap(n, m);
    for (int i = 0; i < n; i++) for (int j = 0; j < m; j++)
        grid[i][j] = tmp[i][j];
}

bool check(int diff) {
    for (int _ : {0,0,0,0}) {
        int lmx = 0, lmn = mx, lst = m;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < lst; j++) if (grid[i][j] < mx - diff) {
                lst = j;
                break;
            }
            for (int j = lst; j < m; j++) lmx = max(lmx, grid[i][j]), lmn = min(lmn, grid[i][j]);
        }
        if (lmx - lmn <= diff) return true;
        rotate();
    }
    return false;
}

int main() {
    cin.tie(0)->sync_with_stdio(0);
    cin >> n >> m;
    for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) {
        cin >> grid[i][j];
        mx = max(mx, grid[i][j]);
    }
    int l = 0, r = mx;
    while (l != r) {
        int mid = (l + r) / 2;
        if (check(mid)) r = mid;
        else l = mid + 1;
    }
    cout << l;
    return 0;
}

Compilation message

joioi.cpp: In function 'bool check(int)':
joioi.cpp:16:14: warning: unused variable '_' [-Wunused-variable]
   16 |     for (int _ : {0,0,0,0}) {
      |              ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 2 ms 2028 KB Output is correct
16 Correct 5 ms 2284 KB Output is correct
17 Correct 12 ms 2540 KB Output is correct
18 Correct 12 ms 2540 KB Output is correct
19 Correct 11 ms 2540 KB Output is correct
20 Correct 9 ms 2560 KB Output is correct
21 Correct 16 ms 2684 KB Output is correct
22 Correct 14 ms 2688 KB Output is correct
23 Correct 14 ms 2668 KB Output is correct
24 Correct 16 ms 2796 KB Output is correct
25 Correct 14 ms 2668 KB Output is correct
26 Correct 15 ms 2688 KB Output is correct
27 Correct 15 ms 2668 KB Output is correct
28 Correct 17 ms 2668 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 2 ms 2028 KB Output is correct
16 Correct 5 ms 2284 KB Output is correct
17 Correct 12 ms 2540 KB Output is correct
18 Correct 12 ms 2540 KB Output is correct
19 Correct 11 ms 2540 KB Output is correct
20 Correct 9 ms 2560 KB Output is correct
21 Correct 16 ms 2684 KB Output is correct
22 Correct 14 ms 2688 KB Output is correct
23 Correct 14 ms 2668 KB Output is correct
24 Correct 16 ms 2796 KB Output is correct
25 Correct 14 ms 2668 KB Output is correct
26 Correct 15 ms 2688 KB Output is correct
27 Correct 15 ms 2668 KB Output is correct
28 Correct 17 ms 2668 KB Output is correct
29 Correct 2236 ms 46636 KB Output is correct
30 Correct 1871 ms 53228 KB Output is correct
31 Correct 2015 ms 42604 KB Output is correct
32 Correct 2426 ms 42528 KB Output is correct
33 Correct 2013 ms 51536 KB Output is correct
34 Correct 1844 ms 38124 KB Output is correct
35 Correct 3412 ms 42092 KB Output is correct
36 Correct 2305 ms 39688 KB Output is correct
37 Correct 2554 ms 41580 KB Output is correct