Submission #1318950

#TimeUsernameProblemLanguageResultExecution timeMemory
1318950muhammad-mutahirMaxcomp (info1cup18_maxcomp)C++20
0 / 100
0 ms332 KiB
#include <bits/stdc++.h>
using namespace std;

#define print(l) for(auto i:l) cout<<i<<" ";cout<<endl;
#define input(t,l,n) vector<t>l(n);for(int i = 0;i<n;i++)cin>>l[i];
#define int long long
#define pb push_back
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
#define all(l) l.begin(),l.end()
#define pii pair<int,int>
#define fi first
#define se second

const int M = 1e9+7;
const int inf = 1e18;


int bp(int x, int y, int p){
    int res = 1;
    x = x % p;
    while (y > 0) {
 
        if (y & 1)
            res = (res * x) % p;
        y = y >> 1;
        x = (x * x) % p;
    }
    return res;
}
 
int MI(int n, int p){
    return bp(n, p - 2, p);
}
int mul(int x,int y, int p){
    return x * 1ull * y % p;
}
int di(int x,int y, int p){
    return mul(x, MI(y, p), p);
}


int n , m , k , q;

void solve(int testcase_number){
    cin>>n>>m;
    // vector<vector<vector<int>>>dp(n+1,vecor<int>(m+1,vector<int>(3,0)));
    int dp[n+1][m+1][3] = {};
    for(int i =0;i<=n;i++){
    	dp[i][0][0] = 0;
    	dp[i][0][1] = inf;
    	dp[i][0][2] = -inf;
    	
    }
    for(int i =0;i<=m;i++){
    	dp[0][i][0] = 0;
    	dp[0][i][1] = inf;
    	dp[0][i][2] = -inf;
    	
    }    
    int mat[n+1][m+1];
    for(int i = 1;i<=n;i++){
    	for(int j = 1;j<=m;j++){
    		cin>>mat[i][j];
    	}
    }
    int ans = 0;
    for(int i = 1;i<=n;i++){
    	for(int j = 1;j<=m;j++){
    		
    		vector<int>p1(3,0);
    		
    		p1[0] = dp[i-1][j][0];
    		p1[1] = dp[i-1][j][1];
    		p1[2] = dp[i-1][j][2];
    		
			vector<int>p2(3,0);
			
    		p2[0] = dp[i][j-1][0];
    		p2[1] = dp[i][j-1][1];
    		p2[2] = dp[i][j-1][2];
    		
    		
    		p2[1] = min(p2[1],mat[i][j]);
    		p2[2] = max(p2[2],mat[i][j]);
    		
    		p1[1] = min(p1[1],mat[i][j]);
    		p1[2] = max(p1[2],mat[i][j]);
    		
    		// cout<<min(p1[]mat[i][j]<<endl; 
    		// print(p1);
    		// print(p2);
    		if(p2[2]-p2[1]-p2[0]-1 > p1[2]-p1[1]-p1[0]-1){
    			dp[i][j][0] = p2[0]+1;
    			dp[i][j][1] = p2[1];
    			dp[i][j][2] = p2[2];
    		}
    		else if(p2[2]-p2[1]-p2[0]-1 < p1[2]-p1[1]-p1[0]-1){
    			dp[i][j][0] = p1[0]+1;
    			dp[i][j][1] = p1[1];
    			dp[i][j][2] = p1[2];
    		}
    		else{
    			if(p2[0] <= p1[0]){
    				dp[i][j][0] = p2[0]+1;
	    			dp[i][j][1] = p2[1];
	    			dp[i][j][2] = p2[2];
    			}
    			else{
    				dp[i][j][0] = p1[0]+1;
	    			dp[i][j][1] = p1[1];
	    			dp[i][j][2] = p1[2];
    			}
    		}
    		ans = max(ans,dp[i][j][2]-dp[i][j][1]-dp[i][j][0]);
    	}
    }
    cout<<ans<<endl;



}


signed main(){
    ios::sync_with_stdio(0);//DO NOT USE IN INTERACTIVE
    cin.tie(0), cout.tie(0);
    cout << fixed<<setprecision(9);

    int t = 1;
    // cin>>t;
    for(int i = 1;i<=t;i++){
        solve(i);
    }

}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...