This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define finish(x) return cout << x << endl, 0
#define ll long long
int n, m, grid[1001][1001], mn[1001][1001];
int solve(){
for(int i = 0 ; i <= n ; i++)
for(int j = 0 ; j <= m ; j++)
mn[i][j] = 1e9;
for(int i = 1 ; i <= n ; i++)
for(int j = 1 ; j <= m ; j++)
grid[i][j] -= i + j;
for(int i = 1 ; i <= n ; i++)
for(int j = 1 ; j <= m ; j++)
mn[i][j] = min(mn[i - 1][j], min(mn[i][j - 1], grid[i][j]));
int ret = 0;
for(int i = 1 ; i <= n ; i++)
for(int j = 1 ; j <= m ; j++)
ret = max(ret, grid[i][j] - mn[i][j]);
for(int i = 1 ; i <= n ; i++)
for(int j = 1 ; j <= m ; j++)
grid[i][j] += i + j;
return ret;
}
void flip1(){
for(int i = 1 ; i <= n ; i++){
int l = 1, r = m;
while(l <= r){
swap(grid[i][l], grid[i][r]);
l++; r--;
}
}
}
void flip2(){
for(int i = 1 ; i <= m ; i++){
int l = 1, r = n;
while(l <= r){
swap(grid[l][i], grid[r][i]);
l++; r--;
}
}
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n >> m;
for(int i = 1 ; i <= n ; i++)
for(int j = 1 ; j <= m ; j++)
cin >> grid[i][j];
int ans = solve();
flip1();
ans = max(ans, solve());
flip2();
ans = max(ans, solve());
flip1();
ans = max(ans, solve());
cout << ans - 1 << endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |