#include<stdio.h>
#define N 2000
#define M 2000
int max(int i,int j){return i<j?j:i;}
int min(int i,int j){return i>j?j:i;}
int n, m, a[N][M], b[N][M], c[N][M], d[N][M], x, ii, jj;
int ok_(int a[][M], int ii, int jj)
{
static int down[M][N];
for(int i=0;i<m;++i)
{
down[i][0]=a[0][i];
for(int j=1;j<n;++j)
down[i][j]=min(down[i][j-1],a[j][i]);
}
int high = a[ii][jj];
static int sep[M];
int ptr=n-1;
for(int i=0;i<m;++i)
{
while(ptr>=0&&down[i][ptr]+x<high)--ptr;
sep[i]=ptr+1;
if(jj == i && sep[i] <= ii)
return 0;
}
int ioi_high=-1,ioi_low=1e9;
for(int i=0;i<m;++i)for(int j=sep[i];j<n;++j)
{
ioi_high=max(ioi_high,a[j][i]);
ioi_low=min(ioi_low,a[j][i]);
if(ioi_low+x<ioi_high)
return 0;
}
return 1;
}
int ok(int x0)
{
x = x0;
return ok_(a, ii, jj) || ok_(b, n-1-ii, jj) || ok_(c, ii, m-1-jj) || ok_(d, n-1-ii, m-1-jj);
}
int main()
{
scanf("%d%d",&n,&m);
for(int i=0;i<n;++i)for(int j=0;j<m;++j)
{
scanf("%d",a[i]+j), b[n-1-i][j]=a[i][j], c[i][m-1-j]=a[i][j], d[n-1-i][m-1-j]=a[i][j];
if(a[i][j]>a[ii][jj])ii=i,jj=j;
}
int lb=-1,ub=1e9;
while(ub-lb>1)
{
int mid=lb+(ub-lb)/2;
if(ok(mid))ub=mid;
else lb=mid;
}
printf("%d",ub);
}
Compilation message
joioi.c: In function 'main':
joioi.c:52:5: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
52 | scanf("%d%d",&n,&m);
| ^~~~~~~~~~~~~~~~~~~
joioi.c:55:9: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
55 | scanf("%d",a[i]+j), b[n-1-i][j]=a[i][j], c[i][m-1-j]=a[i][j], d[n-1-i][m-1-j]=a[i][j];
| ^~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
8536 KB |
Output is correct |
2 |
Correct |
2 ms |
8540 KB |
Output is correct |
3 |
Correct |
1 ms |
8540 KB |
Output is correct |
4 |
Correct |
1 ms |
8796 KB |
Output is correct |
5 |
Correct |
1 ms |
8540 KB |
Output is correct |
6 |
Correct |
1 ms |
8540 KB |
Output is correct |
7 |
Correct |
1 ms |
8540 KB |
Output is correct |
8 |
Correct |
1 ms |
8540 KB |
Output is correct |
9 |
Correct |
2 ms |
8536 KB |
Output is correct |
10 |
Correct |
2 ms |
8540 KB |
Output is correct |
11 |
Correct |
1 ms |
8540 KB |
Output is correct |
12 |
Correct |
1 ms |
8540 KB |
Output is correct |
13 |
Correct |
1 ms |
8540 KB |
Output is correct |
14 |
Correct |
2 ms |
8540 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
8536 KB |
Output is correct |
2 |
Correct |
2 ms |
8540 KB |
Output is correct |
3 |
Correct |
1 ms |
8540 KB |
Output is correct |
4 |
Correct |
1 ms |
8796 KB |
Output is correct |
5 |
Correct |
1 ms |
8540 KB |
Output is correct |
6 |
Correct |
1 ms |
8540 KB |
Output is correct |
7 |
Correct |
1 ms |
8540 KB |
Output is correct |
8 |
Correct |
1 ms |
8540 KB |
Output is correct |
9 |
Correct |
2 ms |
8536 KB |
Output is correct |
10 |
Correct |
2 ms |
8540 KB |
Output is correct |
11 |
Correct |
1 ms |
8540 KB |
Output is correct |
12 |
Correct |
1 ms |
8540 KB |
Output is correct |
13 |
Correct |
1 ms |
8540 KB |
Output is correct |
14 |
Correct |
2 ms |
8540 KB |
Output is correct |
15 |
Correct |
2 ms |
10588 KB |
Output is correct |
16 |
Correct |
6 ms |
17500 KB |
Output is correct |
17 |
Correct |
8 ms |
17756 KB |
Output is correct |
18 |
Correct |
9 ms |
17756 KB |
Output is correct |
19 |
Correct |
9 ms |
17756 KB |
Output is correct |
20 |
Correct |
8 ms |
17756 KB |
Output is correct |
21 |
Correct |
10 ms |
17820 KB |
Output is correct |
22 |
Correct |
10 ms |
17752 KB |
Output is correct |
23 |
Correct |
11 ms |
17944 KB |
Output is correct |
24 |
Correct |
10 ms |
17752 KB |
Output is correct |
25 |
Correct |
10 ms |
17756 KB |
Output is correct |
26 |
Correct |
10 ms |
17920 KB |
Output is correct |
27 |
Correct |
11 ms |
17756 KB |
Output is correct |
28 |
Correct |
12 ms |
17800 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
8536 KB |
Output is correct |
2 |
Correct |
2 ms |
8540 KB |
Output is correct |
3 |
Correct |
1 ms |
8540 KB |
Output is correct |
4 |
Correct |
1 ms |
8796 KB |
Output is correct |
5 |
Correct |
1 ms |
8540 KB |
Output is correct |
6 |
Correct |
1 ms |
8540 KB |
Output is correct |
7 |
Correct |
1 ms |
8540 KB |
Output is correct |
8 |
Correct |
1 ms |
8540 KB |
Output is correct |
9 |
Correct |
2 ms |
8536 KB |
Output is correct |
10 |
Correct |
2 ms |
8540 KB |
Output is correct |
11 |
Correct |
1 ms |
8540 KB |
Output is correct |
12 |
Correct |
1 ms |
8540 KB |
Output is correct |
13 |
Correct |
1 ms |
8540 KB |
Output is correct |
14 |
Correct |
2 ms |
8540 KB |
Output is correct |
15 |
Correct |
2 ms |
10588 KB |
Output is correct |
16 |
Correct |
6 ms |
17500 KB |
Output is correct |
17 |
Correct |
8 ms |
17756 KB |
Output is correct |
18 |
Correct |
9 ms |
17756 KB |
Output is correct |
19 |
Correct |
9 ms |
17756 KB |
Output is correct |
20 |
Correct |
8 ms |
17756 KB |
Output is correct |
21 |
Correct |
10 ms |
17820 KB |
Output is correct |
22 |
Correct |
10 ms |
17752 KB |
Output is correct |
23 |
Correct |
11 ms |
17944 KB |
Output is correct |
24 |
Correct |
10 ms |
17752 KB |
Output is correct |
25 |
Correct |
10 ms |
17756 KB |
Output is correct |
26 |
Correct |
10 ms |
17920 KB |
Output is correct |
27 |
Correct |
11 ms |
17756 KB |
Output is correct |
28 |
Correct |
12 ms |
17800 KB |
Output is correct |
29 |
Correct |
945 ms |
100944 KB |
Output is correct |
30 |
Correct |
831 ms |
99072 KB |
Output is correct |
31 |
Correct |
997 ms |
101968 KB |
Output is correct |
32 |
Correct |
816 ms |
101780 KB |
Output is correct |
33 |
Correct |
873 ms |
98636 KB |
Output is correct |
34 |
Correct |
816 ms |
101804 KB |
Output is correct |
35 |
Correct |
1377 ms |
117784 KB |
Output is correct |
36 |
Correct |
1114 ms |
111184 KB |
Output is correct |
37 |
Correct |
1226 ms |
117692 KB |
Output is correct |