답안 #73776

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
73776 2018-08-29T02:28:22 Z KLPP The Kingdom of JOIOI (JOI17_joioi) C++14
100 / 100
3623 ms 209992 KB
#include<iostream>
#include<stdio.h>

using namespace std;
int h,w;
int A[2000][2000];
int M,m;
bool test(int x){//cout<<x<<endl;
	int region[h][w];
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++)region[i][j]=-1;
	}
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			if(A[i][j]>m+x){
				if(region[i][j]==-1)region[i][j]=1;
				else return false;
			}
			if(A[i][j]<M-x){
				if(region[i][j]==-1)region[i][j]=0;
				else return false;
			}//cout<<region[i][j]<<" ";
		}
	}
	/*for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			cout<<region[i][j]<<" ";
		}cout<<endl;
	}cout<<endl;*/
	int loH[h+w][2];
	int hiH[h+w][2];
	//compute hi
	for(int i=0;i<h;i++){
		hiH[i][0]=-1;
		hiH[i][1]=-1;
		for(int j=0;j<w;j++){
			if(region[i][j]==0)hiH[i][0]=j;
			if(region[i][j]==1)hiH[i][1]=j;
		}
		//cout<<hiH[i][0]<<" "<<hiH[i][1]<<endl;
	}
	//compute lo
	for(int i=0;i<h;i++){
		loH[i][0]=w;
		loH[i][1]=w;
		for(int j=w-1;j>-1;j--){
			if(region[i][j]==0)loH[i][0]=j;
			if(region[i][j]==1)loH[i][1]=j;
		}
		//cout<<loH[i][0]<<" "<<loH[i][1]<<endl;
	}
	int Hi;
	bool b;
	Hi=-1;
	b=true;
	for(int i=0;i<h;i++){
		Hi=max(Hi,hiH[i][0]);
		if(Hi>=loH[i][1])b=false;
	}
	if(b)return true;
	b=true;
	Hi=-1;
	for(int i=0;i<h;i++){
		Hi=max(Hi,hiH[i][1]);
		if(Hi>=loH[i][0])b=false;
	}
	if(b)return true;
	Hi=-1;
	b=true;
	for(int i=h-1;i>-1;i--){
		Hi=max(Hi,hiH[i][0]);
		if(Hi>=loH[i][1])b=false;
	}
	if(b)return true;
	b=true;
	Hi=-1;
	for(int i=h-1;i>-1;i--){
		Hi=max(Hi,hiH[i][1]);
		if(Hi>=loH[i][0])b=false;
	}
	if(b)return true;
	//compute hi
	for(int i=0;i<w;i++){
		hiH[i][0]=-1;
		hiH[i][1]=-1;
		for(int j=0;j<h;j++){
			if(region[j][i]==0)hiH[i][0]=j;
			if(region[j][i]==1)hiH[i][1]=j;
		}
	}
	//compute lo
	for(int i=0;i<w;i++){
		loH[i][0]=h;
		loH[i][1]=h;
		for(int j=h-1;j>-1;j--){
			if(region[j][i]==0)loH[i][0]=j;
			if(region[j][i]==1)loH[i][1]=j;
		}
	}
	Hi=-1;
	b=true;
	for(int i=0;i<w;i++){
		Hi=max(Hi,hiH[i][0]);
		if(Hi>=loH[i][1])b=false;
	}
	if(b)return true;
	b=true;
	Hi=-1;
	for(int i=0;i<w;i++){
		Hi=max(Hi,hiH[i][1]);
		if(Hi>=loH[i][0])b=false;
	}
	if(b)return true;
	Hi=-1;
	b=true;
	for(int i=w-1;i>-1;i--){
		Hi=max(Hi,hiH[i][0]);
		if(Hi>=loH[i][1])b=false;
	}
	if(b)return true;
	b=true;
	Hi=-1;
	for(int i=w-1;i>-1;i--){
		Hi=max(Hi,hiH[i][1]);
		if(Hi>=loH[i][0])b=false;
	}
	if(b)return true;
	
	return false;
}
int main(){
	scanf("%d %d",&h,&w);
	M=-1;
	m=1000000001;
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			scanf("%d",&A[i][j]);
			M=max(M,A[i][j]);
			m=min(m,A[i][j]);
		}
	}
	int hi,lo;
	lo=-1;
	hi=M-m;
	while(hi-lo>1){
		int mid=(hi+lo)/2;
		bool b=test(mid);
		if(b)hi=mid;
		else lo=mid;
	}printf("%d",hi);
	return 0;
}

Compilation message

joioi.cpp: In function 'int main()':
joioi.cpp:132:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d",&h,&w);
  ~~~~~^~~~~~~~~~~~~~~
joioi.cpp:137:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    scanf("%d",&A[i][j]);
    ~~~~~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 2 ms 484 KB Output is correct
3 Correct 3 ms 484 KB Output is correct
4 Correct 3 ms 484 KB Output is correct
5 Correct 3 ms 552 KB Output is correct
6 Correct 3 ms 608 KB Output is correct
7 Correct 2 ms 608 KB Output is correct
8 Correct 2 ms 608 KB Output is correct
9 Correct 2 ms 608 KB Output is correct
10 Correct 3 ms 608 KB Output is correct
11 Correct 3 ms 608 KB Output is correct
12 Correct 2 ms 656 KB Output is correct
13 Correct 3 ms 656 KB Output is correct
14 Correct 3 ms 672 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 2 ms 484 KB Output is correct
3 Correct 3 ms 484 KB Output is correct
4 Correct 3 ms 484 KB Output is correct
5 Correct 3 ms 552 KB Output is correct
6 Correct 3 ms 608 KB Output is correct
7 Correct 2 ms 608 KB Output is correct
8 Correct 2 ms 608 KB Output is correct
9 Correct 2 ms 608 KB Output is correct
10 Correct 3 ms 608 KB Output is correct
11 Correct 3 ms 608 KB Output is correct
12 Correct 2 ms 656 KB Output is correct
13 Correct 3 ms 656 KB Output is correct
14 Correct 3 ms 672 KB Output is correct
15 Correct 3 ms 672 KB Output is correct
16 Correct 12 ms 1660 KB Output is correct
17 Correct 17 ms 1740 KB Output is correct
18 Correct 12 ms 1788 KB Output is correct
19 Correct 26 ms 1788 KB Output is correct
20 Correct 25 ms 1788 KB Output is correct
21 Correct 22 ms 1788 KB Output is correct
22 Correct 13 ms 1788 KB Output is correct
23 Correct 31 ms 1788 KB Output is correct
24 Correct 11 ms 1788 KB Output is correct
25 Correct 41 ms 1788 KB Output is correct
26 Correct 20 ms 1788 KB Output is correct
27 Correct 20 ms 1788 KB Output is correct
28 Correct 22 ms 1788 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 2 ms 484 KB Output is correct
3 Correct 3 ms 484 KB Output is correct
4 Correct 3 ms 484 KB Output is correct
5 Correct 3 ms 552 KB Output is correct
6 Correct 3 ms 608 KB Output is correct
7 Correct 2 ms 608 KB Output is correct
8 Correct 2 ms 608 KB Output is correct
9 Correct 2 ms 608 KB Output is correct
10 Correct 3 ms 608 KB Output is correct
11 Correct 3 ms 608 KB Output is correct
12 Correct 2 ms 656 KB Output is correct
13 Correct 3 ms 656 KB Output is correct
14 Correct 3 ms 672 KB Output is correct
15 Correct 3 ms 672 KB Output is correct
16 Correct 12 ms 1660 KB Output is correct
17 Correct 17 ms 1740 KB Output is correct
18 Correct 12 ms 1788 KB Output is correct
19 Correct 26 ms 1788 KB Output is correct
20 Correct 25 ms 1788 KB Output is correct
21 Correct 22 ms 1788 KB Output is correct
22 Correct 13 ms 1788 KB Output is correct
23 Correct 31 ms 1788 KB Output is correct
24 Correct 11 ms 1788 KB Output is correct
25 Correct 41 ms 1788 KB Output is correct
26 Correct 20 ms 1788 KB Output is correct
27 Correct 20 ms 1788 KB Output is correct
28 Correct 22 ms 1788 KB Output is correct
29 Correct 1937 ms 30408 KB Output is correct
30 Correct 2167 ms 30768 KB Output is correct
31 Correct 3073 ms 32024 KB Output is correct
32 Correct 1882 ms 55292 KB Output is correct
33 Correct 735 ms 71288 KB Output is correct
34 Correct 2487 ms 98512 KB Output is correct
35 Correct 2520 ms 137240 KB Output is correct
36 Correct 959 ms 168932 KB Output is correct
37 Correct 3623 ms 209992 KB Output is correct