Submission #1141563

#TimeUsernameProblemLanguageResultExecution timeMemory
1141563KasymKMaxcomp (info1cup18_maxcomp)C++20
0 / 100
10 ms24132 KiB
#include "bits/stdc++.h"
using namespace std;
#define ff first
#define ss second
#define all(v) v.begin(), v.end()
#define ll long long
#define pb push_back
#define pii pair<int, int>
#define pli pair<ll, int>
#define pll pair<ll, ll>
#define tr(i, c) for(auto i = c.begin(); i != c.end(); ++i)
#define wr puts("----------------")
template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
const int N = 1e3+5;
const ll INF = 1e18;
int v[N][N];

struct node {
    int mx, mn, sz;
    ll val;
    node(){
        mx=INT_MIN, mn=INT_MAX, sz=0;
        val=-INF;
    };
} dp[N][N];

int main(){
    int n, m;
    scanf("%d%d", &n, &m);
    auto is=[&](int a, int b) -> bool {
        return (a>=1 and a<=n and b>=1 and b<=m);
    };
    for(int i = 1; i <= n; ++i)
        for(int j = 1; j <= m; ++j)
            scanf("%d", &v[i][j]);
    for(int i = 1; i <= n; ++i)
        for(int j = 1; j <= m; ++j){
            // 1-> up
            if(is(i-1, j)){
                if(umax(dp[i][j].val, (max(dp[i-1][j].mx, v[i][j])-min(dp[i-1][j].mn, v[i][j])-dp[i-1][j].sz-1)*1ll))
                    umax(dp[i][j].mx, max(dp[i-1][j].mx, v[i][j])), umin(dp[i][j].mn, min(dp[i-1][j].mn, v[i][j])), dp[i][j].sz=dp[i-1][j].sz+1;
            }
            // 2-> left
            if(is(i, j-1)){
                if(umax(dp[i][j].val, (max(dp[i][j-1].mx, v[i][j])-min(dp[i][j-1].mn, v[i][j])-dp[i][j-1].sz-1)*1ll))
                    umax(dp[i][j].mx, max(dp[i][j-1].mx, v[i][j])), umin(dp[i][j].mn, min(dp[i][j-1].mn, v[i][j])), dp[i][j].sz=dp[i][j-1].sz+1;
            }
            // 3-> start new
            if(umax(dp[i][j].val, -1*1ll))
                dp[i][j].mx=v[i][j], dp[i][j].mn=v[i][j], dp[i][j].sz=1;
        }
    ll answer=-INF;
    for(int i = 1; i <= n; ++i)
        for(int j = 1; j <= m; ++j)
            umax(answer, dp[i][j].val);
    printf("%lld\n", answer);
    return 0;
}

Compilation message (stderr)

maxcomp.cpp: In function 'int main()':
maxcomp.cpp:30:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   30 |     scanf("%d%d", &n, &m);
      |     ~~~~~^~~~~~~~~~~~~~~~
maxcomp.cpp:36:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   36 |             scanf("%d", &v[i][j]);
      |             ~~~~~^~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...