/*
Let the good times roll
*/
#include <iostream>
#include <cstdio>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <cstring>
#include <cfloat>
#include <cmath>
#include <cassert>
#include <locale>
#include <string>
#include <bitset>
#include <functional>
#include <climits>
#include <iomanip>
using namespace std;
#define read(x) freopen(x,"r",stdin)
#define write(x) freopen(x,"w",stdout)
#define cl(a,b) memset(a,b,sizeof(a))
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define ll long long
#define ld long double
#define vec vector
#define vi vec<int>
#define heap priority_queue
#define res reserve
#define pb push_back
#define f(x,y,z) for(int x=(y); x<(z); x++)
#define fd(x,y,z) for(int x=(y); x>=(z); x--)
#define fit(x,y) for(auto x: y)
#define srt(x) sort(all(x))
#define rsrt(x) sort(rall(x))
#define make_unique(x) sort(all((x))); (x).resize(unique(all((x))) - (x).begin())
#define pii pair<int,ll>
#define ppi pair<pii,int>
#define pip pair<int,pii>
#define mp make_pair
#define f1 first
#define s2 second
#define cdbg(x) cerr<<#x<<" = "<<x<<",\t";
#define cdbl cerr<<"\n----------\n";
#define pow2(x) ((x)*(x))
#define edist(x1, y1, x2, y2) (sqrt((pow2(x1-x2)+pow2(y1-y2))))
#define mdist(x1, y1, x2, y2) (abs((x1)-(x2))+abs((y1)-(y2)))
#define y1 FullSensei
#define mid ((ss+se)>>1)
#define left (si<<1)
#define right ((si<<1)+1)
#define pi 3.141592653589793
#define popcount __builtin_popcount
#define spc ' '
#define endl '\n'
bool checkbit(int x,int y){return (x&(1<<y));}
int setbit(int x,int y){return (x^(1<<y));}
const int dirs[4][2]={{1,0},{0,1},{-1,0},{0,-1}};
const int mod=1e9+7;
const int p1=805306457;
const int p2=1610612741;
const int INF=1e9;
const int N=1e3+7;
int a[N][N], b[N][N],
xu[N][N], xl[N][N], nd[N][N], nr[N][N];
int n, m;
void pre(){
f(i,1,n+1) f(j,1,m+1) xu[i][j]=xl[i][j]=nd[i][j]=nr[i][j]=-INF;
f(i,2,n+1) f(j,1,m+1) xu[i][j]=max(xu[i-1][j]-1, a[i-1][j]-1);
f(i,1,n+1) f(j,2,m+1) xl[i][j]=max(xl[i][j-1]-1, a[i][j-1]-1);
fd(i,n-1,1) f(j,1,m+1) nd[i][j]=max(nd[i+1][j]-1, -a[i+1][j]-1);
f(i,1,n+1) fd(j,m-1,1) nr[i][j]=max(nr[i][j+1]-1, -a[i][j+1]-1);
}
void dondur(){
f(i,1,n+1){
f(j,1,m+1){
b[j][n-i+1]=a[i][j];
}
}
swap(n,m);
f(i,1,n+1) f(j,1,m+1) a[i][j]=b[i][j];
}
int main(){
//read("in.in");
cin>>n>>m;
f(i,1,n+1){
f(j,1,m+1){
cin>>a[i][j];
}
}
int ans=-1;
{
if(n==1){
if(m==1){
cout<<-1<<endl;
return 0;
}
f(j,1,m){
int t=max(a[1][j], a[1][j+1])-min(a[1][j],a[1][j+1])-2;
ans=max(ans,t);
}
cout<<ans<<endl;
return 0;
}
else if(m==1){
f(i,1,n){
int t=max(a[i][1], a[i+1][1])-min(a[i][1],a[i+1][1])-2;
ans=max(ans,t);
}
cout<<ans<<endl;
return 0;
}
f(i,1,n){
f(j,1,m){
int t=max(a[i][j], a[i][j+1])-min(a[i][j],a[i][j+1])-2;
t=max(a[i][j], a[i+1][j])-min(a[i][j],a[i+1][j])-2;
ans=max(ans,t);
}
}
}
for(int k=0; k<4; k++){
pre();
f(i,2,n){
f(j,2,m){
int w=-1;
w=max(w, xu[i][j] + nd[i][j] - 1);
w=max(w, xu[i][j] + nr[i][j] - 1);
w=max(w, xl[i][j] + nd[i][j] - 1);
w=max(w, xl[i][j] + nr[i][j] - 1);
ans=max(ans, w);
}
}
if(k+1<4){
dondur();
}
}
cout<<ans<<endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
632 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
632 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
632 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
632 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |