# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
706359 | Baytoro | The Kingdom of JOIOI (JOI17_joioi) | C++17 | 1 ms | 340 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define ios ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fr first
#define sc second
#define endl '\n'
#define ll long long
#define int long long
void fopn(string name){
freopen((name+".in").c_str(),"r",stdin);
freopen((name+".out").c_str(),"w",stdout);
}
const ll INF=1e18,mod=998244353;
const int N=2005;
int a[N][N],tmp[N][N];
int n,m;
int calc(int x){
int mn=INF,mx=-INF;
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++)
mn=min(mn,tmp[i][j]),mx=max(mx,tmp[i][j]);
}
for(int i=1, l=m+1;i<=n;i++){
for(int j=1;j<l;j++){
if(tmp[i][j]-mn>x){
l=j;
break;
}
}
for(int j=l+1;j<=m;j++){
if(mx-tmp[i][j]>x) return false;
}
}
return true;
}
int check(int x){
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
tmp[i][j]=a[i][j];
for(int I=0;I<2;I++){
for(int J=0;J<2;J++){
if(calc(x)) return true;
for(int i=1;i<=n;i++){
for(int l=1,r=m;l<r;l++,r--){
swap(tmp[i][l],tmp[i][r]);
}
}
}
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
tmp[i][j]=-tmp[i][j];
}
return false;
}
void solve(){
cin>>n>>m;
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
cin>>a[i][j];
}
}
int l=-1,r=1e9;
while(r-l>1){
int md=(l+r)/2;
if(check(md)) r=md;
else l=md;
}
cout<<r;
}
main(){
//fopn("cbarn");
ios;
int T=1;
//cin>>T;
while(T--){
solve();
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |