Submission #365481

# Submission time Handle Problem Language Result Execution time Memory
365481 2021-02-11T17:40:46 Z inluminas The Kingdom of JOIOI (JOI17_joioi) C++14
100 / 100
775 ms 19948 KB
#include"bits/stdc++.h"
using namespace std;

#define ll long long
#define endl "\n"
#define fastio ios_base::sync_with_stdio(false)

const int lmt=2e3+3;
int a[lmt][lmt],h,w,mx,mn=INT_MAX;



bool ok(int dif){
	int last=w;
	for(int i=1;i<=h;i++){
		for(int j=1;j<=last;j++){
			if(abs(mx-a[i][j])>dif){
				last=j-1;
				break;
			}
		}
		for(int j=last+1;j<=w;j++){
			if(abs(mn-a[i][j])>dif){
				return false;
			}
		}
	}
	return true;
}

int bs(){
	int lo=0,hi=mx-mn;
	while(hi-lo>1){
		int mid=(lo+hi)/2;
		if(ok(mid)){
			hi=mid;
		}else{
			lo=mid;
		}
	}
	if(ok(lo)) return lo;
	else return hi;
}

int main(){
	fastio;

	cin>>h>>w;
	for(int i=1;i<=h;i++){
		for(int j=1;j<=w;j++){
			cin>>a[i][j];
			mn=min(mn,a[i][j]),mx=max(mx,a[i][j]);
		}
	}
	int ans=bs();
	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(ans,bs());
	for(int i=1;i<=h/2;i++){
		for(int j=1;j<=w;j++){
			swap(a[i][j],a[h-i+1][j]);
		}
	}
	ans=min(ans,bs());
	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(ans,bs());
	cout<<ans<<endl;
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 492 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 492 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 492 KB Output is correct
16 Correct 4 ms 1388 KB Output is correct
17 Correct 6 ms 1516 KB Output is correct
18 Correct 6 ms 1516 KB Output is correct
19 Correct 8 ms 1516 KB Output is correct
20 Correct 6 ms 1388 KB Output is correct
21 Correct 11 ms 1644 KB Output is correct
22 Correct 9 ms 1644 KB Output is correct
23 Correct 8 ms 1644 KB Output is correct
24 Correct 8 ms 1516 KB Output is correct
25 Correct 9 ms 1644 KB Output is correct
26 Correct 9 ms 1644 KB Output is correct
27 Correct 8 ms 1644 KB Output is correct
28 Correct 8 ms 1644 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 492 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 492 KB Output is correct
16 Correct 4 ms 1388 KB Output is correct
17 Correct 6 ms 1516 KB Output is correct
18 Correct 6 ms 1516 KB Output is correct
19 Correct 8 ms 1516 KB Output is correct
20 Correct 6 ms 1388 KB Output is correct
21 Correct 11 ms 1644 KB Output is correct
22 Correct 9 ms 1644 KB Output is correct
23 Correct 8 ms 1644 KB Output is correct
24 Correct 8 ms 1516 KB Output is correct
25 Correct 9 ms 1644 KB Output is correct
26 Correct 9 ms 1644 KB Output is correct
27 Correct 8 ms 1644 KB Output is correct
28 Correct 8 ms 1644 KB Output is correct
29 Correct 396 ms 17280 KB Output is correct
30 Correct 404 ms 18156 KB Output is correct
31 Correct 429 ms 18196 KB Output is correct
32 Correct 420 ms 18112 KB Output is correct
33 Correct 367 ms 16108 KB Output is correct
34 Correct 438 ms 18028 KB Output is correct
35 Correct 704 ms 19820 KB Output is correct
36 Correct 622 ms 18668 KB Output is correct
37 Correct 775 ms 19948 KB Output is correct