Submission #375591

# Submission time Handle Problem Language Result Execution time Memory
375591 2021-03-09T14:54:29 Z astoria The Kingdom of JOIOI (JOI17_joioi) C++14
100 / 100
3400 ms 16236 KB
#include "bits/stdc++.h"
using namespace std;

const int H=2005,W=2005;
int h,w,lo,hi;
int g[H][W];

bool check(int x){
	int losen=w+1;
	for(int i=1; i<=h; i++){
		int lopo=0;
		for(int j=1; j<=w; j++){
			if(lo+x < g[i][j]) break;
			lopo++;
		}
		losen=min(losen,lopo);
		int hipo=w+1;
		for(int j=w; j>=1; j--){
			if(hi-x > g[i][j]) break;
			hipo--;
		}
		if(losen + 1 < hipo) return 0;
	}
	return 1;
}

void flip_row(){
	for(int i=1; i<=h; i++){
		for(int j=1; j<=w/2; j++){
			swap(g[i][j],g[i][w-j+1]);
		}
	}
}

void flip_col(){
	for(int j=1; j<=w; j++){
		for(int i=1; i<=h/2; i++){
			swap(g[i][j],g[h-i+1][j]);
		}
	}
}

bool f(int x){
	bool an=0;
	if(check(x)) an=1;
	flip_row();
	if(check(x)) an=1;
	flip_col();
	if(check(x)) an=1;
	flip_row();
	if(check(x)) an=1;
	flip_col();
	return an;
}

int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	cin>>h>>w;
	lo=1e9+500; hi=-1e6;
	for(int j=0; j<=w+1; j++) g[0][j]=0;
	for(int i=1; i<=h; i++){
		g[i][0]=0;
		for(int j=1; j<=w; j++){
			cin>>g[i][j];
			lo=min(lo,g[i][j]);
			hi=max(hi,g[i][j]);
		}
		g[i][w+1]=0;
	}
	for(int j=0; j<=w+1; j++) g[h+1][j]=0;
	
	int l=0, r=1e9+100;
	while(l<r){
		int m=l+((r-l)/2);
		if(f(m)) r=m;
		else l=m+1;
	}
	cout<<l;
	
	//checkc(5);
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 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 364 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 364 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 364 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 364 KB Output is correct
16 Correct 12 ms 1260 KB Output is correct
17 Correct 13 ms 1260 KB Output is correct
18 Correct 10 ms 1260 KB Output is correct
19 Correct 12 ms 1260 KB Output is correct
20 Correct 9 ms 1132 KB Output is correct
21 Correct 11 ms 1260 KB Output is correct
22 Correct 9 ms 1260 KB Output is correct
23 Correct 9 ms 1260 KB Output is correct
24 Correct 8 ms 1132 KB Output is correct
25 Correct 9 ms 1260 KB Output is correct
26 Correct 10 ms 1260 KB Output is correct
27 Correct 12 ms 1260 KB Output is correct
28 Correct 14 ms 1260 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 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 364 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 364 KB Output is correct
16 Correct 12 ms 1260 KB Output is correct
17 Correct 13 ms 1260 KB Output is correct
18 Correct 10 ms 1260 KB Output is correct
19 Correct 12 ms 1260 KB Output is correct
20 Correct 9 ms 1132 KB Output is correct
21 Correct 11 ms 1260 KB Output is correct
22 Correct 9 ms 1260 KB Output is correct
23 Correct 9 ms 1260 KB Output is correct
24 Correct 8 ms 1132 KB Output is correct
25 Correct 9 ms 1260 KB Output is correct
26 Correct 10 ms 1260 KB Output is correct
27 Correct 12 ms 1260 KB Output is correct
28 Correct 14 ms 1260 KB Output is correct
29 Correct 3097 ms 15340 KB Output is correct
30 Correct 3105 ms 16108 KB Output is correct
31 Correct 3357 ms 16144 KB Output is correct
32 Correct 3361 ms 16108 KB Output is correct
33 Correct 2809 ms 14316 KB Output is correct
34 Correct 3359 ms 16236 KB Output is correct
35 Correct 3400 ms 16108 KB Output is correct
36 Correct 2953 ms 16012 KB Output is correct
37 Correct 3260 ms 16108 KB Output is correct