Submission #1107946

#TimeUsernameProblemLanguageResultExecution timeMemory
1107946HasanV11010238Maxcomp (info1cup18_maxcomp)C++17
100 / 100
298 ms32656 KiB
#include <bits/stdc++.h>
#define ll long long
#define INF 10000000000
using namespace std;
int n, m;
ll ans = -INF;
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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...