#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
// #pragma GCC optimize("Ofast,unroll-loops,fast-math")
// #pragma GCC target("popcnt")
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll,ll> pll;
#define sz size()
#define ff first
#define ss second
#define all(a) a.begin(),a.end()
#define pb push_back
const int mod = ll(1e9)+7; //(b + (a%b)) % b (to mod -1%(10^9+7) correctly in c++ its -1 but its suppose to be 10^9+6
const ll MOD = 998244353; // (a%mod)*(binpow(b,mod-2,mod) = (a/b)%mod
const int N = ll(4e5)+100;
const long long inf = 1e17;
const long double eps = 1e-15L;
ll lcm(ll a, ll b) { return (a / __gcd(a,b))*b; }
ll binpow(ll a, ll b, ll m) { ll res=1; a %= m; while(b>0){ if(b&1)res=(res * a) % m; a=(a * a) % m; b/=2; } return res%m;}
void Freopen(string Key){ freopen((Key+".in").c_str(), "r", stdin); freopen((Key+".out").c_str(), "w", stdout); }
long long n, m, a[1005][1005], mx[1005][1005][4];
void Baizho() {
cin>>n>>m;
for(int i = 1; i <= n; i ++) {
for(int j = 1; j <= m; j ++) cin>>a[i][j];
}
for(int i = 0; i <= n + 1; i ++) for(int j = 0; j <= m + 1; j ++) for(int k = 0; k < 4; k ++) mx[i][j][k] = -inf;
for(int i = n; i >= 1; i --) {
for(int j = m; j >= 1; j --) mx[i][j][0] = max({mx[i][j][0], mx[i - 1][j][0], mx[i][j + 1][0], -a[i][j]-i-j});
for(int j = 1; j <= m; j ++) mx[i][j][1] = max({mx[i][j][1], mx[i - 1][j][1], mx[i][j - 1][1], -a[i][j]-i+j});
}
for(int i = 1; i <= n; i ++) {
for(int j = m; j >= 1; j --) mx[i][j][2] = max({mx[i][j][2], mx[i + 1][j][2], mx[i][j + 1][2], -a[i][j]+i-j});
for(int j = 1; j <= m; j ++) mx[i][j][3] = max({mx[i][j][3], mx[i + 1][j][3], mx[i][j - 1][3], -a[i][j]+i+j});
}
long long ans = -inf;
for(int i = 1; i <= n; i ++) {
for(int j = 1; j <= m; j ++) {
ans = max({ans, a[i][j] + i + j + mx[i][j][0], a[i][j] + i - j + mx[i][j][1], a[i][j] - i + j + mx[i][j][2], a[i][i] - i - j + mx[i][j][3]});
}
}
cout<<ans;
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
// precalc();
int ttt = 1;
// cin>>ttt;
for(int i=1; i<=ttt; i++) { Baizho(); }
}
Compilation message
maxcomp.cpp: In function 'void Freopen(std::string)':
maxcomp.cpp:35:34: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
35 | void Freopen(string Key){ freopen((Key+".in").c_str(), "r", stdin); freopen((Key+".out").c_str(), "w", stdout); }
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
maxcomp.cpp:35:76: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
35 | void Freopen(string Key){ freopen((Key+".in").c_str(), "r", stdin); freopen((Key+".out").c_str(), "w", stdout); }
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
2396 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
2396 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
2396 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
2396 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |