Submission #408880

#TimeUsernameProblemLanguageResultExecution timeMemory
408880MilosMilutinovicThe Kingdom of JOIOI (JOI17_joioi)C++14
100 / 100
1231 ms19472 KiB
#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 (stderr)

joioi.cpp: In lambda function:
joioi.cpp:42:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   42 |       int mid = bot + top >> 1;
      |                 ~~~~^~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...