Submission #365474

#TimeUsernameProblemLanguageResultExecution timeMemory
365474tushar_2658The Kingdom of JOIOI (JOI17_joioi)C++14
0 / 100
1 ms364 KiB
#include "bits/stdc++.h" using namespace std; const int maxn = 2005; using ll = long long; ll a[maxn][maxn], b[maxn][maxn]; int n, m; ll mn = 1e9, mx = -1e9; bool can(ll x){ for(int i = 1; i <= n; ++i){ int MX = 0; for(int j = 1; j <= m; ++j){ if(a[i][j] > mn + x){ MX = j; } } for(int j = 1; j < MX; ++j){ if(a[i][j] < mx - x){ return 0; } } } return 1; } void rotate(){ for(int i = 1; i <= n; ++i){ for(int j = 1; j <= m; ++j){ b[i][j] = a[i][j]; } } for(int i = m; i > 0; --i){ for(int j = 1; j <= n; ++j){ a[i][j] = b[j][m - i + 1]; } } } int main(int argc, char const *argv[]) { ios::sync_with_stdio(false); cin.tie(0); cin >> n >> m; for(int i = 1; i <= n; ++i){ for(int j = 1; j <= m; ++j){ cin >> a[i][j]; mn = min(a[i][j], mn); mx = max(a[i][j], mx); } } ll res = 1e9; for(int i = 1; i <= 4; ++i){ ll lo = 0, hi = 1e9, ans = -1; while(lo <= hi){ ll mid = (lo + hi) >> 1; if(can(mid)){ ans = mid; hi = mid - 1; }else { lo = mid + 1; } } res = min(res, ans); rotate(); } cout << res << '\n'; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...