/** made by amunduzbaev **/
#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define ub upper_bound
#define lb lower_bound
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(),x.rend()
#define NeedForSpeed ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define int long long
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
typedef vector<int> vii;
typedef vector<pll> vpll;
typedef vector<pii> vpii;
template<class T> bool umin(T& a, const T& b) {return a > b? a = b, true:false;}
template<class T> bool umax(T& a, const T& b) {return a < b? a = b, true:false;}
const int N = 2e3+5;
const int mod = 1e9+7;
const ll inf = 1e18;
const ld Pi = acos(-1);
#define MULTI 0
int n, m, k, ans, res, a[N][N];
int pp[N][N], ps[N][N], sp[N][N], ss[N][N];
void solve(int t_case){
cin>>n>>m;
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
cin>>a[i][j];
}
}
res = -2;
for(int i=0;i<N;i++){
for(int j=0;j<N;j++){
pp[i][j] = -inf;
ps[i][j] = -inf;
sp[i][j] = -inf;
ss[i][j] = -inf;
}
}
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
pp[i][j] = -a[i][j] + i + j;
if(i) umax(pp[i][j], pp[i-1][j]);
if(j) umax(pp[i][j], pp[i][j-1]);
}
}
for(int i=0;i<n;i++){
for(int j=m-1;j>=0;j--){
ps[i][j] = -a[i][j] + i - j;
if(i) umax(ps[i][j], ps[i-1][j]);
umax(ps[i][j], ps[i][j+1]);
}
}
for(int i=n-1;i>=0;i--){
for(int j=0;j<m;j++){
sp[i][j] = -a[i][j] - i + j;
umax(sp[i][j], sp[i+1][j]);
if(j) umax(sp[i][j], sp[i][j-1]);
}
}
for(int i=n-1;i>=0;i--){
for(int j=m-1;j>=0;j--){
ss[i][j] = -a[i][j] - i - j;
umax(ss[i][j], ss[i+1][j]);
umax(ss[i][j], ss[i][j+1]);
}
}
//for(int i=0;i<n;i++){
//for(int j=0;j<m;j++){
//cout<<pp[i][j]<<" ";
//}
//cout<<"\n";
//}
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
int tt = a[i][j] + i + j -1;
umax(res, tt + ss[i][j]);
tt = a[i][j] + i - j-1, umax(res, tt + sp[i][j]);
tt = a[i][j] - i + j-1, umax(res, tt + ps[i][j]);
tt = a[i][j] - i - j-1, umax(res, tt + pp[i][j]);
}
}
cout<<res<<"\n";
}
signed main(){
NeedForSpeed
if(!MULTI) {
solve(1);
} else {
int t; cin>>t;
for(int t_case = 1; t_case <= t; t_case++) solve(t_case);
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
70 ms |
126188 KB |
Output is correct |
2 |
Correct |
72 ms |
126188 KB |
Output is correct |
3 |
Correct |
71 ms |
126336 KB |
Output is correct |
4 |
Correct |
69 ms |
126188 KB |
Output is correct |
5 |
Correct |
70 ms |
126188 KB |
Output is correct |
6 |
Correct |
71 ms |
126188 KB |
Output is correct |
7 |
Correct |
81 ms |
126316 KB |
Output is correct |
8 |
Correct |
71 ms |
126268 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
67 ms |
126188 KB |
Output is correct |
2 |
Correct |
69 ms |
126188 KB |
Output is correct |
3 |
Correct |
70 ms |
126188 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
70 ms |
126188 KB |
Output is correct |
2 |
Correct |
72 ms |
126188 KB |
Output is correct |
3 |
Correct |
71 ms |
126336 KB |
Output is correct |
4 |
Correct |
69 ms |
126188 KB |
Output is correct |
5 |
Correct |
70 ms |
126188 KB |
Output is correct |
6 |
Correct |
71 ms |
126188 KB |
Output is correct |
7 |
Correct |
81 ms |
126316 KB |
Output is correct |
8 |
Correct |
71 ms |
126268 KB |
Output is correct |
9 |
Correct |
74 ms |
126364 KB |
Output is correct |
10 |
Correct |
69 ms |
126444 KB |
Output is correct |
11 |
Correct |
69 ms |
126444 KB |
Output is correct |
12 |
Correct |
77 ms |
126444 KB |
Output is correct |
13 |
Correct |
69 ms |
126444 KB |
Output is correct |
14 |
Correct |
70 ms |
126444 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
70 ms |
126188 KB |
Output is correct |
2 |
Correct |
72 ms |
126188 KB |
Output is correct |
3 |
Correct |
71 ms |
126336 KB |
Output is correct |
4 |
Correct |
69 ms |
126188 KB |
Output is correct |
5 |
Correct |
70 ms |
126188 KB |
Output is correct |
6 |
Correct |
71 ms |
126188 KB |
Output is correct |
7 |
Correct |
81 ms |
126316 KB |
Output is correct |
8 |
Correct |
71 ms |
126268 KB |
Output is correct |
9 |
Correct |
67 ms |
126188 KB |
Output is correct |
10 |
Correct |
69 ms |
126188 KB |
Output is correct |
11 |
Correct |
70 ms |
126188 KB |
Output is correct |
12 |
Correct |
74 ms |
126364 KB |
Output is correct |
13 |
Correct |
69 ms |
126444 KB |
Output is correct |
14 |
Correct |
69 ms |
126444 KB |
Output is correct |
15 |
Correct |
77 ms |
126444 KB |
Output is correct |
16 |
Correct |
69 ms |
126444 KB |
Output is correct |
17 |
Correct |
70 ms |
126444 KB |
Output is correct |
18 |
Correct |
191 ms |
138092 KB |
Output is correct |
19 |
Correct |
199 ms |
146668 KB |
Output is correct |
20 |
Correct |
190 ms |
145920 KB |
Output is correct |
21 |
Correct |
193 ms |
146540 KB |
Output is correct |
22 |
Correct |
192 ms |
146540 KB |
Output is correct |
23 |
Correct |
194 ms |
146540 KB |
Output is correct |
24 |
Correct |
195 ms |
146796 KB |
Output is correct |