답안 #365710

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
365710 2021-02-12T08:39:35 Z mosiashvililuka Maxcomp (info1cup18_maxcomp) C++14
0 / 100
1 ms 364 KB
#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

maxcomp.cpp: In function 'int main()':
maxcomp.cpp:6:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    6 |  scanf("%d %d\n",&a,&b);
      |  ~~~~~^~~~~~~~~~~~~~~~~
maxcomp.cpp:9:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    9 |    if(j!=b) scanf("%d ",&f[i][j]); else scanf("%d",&f[i][j]);
      |             ~~~~~^~~~~~~~~~~~~~~~
maxcomp.cpp:9:46: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    9 |    if(j!=b) scanf("%d ",&f[i][j]); else scanf("%d",&f[i][j]);
      |                                         ~~~~~^~~~~~~~~~~~~~~
maxcomp.cpp:11:17: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   11 |   if(i!=a) scanf("\n");
      |            ~~~~~^~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 364 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 364 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 364 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 364 KB Output isn't correct
2 Halted 0 ms 0 KB -