# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
365710 | mosiashvililuka | Maxcomp (info1cup18_maxcomp) | C++14 | 1 ms | 364 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;
int a,b,c,d,e,i,j,ii,jj,zx,xc,f[1004][1004],mn,mx,Xmn[1009],Xmx[1009],Ymn[1009],Ymx[1009],pas;
int main(){
ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
scanf("%d %d\n",&a,&b);
for(i=1; i<=a; i++){
for(j=1; j<=b; j++){
if(j!=b) scanf("%d ",&f[i][j]); else scanf("%d",&f[i][j]);
}
if(i!=a) scanf("\n");
}
if(a==1){
mn=2000000009;
for(i=1; i<=a; i++){
for(j=1; j<=b; j++){
if(mn>f[i][j]) mn=f[i][j];
if(mx<f[i][j]) mx=f[i][j];
}
}
cout<<mx-mn-2;
return 0;
}
if(a==1&&b==1){
cout<<-1;
return 0;
}
mn=2000000009;
for(i=1; i<=a; i++){
for(j=1; j<=b; j++){
if(mn>f[i][j]) mn=f[i][j];
if(mx<f[i][j]) mx=f[i][j];
}
}
for(i=1; i<=a; i++){
for(j=1; j<=b; j++){
if(f[i][j]==mn){
Xmn[i]=1;Ymn[j]=1;
}
if(f[i][j]==mx){
Xmx[i]=1;Ymx[j]=1;
}
}
}
for(i=1; i<=a; i++){
for(j=1; j<=b; j++){
if(f[i][j]==mn){
if(Xmx[i]==1||Ymx[j]==1){
cout<<mx-mn-2;
return 0;
}
}
if(f[i][j]==mx){
if(Xmn[i]==1||Ymn[j]==1){
cout<<mx-mn-2;
return 0;
}
}
}
}
cout<<mx-mn-3;
return 0;
}
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... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |