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>
#include<fstream>
#pragma GCC optimize("Ofast,O3,unroll-loops")
#pragma GCC target("avx2")
using namespace std;
//ifstream fin("FEEDING.INP");
//ofstream fout("FEEDING.OUT");
#define sz(a) (int)a.size()
#define ll long long
#define pb push_back
#define forr(i, a, b) for(int i = a; i < b; i++)
#define dorr(i, a, b) for(int i = a; i >= b; i--)
#define ld long double
#define vt vector
#include<fstream>
#define fi first
#define se second
#define pll pair<ll, ll>
#define pii pair<int, int>
const ll mxn = 2e5 + 5, base = 972663749;
const ll mod = 911382323, mxv = 1e9 + 1, inf = 2e9;
int n, m;
int col[1005];
int a[1005][1005];
signed main()
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n >> m;
for(int i = 1; i <= n; i++){
for(int j = 1; j <= m; j++){
cin >> a[i][j];
}
}
for(int i = 1; i <= m; i++)col[i] = -inf;
int ans = 0;
for(int i = 1; i <= n; i++){
int mxval = -inf;
for(int j = 1; j <= m; j++){
col[j] = max(col[j], -a[i][j] + i + j);
mxval = max(mxval, col[j]);
ans = max(ans, a[i][j] - i - j + mxval);
}
}
for(int i = 1; i <= m; i++)col[i] = -inf;
for(int i = 1; i <= n; i++){
int mxval = -inf;
for(int j = m; j >= 1; j--){
col[j] = max(col[j], -a[i][j] + i - j);
mxval = max(mxval, col[j]);
ans = max(ans, a[i][j] - i + j + mxval);
}
}
for(int i = 1; i <= m; i++)col[i] = -inf;
for(int i = n; i >= 1; i--){
int mxval = -inf;
for(int j = m; j >= 1; j--){
col[j] = max(col[j], -a[i][j] - i - j);
mxval = max(mxval, col[j]);
ans = max(ans, a[i][j] + i + j + mxval);
}
}
for(int i = 1; i <= m; i++)col[i] = -inf;
for(int i = n; i >= 1; i--){
int mxval = -inf;
for(int j = 1; j <= m; j++){
col[j] = max(col[j], -a[i][j] - i + j);
mxval = max(mxval, col[j]);
ans = max(ans, a[i][j] + i - j + mxval);
}
}
cout << ans - 1;
return(0);
}
# | 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... |