#include <bits/stdc++.h>
#define DIM 2010
#define DIMBUFF 30000000
#define INF 2000000000
using namespace std;
int a[DIM][DIM],b[DIM][DIM],viz[DIM][DIM];
struct idk{
int val,l,c;
} v[DIM*DIM];
pair<int,int> c[DIM*DIM];
int di[] = {-1,1,0,0};
int dj[] = {0,0,-1,1};
int n,m,i,j,sol,mini,maxi,k,pos;
char buff[DIMBUFF];
int verif (int val){
int last = 0;
for (i=1;i<=n;i++){
for (j=1;j<=m;j++){
if (a[i][j] < maxi - val)
last = max(last,j);
}
for (j=1;j<=m;j++)
if (a[i][j] > mini + val && j <= last)
return 0;
}
return 1;
}
void solve (){
int st = 0, dr = maxi - mini, val = INF;
while (st <= dr){
int mid = (st+dr)>>1;
if (verif (mid)){
val = mid;
dr = mid-1;
} else st = mid+1;
}
sol = min (sol,val);
}
inline int cmp (idk a, idk b){
return a.val < b.val;
}
void roteste_linii(){
for (i=1;i<=n/2;i++)
for (j=1;j<=m;j++)
swap (a[i][j],a[n-i+1][j]);
}
void roteste_coloane(){
for (i=1;i<=n;i++)
for (j=1;j<=m/2;j++)
swap (a[i][j],a[i][m-j+1]);
}
int get_nr(){
while (!(buff[pos] >= '0' && buff[pos] <= '9'))
++pos;
int nr = 0;
while (buff[pos] >= '0' && buff[pos] <= '9'){
nr = nr*10 + buff[pos] - '0';
++pos;
}
return nr;
}
int main (){
//ifstream cin ("date.in");
//ofstream cout ("date.out");
cin>>n>>m;
mini = INF;
for (i=1;i<=n;++i)
for (j=1;j<=m;++j){
cin>>a[i][j];
mini = min (mini,a[i][j]);
maxi = max (maxi,a[i][j]);
// v[++k] = {a[i][j],i,j};
}
//sort (v+1,v+k+1,cmp);
sol = INF;
solve();
roteste_linii();
solve();
roteste_coloane();
solve();
roteste_linii();
solve();
cout<<sol;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Correct |
5 ms |
384 KB |
Output is correct |
13 |
Correct |
5 ms |
384 KB |
Output is correct |
14 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Correct |
5 ms |
384 KB |
Output is correct |
13 |
Correct |
5 ms |
384 KB |
Output is correct |
14 |
Correct |
5 ms |
384 KB |
Output is correct |
15 |
Correct |
5 ms |
384 KB |
Output is correct |
16 |
Correct |
13 ms |
1280 KB |
Output is correct |
17 |
Correct |
28 ms |
1444 KB |
Output is correct |
18 |
Correct |
25 ms |
1216 KB |
Output is correct |
19 |
Correct |
29 ms |
1272 KB |
Output is correct |
20 |
Correct |
24 ms |
1152 KB |
Output is correct |
21 |
Correct |
33 ms |
1280 KB |
Output is correct |
22 |
Correct |
36 ms |
1272 KB |
Output is correct |
23 |
Correct |
36 ms |
1280 KB |
Output is correct |
24 |
Correct |
31 ms |
1144 KB |
Output is correct |
25 |
Correct |
39 ms |
1272 KB |
Output is correct |
26 |
Correct |
35 ms |
1272 KB |
Output is correct |
27 |
Correct |
33 ms |
1272 KB |
Output is correct |
28 |
Correct |
33 ms |
1272 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Correct |
5 ms |
384 KB |
Output is correct |
13 |
Correct |
5 ms |
384 KB |
Output is correct |
14 |
Correct |
5 ms |
384 KB |
Output is correct |
15 |
Correct |
5 ms |
384 KB |
Output is correct |
16 |
Correct |
13 ms |
1280 KB |
Output is correct |
17 |
Correct |
28 ms |
1444 KB |
Output is correct |
18 |
Correct |
25 ms |
1216 KB |
Output is correct |
19 |
Correct |
29 ms |
1272 KB |
Output is correct |
20 |
Correct |
24 ms |
1152 KB |
Output is correct |
21 |
Correct |
33 ms |
1280 KB |
Output is correct |
22 |
Correct |
36 ms |
1272 KB |
Output is correct |
23 |
Correct |
36 ms |
1280 KB |
Output is correct |
24 |
Correct |
31 ms |
1144 KB |
Output is correct |
25 |
Correct |
39 ms |
1272 KB |
Output is correct |
26 |
Correct |
35 ms |
1272 KB |
Output is correct |
27 |
Correct |
33 ms |
1272 KB |
Output is correct |
28 |
Correct |
33 ms |
1272 KB |
Output is correct |
29 |
Correct |
1665 ms |
15444 KB |
Output is correct |
30 |
Correct |
1706 ms |
16220 KB |
Output is correct |
31 |
Correct |
1888 ms |
16084 KB |
Output is correct |
32 |
Correct |
1703 ms |
16132 KB |
Output is correct |
33 |
Correct |
1494 ms |
14088 KB |
Output is correct |
34 |
Correct |
1823 ms |
16236 KB |
Output is correct |
35 |
Correct |
2823 ms |
18680 KB |
Output is correct |
36 |
Correct |
2454 ms |
19136 KB |
Output is correct |
37 |
Correct |
3022 ms |
35832 KB |
Output is correct |