제출 #849494

#제출 시각아이디문제언어결과실행 시간메모리
849494qthang2k11The Kingdom of JOIOI (JOI17_joioi)C++17
0 / 100
0 ms348 KiB
#include <bits/stdc++.h> using namespace std; const int N = 2003, MAX = 1e9; int m, n, a[N][N], mi = MAX, mx = 0, ans = MAX; bool ok(int f) { int lst = n; for (int i = 1; i <= m; i++) { for (int j = 0; j < lst; j++) { if (mi + f < a[i][j]) { lst = j; break; } } for (int j = n; j > lst; j--) if (mx - f > a[i][j]) return false; } return true; } void deal() { int l = 0, r = ans; while (l <= r) { int mid = (l + r) / 2; if (ok(mid)) { ans = mid; r = mid - 1; } else l = mid + 1; } } void flip_col() { for (int i = m / 2; i > 0; i--) for (int j = 1; j <= n; j++) swap(a[i][j], a[m - i + 1][j]); } void flip_row() { for (int i = 1; i <= m; i++) for (int j = n / 2; j > 0; j--) swap(a[i][j], a[i][n - j + 1]); } int32_t main() { cin.tie(0)->sync_with_stdio(0); cin >> m >> n; for (int i = 1; i <= m; i++) { for (int j = 1; j <= n; j++) { cin >> a[i][j]; mi = min(mi, a[i][j]); mx = max(mx, a[i][j]); } } ans = mx - mi; deal(); flip_col(); deal(); flip_row(); deal(); flip_col(); deal(); cout << ans; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...