Submission #1174700

#TimeUsernameProblemLanguageResultExecution timeMemory
1174700browntoadMaxcomp (info1cup18_maxcomp)C++20
100 / 100
63 ms16200 KiB
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast", "unroll-loops")
using namespace std;
#define ll long long
#define int ll
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define REP1(i, n) FOR(i, 1, n+1)
#define RREP(i, n) for (int i = (n)-1; i >= 0; i--)
#define RREP1(i, n) for (int i = (n); i >= 1; i--)
#define pii pair<int, int>
#define f first
#define s second
#define pb push_back
#define endl '\n'
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) (int)((x).size())


#ifdef TOAD
#define IOS()
#else
#define IOS() ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#endif



const ll maxn = 1e3+5;
const ll mod = 1e9+7;
const ll inf = 1ll<<60;

int n, m;

int arr[maxn][maxn];

int pfmx[maxn][maxn];
signed main(){
    IOS();
    cin>>n>>m;
    REP1(i, n){
        REP1(j, m){
            cin>>arr[i][j];
        }
    }

    REP(i, maxn){
        REP(j, maxn){
            pfmx[i][j] = -inf;
        }
    }
    int ans = -inf;
    REP1(i, n){
        REP1(j, m){
            pfmx[i][j] = max({-arr[i][j] + i + j, pfmx[i-1][j], pfmx[i][j-1]});
            ans = max(ans, arr[i][j] + pfmx[i][j] - i - j - 1);
        }
    }

    REP(i, maxn){
        REP(j, maxn){
            pfmx[i][j] = -inf;
        }
    }
    RREP1(i, n){
        REP1(j, m){
            pfmx[i][j] = max({-arr[i][j] - i + j, pfmx[i+1][j], pfmx[i][j-1]});
            ans = max(ans, arr[i][j] + pfmx[i][j] + i - j - 1);
        }
    }

    REP(i, maxn){
        REP(j, maxn){
            pfmx[i][j] = -inf;
        }
    }
    REP1(i, n){
        RREP1(j, m){
            pfmx[i][j] = max({-arr[i][j] + i - j, pfmx[i-1][j], pfmx[i][j+1]});
            ans = max(ans, arr[i][j] + pfmx[i][j] - i + j - 1);
        }
    }

    REP(i, maxn){
        REP(j, maxn){
            pfmx[i][j] = -inf;
        }
    }
    RREP1(i, n){
        RREP1(j, m){
            pfmx[i][j] = max({-arr[i][j] - i - j, pfmx[i+1][j], pfmx[i][j+1]});
            ans = max(ans, arr[i][j] + pfmx[i][j] + i + j - 1);
        }
    }

    cout<<ans<<endl;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...