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>
#define ll long long
#define INF 10000000000
using namespace std;
int n, m;
ll ans = 0;
vector<vector<ll>> v;
void f(){
vector<vector<ll>> mi(n + 1, vector<ll>(m + 1, INF));
for (int i = 1; i <= n; i++){
for (int j = 1; j <= m; j++){
mi[i][j] = min(mi[i][j - 1] + 1, v[i][j]);
}
}
vector<vector<ll>> dp(n + 1, vector<ll>(m + 1, INF));
for (int i = 1; i <= n; i++){
for (int j = 1; j <= m; j++){
dp[i][j] = min(dp[i - 1][j] + 1, mi[i][j]);
ans = max(ans, abs(v[i][j] - dp[i][j]) - 1);
}
}
}
void swv(){
for(int i = 1; i <= n / 2; i++){
swap(v[i], v[n - i + 1]);
}
}
void swh(){
for (int i = 1; i <= n; i++){
for (int j = 1; j <= m / 2; j++){
swap(v[i][j], v[i][m - j + 1]);
}
}
}
int main(){
cin>>n>>m;
v.assign(n + 1, vector<ll>(m + 1, 0));
for (int i = 1; i <= n; i++){
for (int j = 1; j <= m; j++){
cin>>v[i][j];
}
}
f();
swh();
f();
swv();
f();
swh();
f();
cout<<ans;
}
# | 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... |