#include "bits/stdc++.h"
using namespace std;
#define int long long
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 |
2 ms |
364 KB |
Output is correct |
16 |
Correct |
14 ms |
1516 KB |
Output is correct |
17 |
Correct |
13 ms |
1772 KB |
Output is correct |
18 |
Correct |
11 ms |
1772 KB |
Output is correct |
19 |
Correct |
11 ms |
1900 KB |
Output is correct |
20 |
Correct |
9 ms |
1644 KB |
Output is correct |
21 |
Correct |
12 ms |
2028 KB |
Output is correct |
22 |
Correct |
10 ms |
1900 KB |
Output is correct |
23 |
Correct |
10 ms |
1900 KB |
Output is correct |
24 |
Correct |
9 ms |
1644 KB |
Output is correct |
25 |
Correct |
10 ms |
1900 KB |
Output is correct |
26 |
Correct |
10 ms |
1900 KB |
Output is correct |
27 |
Correct |
12 ms |
1900 KB |
Output is correct |
28 |
Correct |
12 ms |
1900 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 |
2 ms |
364 KB |
Output is correct |
16 |
Correct |
14 ms |
1516 KB |
Output is correct |
17 |
Correct |
13 ms |
1772 KB |
Output is correct |
18 |
Correct |
11 ms |
1772 KB |
Output is correct |
19 |
Correct |
11 ms |
1900 KB |
Output is correct |
20 |
Correct |
9 ms |
1644 KB |
Output is correct |
21 |
Correct |
12 ms |
2028 KB |
Output is correct |
22 |
Correct |
10 ms |
1900 KB |
Output is correct |
23 |
Correct |
10 ms |
1900 KB |
Output is correct |
24 |
Correct |
9 ms |
1644 KB |
Output is correct |
25 |
Correct |
10 ms |
1900 KB |
Output is correct |
26 |
Correct |
10 ms |
1900 KB |
Output is correct |
27 |
Correct |
12 ms |
1900 KB |
Output is correct |
28 |
Correct |
12 ms |
1900 KB |
Output is correct |
29 |
Correct |
3470 ms |
52356 KB |
Output is correct |
30 |
Correct |
3349 ms |
53436 KB |
Output is correct |
31 |
Correct |
3637 ms |
55020 KB |
Output is correct |
32 |
Correct |
3669 ms |
55020 KB |
Output is correct |
33 |
Correct |
3034 ms |
47980 KB |
Output is correct |
34 |
Correct |
3692 ms |
55044 KB |
Output is correct |
35 |
Correct |
3625 ms |
70624 KB |
Output is correct |
36 |
Correct |
3113 ms |
65364 KB |
Output is correct |
37 |
Correct |
3550 ms |
70636 KB |
Output is correct |