Submission #685275

#TimeUsernameProblemLanguageResultExecution timeMemory
685275alexdumitruMaxcomp (info1cup18_maxcomp)C++14
100 / 100
125 ms28424 KiB
#include <fstream> #include <iostream> using namespace std; int myMax(int a, int b) { return (a > b ? a : b); } int myMax(int a, int b, int c) { return myMax(myMax(a, b), c); } const int NMAX = 1000; const int INF = 2e9; int n, m; int a[NMAX + 1][NMAX + 1]; int dp[4][NMAX + 1][NMAX + 1]; int ans = -1; void solve() { cin >> n >> m; for(int i = 1; i <= n; i++) for(int j = 1; j <= m; j++) cin >> a[i][j]; for(int k = 0; k <= 3; k++) { for(int i = 0; i <= n + 1; i++) dp[k][i][0] = dp[k][i][m + 1] = -INF; for(int j = 1; j <= m; j++) dp[k][0][j] = dp[k][n + 1][j] = -INF; } for(int i = 1; i <= n; i++) for(int j = 1; j <= m; j++) dp[0][i][j] = myMax(dp[0][i][j - 1], dp[0][i - 1][j], -a[i][j]) - 1; for(int i = 1; i <= n; i++) for(int j = m; j >= 1; j--) dp[1][i][j] = myMax(dp[1][i][j + 1], dp[1][i - 1][j], -a[i][j]) - 1; for(int i = n; i >= 1; i--) for(int j = 1; j <= m; j++) dp[2][i][j] = myMax(dp[2][i][j - 1], dp[2][i + 1][j], -a[i][j]) - 1; for(int i = n; i >= 1; i--) for(int j = m; j >= 1; j--) dp[3][i][j] = myMax(dp[3][i][j + 1], dp[3][i + 1][j], -a[i][j]) - 1; for(int i = 1; i <= n; i++) for(int j = 1; j <= m; j++) if(a[i][j] + myMax(myMax(dp[0][i][j], dp[1][i][j], dp[2][i][j]), dp[3][i][j]) > ans) ans = a[i][j] + myMax(myMax(dp[0][i][j], dp[1][i][j], dp[2][i][j]), dp[3][i][j]); cout << ans << '\n'; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); solve(); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...