Submission #1318934

#TimeUsernameProblemLanguageResultExecution timeMemory
1318934Sir_Ahmed_ImranMaxcomp (info1cup18_maxcomp)C++17
15 / 100
1 ms332 KiB
            //    01001100 01001111 01010100 01000001    \\
            //                                           \\
            //                ╦  ╔═╗╔╦╗╔═╗               \\
            //                ║  ║ ║ ║ ╠═╣               \\
            //                ╩═╝╚═╝ ╩ ╩ ╩               \\
            //                                           \\
            //    01001100 01001111 01010100 01000001    \\
 
#include <bits/stdc++.h>
using namespace std;
#define nl '\n'
#define ff first
#define ss second
#define ll long long
#define ld long double
#define terminator main
#define pll pair<ll,ll>
#define add insert
#define append push_back
#define pii pair<int,int>
#define all(x) (x).begin(),(x).end()
#define L0TA ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

const int N = 1e3 + 3;

int a[N][N];
int x[N][N][4];

void solve(){
    int n, m, ans;
    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 + 2; i++)
        for(int j = 0; j < m + 2; j++)
            for(int k = 0; k < 4; k++)
                x[i][j][k] = -1e9;
    for(int i = 1; i <= n; i++)
        for(int j = 1; j <= m; j++)
            x[i][j][0] = max(max(x[i - 1][j][0], x[i][j - 1][0]), - a[i][j] + i + j);
    for(int i = 1; i <= n; i++)
        for(int j = m; j > 0; j--)
            x[i][j][1] = max(max(x[i - 1][j][1], x[i][j + 1][1]), - a[i][j] + i - j);
    for(int i = n; i > 0; i--)
        for(int j = 1; j <= m; j++)
            x[i][j][2] = max(max(x[i + 1][j][2], x[i][j - 1][2]), - a[i][j] - i + j);
    for(int i = n; i > 0; i--)
        for(int j = m; j > 0; j--)
            x[i][j][3] = max(max(x[i + 1][j][3], x[i][j + 1][3]), - a[i][j] - i - j);
    ans = -1e9;
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= m; j++){
            ans = max(ans, a[i][j] - i - j + x[i][j][0] - 1);
            ans = max(ans, a[i][j] - i + j + x[i][j][1] - 1);
            ans = max(ans, a[i][j] + i - j + x[i][j][2] - 1);
            ans = max(ans, a[i][j] + i + j + x[i][j][3] - 1);
        }
    }
    cout << ans;
}

int terminator(){
    L0TA;
    int T = 1;
    //cin >> T;
    while(T--)
        solve();
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...