Submission #750389

# Submission time Handle Problem Language Result Execution time Memory
750389 2023-05-29T13:01:13 Z pcc The Kingdom of JOIOI (JOI17_joioi) C++14
100 / 100
1060 ms 51920 KB
#include <bits/stdc++.h>
using namespace std;

const int mxn = 2022;
int arr[mxn][mxn],lim[mxn];
int n,m;
int small = 1e9+10;

bool calc(int d){
	for(lim[1] = 1;lim[1]<=m&&arr[1][lim[1]]<=small+d;lim[1]++);
	for(int i = 2;i<=n;i++){
		for(lim[i] = 1;lim[i]<lim[i-1]&&arr[i][lim[i]]<=small+d;lim[i]++);
	}
	int big = 0,small = 1e9+10;
	for(int i = 1;i<=n;i++){
		for(int j = m;j>=lim[i];j--)big = max(big,arr[i][j]),small = min(small,arr[i][j]);
	}
	return big-small<=d;
}

bool f(int d){
	bool flag = false;
	flag = calc(d);
	for(int i = 1;i<=n;i++)reverse(arr[i]+1,arr[i]+1+m);
	flag = flag||calc(d);
	reverse(arr+1,arr+n+1);
	flag = flag||calc(d);
	for(int i = 1;i<=n;i++)reverse(arr[i]+1,arr[i]+1+m);
	flag = flag||calc(d);
	return flag;
}

int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>n>>m;
	int big = 0;
	for(int i = 1;i<=n;i++)
		for(int j = 1;j<=m;j++)cin>>arr[i][j],big = max(big,arr[i][j]),small = min(small,arr[i][j]);
	int l = 0,r = big;
	while(l != r){
		int mid = (l+r)>>1;
		if(f(mid))r = mid;
		else l = mid+1;
	}
	cout<<l;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 324 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 328 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 324 KB Output is correct
14 Correct 1 ms 328 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 324 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 328 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 324 KB Output is correct
14 Correct 1 ms 328 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 4 ms 1880 KB Output is correct
17 Correct 11 ms 2132 KB Output is correct
18 Correct 11 ms 2128 KB Output is correct
19 Correct 10 ms 2132 KB Output is correct
20 Correct 10 ms 1972 KB Output is correct
21 Correct 22 ms 2260 KB Output is correct
22 Correct 15 ms 2260 KB Output is correct
23 Correct 15 ms 2244 KB Output is correct
24 Correct 13 ms 2004 KB Output is correct
25 Correct 14 ms 2300 KB Output is correct
26 Correct 15 ms 2304 KB Output is correct
27 Correct 15 ms 2304 KB Output is correct
28 Correct 16 ms 2252 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 324 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 328 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 324 KB Output is correct
14 Correct 1 ms 328 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 4 ms 1880 KB Output is correct
17 Correct 11 ms 2132 KB Output is correct
18 Correct 11 ms 2128 KB Output is correct
19 Correct 10 ms 2132 KB Output is correct
20 Correct 10 ms 1972 KB Output is correct
21 Correct 22 ms 2260 KB Output is correct
22 Correct 15 ms 2260 KB Output is correct
23 Correct 15 ms 2244 KB Output is correct
24 Correct 13 ms 2004 KB Output is correct
25 Correct 14 ms 2300 KB Output is correct
26 Correct 15 ms 2304 KB Output is correct
27 Correct 15 ms 2304 KB Output is correct
28 Correct 16 ms 2252 KB Output is correct
29 Correct 631 ms 37308 KB Output is correct
30 Correct 642 ms 37668 KB Output is correct
31 Correct 645 ms 39244 KB Output is correct
32 Correct 716 ms 39188 KB Output is correct
33 Correct 612 ms 34308 KB Output is correct
34 Correct 652 ms 39244 KB Output is correct
35 Correct 1060 ms 51920 KB Output is correct
36 Correct 967 ms 49728 KB Output is correct
37 Correct 1020 ms 50504 KB Output is correct