Submission #1143543

#TimeUsernameProblemLanguageResultExecution timeMemory
1143543AgageldiMaxcomp (info1cup18_maxcomp)C++17
100 / 100
105 ms24168 KiB
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define N 600005
#define pb push_back
#define ff first
#define ss second
#define all(x) x.begin(),x.end()
#define sz(s) (int)s.size()
#define pii pair<int,int>

//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

ll T, n, a[2000][2000], t, m, answer = -1, vis[2000][2000], dp[2000][2000];
vector <pair<int,int>> path, ans;

int main () {
	ios::sync_with_stdio(0);cin.tie(0);
	cin >> n >> m;
	bool tr = 0;
	for(int i= 0;i<=n;i++) {
		dp[i][0] = dp[i][m + 1] = INT_MAX;
	}
	for(int i=0;i<=m;i++) {
		dp[0][i] = dp[n + 1][i] = INT_MAX;
	}
	for(int i = 1;i <= n;i++) {
		for(int j = 1; j <= m; j++) {
			cin >> a[i][j];
			dp[i][j] = a[i][j] + 1;
		}
	}
	for(int i=1;i<=n;i++){
		for(int j= 1;j<=m;j++) {
			dp[i][j] = min(dp[i][j],dp[i][j - 1] + 1);
		}
	}
	for(int i = 1; i <= n; i++){
		for(int j = m; j >= 1; j--) {
			dp[i][j] = min(dp[i][j],dp[i][j + 1] + 1);
		}
	}
	for(int i = 1; i <= m; i++){
		for(int j = 1; j <= n; j++) {
			dp[j][i] = min(dp[j][i],dp[j - 1][i] + 1);
		}
	}
	for(int i = 1; i <= m; i++) {
		for(int j = n; j >= 1; j--) {                                             
			dp[j][i] = min(dp[j][i],dp[j + 1][i] + 1);
		}
	}
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++) {
			answer = max(answer,a[i][j] - dp[i][j]);
		}
	}
	cout << answer << '\n';
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...