Submission #408880

# Submission time Handle Problem Language Result Execution time Memory
408880 2021-05-19T18:43:00 Z MilosMilutinovic The Kingdom of JOIOI (JOI17_joioi) C++14
100 / 100
1231 ms 19472 KB
#include <bits/stdc++.h>

using namespace std;

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  vector<vector<int>> a(n, vector<int>(m));
  int mn = 1e9, mx = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> a[i][j];
      mn = min(mn, a[i][j]);
      mx = max(mx, a[i][j]);
    }
  }
  auto Can = [&](int dif) {
    int col = 1e9;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        if (a[i][j] < mx - dif) {
          col = min(col, j);
        }
      }
      for (int j = 0; j < m; j++) {
        if (a[i][j] > mn + dif && j >= col) {
          return false;
        }
      }
    }
    return true;
  };
  int ans = 1e9;
  function<void()> Do = [&]() {
    int bot = 0, top = 1e9;
    while (bot <= top) {
      int mid = bot + top >> 1;
      if (Can(mid)) {
        ans = min(ans, mid);
        top = mid - 1;
      } else {
        bot = mid + 1;
      }
    }
  };
  Do();
  reverse(a.begin(), a.end());
  Do();
  for (int i = 0; i < n; i++) reverse(a[i].begin(), a[i].end());
  Do();
  reverse(a.begin(), a.end());
  Do();
  cout << ans << '\n';
  return 0;
}

Compilation message

joioi.cpp: In lambda function:
joioi.cpp:42:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   42 |       int mid = bot + top >> 1;
      |                 ~~~~^~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 312 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 316 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 308 KB Output is correct
10 Correct 1 ms 316 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 312 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 316 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 308 KB Output is correct
10 Correct 1 ms 316 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 12 ms 460 KB Output is correct
17 Correct 13 ms 748 KB Output is correct
18 Correct 13 ms 740 KB Output is correct
19 Correct 15 ms 744 KB Output is correct
20 Correct 12 ms 588 KB Output is correct
21 Correct 11 ms 844 KB Output is correct
22 Correct 11 ms 840 KB Output is correct
23 Correct 13 ms 832 KB Output is correct
24 Correct 10 ms 716 KB Output is correct
25 Correct 16 ms 844 KB Output is correct
26 Correct 11 ms 844 KB Output is correct
27 Correct 12 ms 844 KB Output is correct
28 Correct 13 ms 844 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 312 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 316 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 308 KB Output is correct
10 Correct 1 ms 316 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 12 ms 460 KB Output is correct
17 Correct 13 ms 748 KB Output is correct
18 Correct 13 ms 740 KB Output is correct
19 Correct 15 ms 744 KB Output is correct
20 Correct 12 ms 588 KB Output is correct
21 Correct 11 ms 844 KB Output is correct
22 Correct 11 ms 840 KB Output is correct
23 Correct 13 ms 832 KB Output is correct
24 Correct 10 ms 716 KB Output is correct
25 Correct 16 ms 844 KB Output is correct
26 Correct 11 ms 844 KB Output is correct
27 Correct 12 ms 844 KB Output is correct
28 Correct 13 ms 844 KB Output is correct
29 Correct 996 ms 16372 KB Output is correct
30 Correct 1050 ms 15940 KB Output is correct
31 Correct 1231 ms 17192 KB Output is correct
32 Correct 1067 ms 17212 KB Output is correct
33 Correct 925 ms 14968 KB Output is correct
34 Correct 1185 ms 17112 KB Output is correct
35 Correct 938 ms 18576 KB Output is correct
36 Correct 807 ms 15632 KB Output is correct
37 Correct 1074 ms 19472 KB Output is correct