Submission #991905

#TimeUsernameProblemLanguageResultExecution timeMemory
991905imarnThe Kingdom of JOIOI (JOI17_joioi)C++14
100 / 100
533 ms54868 KiB
#include<bits/stdc++.h> #define ll long long #define pll pair<ll,ll> #define f first #define s second #define pb push_back #define all(x) x.begin(),x.end() using namespace std; int a[2005][2005]{0},mx=0,mn=1e9,h,w; bool ch(ll x){ int id=w+1; for(int i=1;i<=h;i++){ for(int j=1;j<=w;j++){ if(mx-a[i][j]>x)id=min(id,j); } for(int j=id;j<=w;j++){ if(a[i][j]-mn>x)return 0; } }return 1; } ll solve(){ ll l=0,r=mx-mn; while(l<r){ ll m=(l+r)>>1; if(ch(m))r=m; else l=m+1; }return l; } int main(){ ios_base::sync_with_stdio(0);cin.tie(0); cin>>h>>w; for(int i=1;i<=h;i++)for(int j=1;j<=w;j++)cin>>a[i][j],mx=max(mx,a[i][j]),mn=min(mn,a[i][j]); ll ans=1e9; ans=min(solve(),ans); for(int i=1;i<=h;i++)for(int j=1;j<=w/2;j++)swap(a[i][j],a[i][w-j+1]); ans=min(solve(),ans); for(int j=1;j<=w;j++)for(int i=1;i<=h/2;i++)swap(a[i][j],a[h-i+1][j]); ans=min(solve(),ans); for(int i=1;i<=h;i++)for(int j=1;j<=w/2;j++)swap(a[i][j],a[i][w-j+1]); ans=min(solve(),ans); cout<<ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...