Submission #870458

#TimeUsernameProblemLanguageResultExecution timeMemory
870458phoenix0423The Kingdom of JOIOI (JOI17_joioi)C++17
0 / 100
1 ms468 KiB
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pll; #define fastio ios::sync_with_stdio(false), cin.tie(0) #define pb push_back #define eb emplace_back #define f first #define s second #define lowbit(x) x&-x const int N = 998244353; const int INF = 1e9; const int maxn = 2005; ll a[maxn][maxn]; int main(void){ fastio; int h, w; cin>>h>>w; ll mn = INF, mx = 0; for(int i = 0; i < h; i++){ for(int j = 0; j < w; j++){ cin>>a[i][j]; mn = min(mn, a[i][j]); mx = max(mx, a[i][j]); } } int ng = -1, ok = INF + 5; while(ng + 1 < ok){ int m = (ng + ok) / 2; int bad = 0; vector<int> mnx(h + 1, INF), mn2x(h + 1, INF); for(int i = 0; i < h; i++){ for(int j = 0; j < w; j++){ if(a[i][j] > mn + m && a[i][j] < mx - m) bad = 1; if(a[i][j] > mn + m) mnx[i] = min(mnx[i], j); if(a[i][j] < mx - m) mn2x[i] = min(mn2x[i], j); } } if(bad){ ng = m; continue; } vector<int> lst(mn2x), lsb(mn2x), grt(mnx), grb(mnx); for(int i = 1; i < h; i++) lst[i] = min(lst[i], lst[i - 1]), grt[i] = min(grt[i], grt[i - 1]); for(int i = h - 2; i >= 0; i--) lsb[i] = min(lsb[i], lsb[i + 1]), grb[i] = min(grb[i], grb[i + 1]); vector<int> gd(4, 1); for(int i = 0; i < h; i++){ for(int j = 0; j < w; j++){ if(a[i][j] > mn + m){ if(j > lst[i]) gd[0] = 0; if(j > lsb[i]) gd[1] = 0; } if(a[i][j] < mx - m){ if(j > grt[i]) gd[2] = 0; if(j > grb[i]) gd[3] = 0; } } } if(gd[0] + gd[1] + gd[2] + gd[3]) ok = m; else ng = m; } cout<<ok<<"\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...