This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#pragma GCC optimize("-O3")
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define ll long long
#define ld long double
#define vl vector<ll>
#define vi vector<int>
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define pb push_back
#define p_b pop_back
#define pii pair<int, int>
#define pll pair<ll, ll>
#define f first
#define s second
using namespace std;
using namespace __gnu_pbds;
typedef tree<ll, null_type, less_equal<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
//random_device rd;
//mt19937 gen(rd());
//uniform_int_distribution<> d(0, 1e9);
void solve()
{
ll n, m, i, j;
cin >> n >> m;
ll a[n+5][m+5];
for(i = 1; i <= n; i++)
{
for(j = 1; j <= m; j++)
cin >> a[i][j];
}
for(i = 1; i <= n; i++)
reverse(a[i]+1, a[i]+m+1);
ll minn[n+5][m+5], maxx[n+5][m+5];
for(i = 0; i <= n; i++)
{
for(j = 0; j <= m; j++)
{
minn[i][j] = LLONG_MAX;
maxx[i][j] = LLONG_MIN;
}
}
ll res = -1;
for(i = 1; i <= n; i++)
{
for(j = 1; j <= m; j++)
{
minn[i][j] = min(minn[i-1][j], minn[i][j-1]);
maxx[i][j] = max(maxx[i-1][j], maxx[i][j-1]);
minn[i][j] = min(minn[i][j], a[i][j] - i - j);
maxx[i][j] = max(maxx[i][j], a[i][j] + i + j);
res = max(res, maxx[i][j] - a[i][j] - i - j);
res = max(res, a[i][j] - i - j - minn[i][j]);
}
}
cout << res << "\n";
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
ll tests = 1;
//cin >> tests;
while(tests--)
{
solve();
}
}
# | 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... |