답안 #916926

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
916926 2024-01-26T19:18:39 Z NintsiChkhaidze Maxcomp (info1cup18_maxcomp) C++17
100 / 100
115 ms 16180 KB
#include <bits/stdc++.h>
#define ll long long
#define s second
#define f first
#define pb push_back
#define pii pair <int,int>
#define left (h<<1),l,(l + r)/2
#define right ((h<<1)|1),(l + r)/2 + 1,r
#define int ll 
using namespace std;

const int N = 1e3 + 3,inf = 1e18;

int a[N][N],n,m,dp[N][N];

void go(){
	for (int i = 0; i <= n + 1; i++)
		for (int j = 0; j <= m + 1; j++){
			if (!i || i > n || !j || j > m) a[i][j] = inf;
			dp[i][j] = inf; 
		}	
}

signed main() {
	ios_base::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL);

	int ans=-1;
	cin>>n>>m;
	for (int i = 1; i <= n; i++){
		for (int j = 1; j <= m; j++){
			cin >> a[i][j];
		}
	}

	go();
	for (int i = 1; i <= n; i++){
		for (int j = m; j >= 1; j--){
			dp[i][j] = min({dp[i][j],a[i - 1][j] + 2,a[i][j + 1] + 2});
			dp[i][j] = min({dp[i][j],dp[i - 1][j] + 1,dp[i][j + 1] + 1});
			ans=max(ans,a[i][j] - dp[i][j]);
		}
	}

	go();
	for (int i = 1; i <= n; i++){
		for (int j = 1; j <= m; j++){
			dp[i][j] = min({dp[i][j],a[i - 1][j] + 2,a[i][j - 1] + 2});
			dp[i][j] = min({dp[i][j],dp[i - 1][j] + 1,dp[i][j - 1] + 1});
			ans=max(ans,a[i][j] - dp[i][j]);
		}
	}

	go();
	for (int i = n; i >= 1; i--){
		for (int j = 1; j <= m; j++){
			dp[i][j] = min({dp[i][j],a[i + 1][j] + 2,a[i][j - 1] + 2});
			dp[i][j] = min({dp[i][j],dp[i + 1][j] + 1,dp[i][j - 1] + 1});
			ans=max(ans,a[i][j] - dp[i][j]);
		}
	}

	go();
	for (int i = n; i >= 1; i--){
		for (int j = m; j >= 1; j--){
			dp[i][j] = min({dp[i][j],a[i + 1][j] + 2,a[i][j + 1] + 2});
			dp[i][j] = min({dp[i][j],dp[i + 1][j] + 1,dp[i][j + 1] + 1});
			ans=max(ans,a[i][j] - dp[i][j]);
		}
	}

	cout<<ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 2 ms 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 2 ms 4444 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 2 ms 4444 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 2 ms 4444 KB Output is correct
18 Correct 96 ms 15956 KB Output is correct
19 Correct 98 ms 16180 KB Output is correct
20 Correct 113 ms 15952 KB Output is correct
21 Correct 115 ms 15956 KB Output is correct
22 Correct 91 ms 16076 KB Output is correct
23 Correct 90 ms 15952 KB Output is correct
24 Correct 88 ms 15700 KB Output is correct