#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ld long double
#define show(x,y) cout << y << " " << #x << endl;
#define show2(x,y,i,j) cout << y << " " << #x << " " << j << " " << #i << endl;
#define show3(x,y,i,j,p,q) cout << y << " " << #x << " " << j << " " << #i << " " << q << " " << #p << endl;
#define show4(x,y) for(auto it:x) cout << it << " "; cout << #y << endl;
typedef pair<long long,long long>pii;
int n,m;
int arr[2005][2005];
int arr2[2005][2005];
int arr3[2005][2005];
int arr4[2005][2005];
int mini=INT_MAX;
int maxi=0;
bool check(int range){
int l=mini+range;
int r=maxi-range;
int ptr=-1;
int ptr2=-1;
int ptr3=-1;
int ptr4=-1;
bool amos=true;
bool amos2=true;
bool amos3=true;
bool amos4=true;
for(int x=0;x<n;x++){
for(int y=0;y<m;y++){
if(arr[x][y]>l) ptr=max(ptr,y);
if(arr2[x][y]>l) ptr2=max(ptr2,y);
if(arr3[x][y]>l) ptr3=max(ptr3,y);
if(arr4[x][y]>l) ptr4=max(ptr4,y);
}
for(int y=0;y<=ptr;y++){
if(arr[x][y]<r) amos=false;
}
for(int y=0;y<=ptr2;y++){
if(arr2[x][y]<r) amos2=false;
}
for(int y=0;y<=ptr3;y++){
if(arr3[x][y]<r) amos3=false;
}
for(int y=0;y<=ptr4;y++){
if(arr4[x][y]<r) amos4=false;
}
}
return amos|amos2|amos3|amos4;
}
void solve(){
cin >> n >> m;
for(int x=0;x<n;x++){
for(int y=0;y<m;y++){
cin >> arr[x][y];
mini=min(mini,arr[x][y]);
maxi=max(maxi,arr[x][y]);
}
}
for(int x=0;x<n;x++){
for(int y=0;y<m;y++){
arr2[x][y]=arr[n-x-1][m-y-1];
arr3[x][y]=arr[n-x-1][y];
arr4[x][y]=arr[x][m-y-1];
}
}
int l=0;
int r=1e9;
int best=r;
int mid;
while(l<=r){
mid=(l+r)/2;
if(check(mid)){
best=mid;
r=mid-1;
}
else l=mid+1;
}
cout << best;
}
int32_t main(){
ios::sync_with_stdio(0);
cin.tie(0);
int t=1;
//cin >> t;
while(t--){
solve();
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
6608 KB |
Output is correct |
2 |
Correct |
1 ms |
6488 KB |
Output is correct |
3 |
Correct |
2 ms |
6492 KB |
Output is correct |
4 |
Correct |
1 ms |
6488 KB |
Output is correct |
5 |
Correct |
1 ms |
6492 KB |
Output is correct |
6 |
Correct |
1 ms |
6488 KB |
Output is correct |
7 |
Correct |
2 ms |
6492 KB |
Output is correct |
8 |
Correct |
1 ms |
6492 KB |
Output is correct |
9 |
Correct |
1 ms |
6492 KB |
Output is correct |
10 |
Correct |
1 ms |
6612 KB |
Output is correct |
11 |
Correct |
1 ms |
6488 KB |
Output is correct |
12 |
Correct |
1 ms |
6488 KB |
Output is correct |
13 |
Correct |
1 ms |
6488 KB |
Output is correct |
14 |
Correct |
1 ms |
6492 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
6608 KB |
Output is correct |
2 |
Correct |
1 ms |
6488 KB |
Output is correct |
3 |
Correct |
2 ms |
6492 KB |
Output is correct |
4 |
Correct |
1 ms |
6488 KB |
Output is correct |
5 |
Correct |
1 ms |
6492 KB |
Output is correct |
6 |
Correct |
1 ms |
6488 KB |
Output is correct |
7 |
Correct |
2 ms |
6492 KB |
Output is correct |
8 |
Correct |
1 ms |
6492 KB |
Output is correct |
9 |
Correct |
1 ms |
6492 KB |
Output is correct |
10 |
Correct |
1 ms |
6612 KB |
Output is correct |
11 |
Correct |
1 ms |
6488 KB |
Output is correct |
12 |
Correct |
1 ms |
6488 KB |
Output is correct |
13 |
Correct |
1 ms |
6488 KB |
Output is correct |
14 |
Correct |
1 ms |
6492 KB |
Output is correct |
15 |
Correct |
2 ms |
8540 KB |
Output is correct |
16 |
Correct |
10 ms |
21112 KB |
Output is correct |
17 |
Correct |
13 ms |
21084 KB |
Output is correct |
18 |
Correct |
10 ms |
21084 KB |
Output is correct |
19 |
Correct |
13 ms |
21080 KB |
Output is correct |
20 |
Correct |
12 ms |
19036 KB |
Output is correct |
21 |
Correct |
14 ms |
21212 KB |
Output is correct |
22 |
Correct |
11 ms |
21340 KB |
Output is correct |
23 |
Correct |
16 ms |
21340 KB |
Output is correct |
24 |
Correct |
11 ms |
19292 KB |
Output is correct |
25 |
Correct |
21 ms |
21340 KB |
Output is correct |
26 |
Correct |
12 ms |
21336 KB |
Output is correct |
27 |
Correct |
11 ms |
21340 KB |
Output is correct |
28 |
Correct |
17 ms |
21336 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
6608 KB |
Output is correct |
2 |
Correct |
1 ms |
6488 KB |
Output is correct |
3 |
Correct |
2 ms |
6492 KB |
Output is correct |
4 |
Correct |
1 ms |
6488 KB |
Output is correct |
5 |
Correct |
1 ms |
6492 KB |
Output is correct |
6 |
Correct |
1 ms |
6488 KB |
Output is correct |
7 |
Correct |
2 ms |
6492 KB |
Output is correct |
8 |
Correct |
1 ms |
6492 KB |
Output is correct |
9 |
Correct |
1 ms |
6492 KB |
Output is correct |
10 |
Correct |
1 ms |
6612 KB |
Output is correct |
11 |
Correct |
1 ms |
6488 KB |
Output is correct |
12 |
Correct |
1 ms |
6488 KB |
Output is correct |
13 |
Correct |
1 ms |
6488 KB |
Output is correct |
14 |
Correct |
1 ms |
6492 KB |
Output is correct |
15 |
Correct |
2 ms |
8540 KB |
Output is correct |
16 |
Correct |
10 ms |
21112 KB |
Output is correct |
17 |
Correct |
13 ms |
21084 KB |
Output is correct |
18 |
Correct |
10 ms |
21084 KB |
Output is correct |
19 |
Correct |
13 ms |
21080 KB |
Output is correct |
20 |
Correct |
12 ms |
19036 KB |
Output is correct |
21 |
Correct |
14 ms |
21212 KB |
Output is correct |
22 |
Correct |
11 ms |
21340 KB |
Output is correct |
23 |
Correct |
16 ms |
21340 KB |
Output is correct |
24 |
Correct |
11 ms |
19292 KB |
Output is correct |
25 |
Correct |
21 ms |
21340 KB |
Output is correct |
26 |
Correct |
12 ms |
21336 KB |
Output is correct |
27 |
Correct |
11 ms |
21340 KB |
Output is correct |
28 |
Correct |
17 ms |
21336 KB |
Output is correct |
29 |
Correct |
836 ms |
147892 KB |
Output is correct |
30 |
Correct |
924 ms |
147648 KB |
Output is correct |
31 |
Correct |
1146 ms |
149356 KB |
Output is correct |
32 |
Correct |
801 ms |
149340 KB |
Output is correct |
33 |
Correct |
580 ms |
139628 KB |
Output is correct |
34 |
Correct |
963 ms |
149620 KB |
Output is correct |
35 |
Correct |
972 ms |
165004 KB |
Output is correct |
36 |
Correct |
838 ms |
159688 KB |
Output is correct |
37 |
Correct |
1432 ms |
165112 KB |
Output is correct |