제출 #464856

#제출 시각아이디문제언어결과실행 시간메모리
464856okaragulMaxcomp (info1cup18_maxcomp)C++17
100 / 100
492 ms8176 KiB
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define endl "\n"
#define all(aa) aa.begin(), aa.end()

int main(){
	int n, m, ans=-1;
	cin>>n>>m;
	vector<vector<int>> mat(n, vector<int>(m)), dp(n, vector<int>(m));

	for(int i = 0; i < n; i++) for(int j = 0; j < m; j++) cin>>mat[i][j];

	dp=mat;
	for(int x = n-1; x >= 0; x--) for(int y = m-1; y >= 0; y--)
		ans=max(ans, mat[x][y]-(dp[x][y]=min({dp[x][min(m-1, y+1)]+1, dp[min(n-1, x+1)][y]+1, dp[x][y]+1})));

	dp=mat;
	for(int x = n-1; x >= 0; x--) for(int y = 0; y < m; y++)
		ans=max(ans, mat[x][y]-(dp[x][y]=min({dp[x][max(0, y-1)]+1, dp[min(n-1, x+1)][y]+1, dp[x][y]+1})));

	dp=mat;
	for(int x = 0; x < n; x++) for(int y = m-1; y >= 0; y--)
		ans=max(ans, mat[x][y]-(dp[x][y]=min({dp[x][min(m-1, y+1)]+1, dp[max(0, x-1)][y]+1, dp[x][y]+1})));

	dp=mat;
	for(int x = 0; x < n; x++) for(int y = 0; y < m; y++)
		ans=max(ans, mat[x][y]-(dp[x][y]=min({dp[x][max(0, y-1)]+1, dp[max(0, x-1)][y]+1, dp[x][y]+1})));

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