Submission #1051238

# Submission time Handle Problem Language Result Execution time Memory
1051238 2024-08-10T01:34:31 Z pcc Maxcomp (info1cup18_maxcomp) C++17
100 / 100
64 ms 17496 KB
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define pll pair<ll,ll>
#define pii pair<int,int>
#define fs first
#define sc second
#define tlll tuple<ll,ll,ll>


const int inf = 1e9;
const int mxn = 1010;
int arr[mxn][mxn];
int dp[mxn][mxn];
int N,M;


int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>N>>M;
	for(auto &i:arr)for(auto &j:i)j = -inf*2;
	for(auto &i:dp)for(auto &j:i)j = -inf*2;
	for(int i = 1;i<=N;i++){
		for(int j = 1;j<=M;j++)cin>>arr[i][j];
	}
	int ans = -inf*2;
	for(int i = 1;i<=N;i++){
		for(int j = 1;j<=M;j++){
			dp[i][j] = max(dp[i-1][j],dp[i][j-1]);
			dp[i][j] = max(dp[i][j],-arr[i][j]+i+j);
			ans = max(ans,dp[i][j]-i-j+arr[i][j]-1);
		}
	}
	for(int i = N;i>=1;i--){
		for(int j = 1;j<=M;j++){
			dp[i][j] = max(dp[i+1][j],dp[i][j-1]);
			dp[i][j] = max(dp[i][j],-arr[i][j]-i+j);
			ans = max(ans,dp[i][j]+i-j+arr[i][j]-1);
		}
	}
	for(int i = 1;i<=N;i++){
		for(int j = M;j>=1;j--){
			dp[i][j] = max(dp[i-1][j],dp[i][j+1]);
			dp[i][j] = max(dp[i][j],-arr[i][j]+i-j);
			ans = max(ans,dp[i][j]-i+j+arr[i][j]-1);
		}
	}
	for(int i = N;i>=1;i--){
		for(int j = M;j>=1;j--){
			dp[i][j] = max(dp[i+1][j],dp[i][j+1]);
			dp[i][j] = max(dp[i][j],-arr[i][j]-i-j);
			ans = max(ans,dp[i][j]+i+j+arr[i][j]-1);
		}
	}
	cout<<ans<<'\n';
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 8292 KB Output is correct
2 Correct 3 ms 8316 KB Output is correct
3 Correct 3 ms 8300 KB Output is correct
4 Correct 3 ms 8284 KB Output is correct
5 Correct 3 ms 8284 KB Output is correct
6 Correct 3 ms 8284 KB Output is correct
7 Correct 3 ms 8284 KB Output is correct
8 Correct 3 ms 8284 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 8284 KB Output is correct
2 Correct 3 ms 8284 KB Output is correct
3 Correct 3 ms 8284 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 8292 KB Output is correct
2 Correct 3 ms 8316 KB Output is correct
3 Correct 3 ms 8300 KB Output is correct
4 Correct 3 ms 8284 KB Output is correct
5 Correct 3 ms 8284 KB Output is correct
6 Correct 3 ms 8284 KB Output is correct
7 Correct 3 ms 8284 KB Output is correct
8 Correct 3 ms 8284 KB Output is correct
9 Correct 3 ms 8464 KB Output is correct
10 Correct 3 ms 8536 KB Output is correct
11 Correct 3 ms 8408 KB Output is correct
12 Correct 3 ms 8468 KB Output is correct
13 Correct 3 ms 8284 KB Output is correct
14 Correct 3 ms 8284 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 8292 KB Output is correct
2 Correct 3 ms 8316 KB Output is correct
3 Correct 3 ms 8300 KB Output is correct
4 Correct 3 ms 8284 KB Output is correct
5 Correct 3 ms 8284 KB Output is correct
6 Correct 3 ms 8284 KB Output is correct
7 Correct 3 ms 8284 KB Output is correct
8 Correct 3 ms 8284 KB Output is correct
9 Correct 3 ms 8284 KB Output is correct
10 Correct 3 ms 8284 KB Output is correct
11 Correct 3 ms 8284 KB Output is correct
12 Correct 3 ms 8464 KB Output is correct
13 Correct 3 ms 8536 KB Output is correct
14 Correct 3 ms 8408 KB Output is correct
15 Correct 3 ms 8468 KB Output is correct
16 Correct 3 ms 8284 KB Output is correct
17 Correct 3 ms 8284 KB Output is correct
18 Correct 61 ms 16872 KB Output is correct
19 Correct 61 ms 16720 KB Output is correct
20 Correct 57 ms 16468 KB Output is correct
21 Correct 60 ms 16728 KB Output is correct
22 Correct 61 ms 16748 KB Output is correct
23 Correct 60 ms 16728 KB Output is correct
24 Correct 64 ms 17496 KB Output is correct