Submission #939242

#TimeUsernameProblemLanguageResultExecution timeMemory
939242qwe1rt1yuiop1The Kingdom of JOIOI (JOI17_joioi)C++14
0 / 100
0 ms600 KiB
#include <bits/stdc++.h> #define int long long using namespace std; void solve() { int n, m; cin >> n >> m; vector<vector<int>> v(n, vector<int>(m)); for (auto &i : v) for (auto &j : i) cin >> j; int l = 0, r = 1000000005; while (l < r) { int mid = (l + r) >> 1, ok = 1; vector<int> a(n), b(n); for (int i = 0; i < n; ++i) { int mx = v[i][0], mn = mx; for (a[i] = 0; a[i] < m; ++a[i]) { mx = max(mx, v[i][a[i]]); mn = min(mn, v[i][a[i]]); if (mx - mn > mid) break; } --a[i]; } for (int i = 0; i < n; ++i) { int mx = v[i][m - 1], mn = mx; for (b[i] = m - 1; b[i] >= 0; --b[i]) { mx = max(mx, v[i][b[i]]); mn = min(mn, v[i][b[i]]); if (mx - mn > mid) break; } ++b[i]; if (b[i] > a[i] + 1) { ok = 0; break; } } if (ok == 0) { l = mid + 1; continue; } int mn = a[0]; for (int i = 1; i < n; ++i) { mn = min(mn, a[i]); if (b[i] > mn + 1) { ok = 0; break; } } if (ok) { r = mid; continue; } int mx = b[0]; for (int i = 1; i < n; ++i) { mx = max(mx, b[i]); if (mx > a[i] + 1) { ok = 0; break; } } if (ok) r = mid; else l = mid + 1; } cout << l << '\n'; } /* 4 4 1 12 6 11 11 10 2 14 10 1 9 20 4 17 19 10 8 6 23 23 10 11 16 21 15 26 19 28 19 20 25 26 28 16 15 11 11 8 19 11 15 24 14 19 15 14 24 11 10 8 11 7 6 14 23 5 19 23 17 17 18 11 21 14 20 16 */ signed main() { ios::sync_with_stdio(0); cin.tie(0); solve(); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...