Submission #45195

#TimeUsernameProblemLanguageResultExecution timeMemory
45195BruteforcemanMaxcomp (info1cup18_maxcomp)C++11
100 / 100
228 ms80640 KiB
#include "bits/stdc++.h"
using namespace std;
int n, m;
int a[1005][1005];
int tl[1005][1005];
int tr[1005][1005];
int dl[1005][1005];
int dr[1005][1005];

int solve(int x, int y) {
	int ans = INT_MIN;
	/* for(int i = 1; i <= n; i++) {
		for(int j = 1; j <= m; j++) {
			ans = max(ans, a[i][j] - a[x][y] - abs(x - i) - abs(y - j));
		}
	}*/
	ans = max(ans, tl[x][y] - a[x][y] - x - y);
	ans = max(ans, tr[x][y] - a[x][y] - x + y);
	ans = max(ans, dl[x][y] - a[x][y] + x - y);
	ans = max(ans, dr[x][y] - a[x][y] + x + y);
	return ans - 1;
}

int main(int argc, char const *argv[])
{
	scanf("%d %d", &n, &m);
	for(int i = 1; i <= n; i++) {
		for(int j = 1; j <= m; j++) {
			scanf("%d", &a[i][j]);
		}
	}
	memset(tl, -63, sizeof tl);
	memset(tr, -63, sizeof tr);
	memset(dl, -63, sizeof dl);
	memset(dr, -63, sizeof dr);

	for(int i = 1; i <= n; i++) {
		for(int j = 1; j <= m; j++) {
			tl[i][j] = max(tl[i - 1][j], tl[i][j - 1]);
			tl[i][j] = max(tl[i][j], a[i][j] + i + j);
		}
	}
	for(int i = 1; i <= n; i++) {
		for(int j = m; j >= 1; j--) {
			tr[i][j] = max(tr[i - 1][j], tr[i][j + 1]);
			tr[i][j] = max(tr[i][j], a[i][j] + i - j);
		}
	}
	for(int i = n; i >= 1; i--) {
		for(int j = 1; j <= m; j++) {
			dl[i][j] = max(dl[i + 1][j], dl[i][j - 1]);
			dl[i][j] = max(dl[i][j], a[i][j] - i + j);
		}
	}
	for(int i = n; i >= 1; i--) {
		for(int j = m; j >= 1; j--) {
			dr[i][j] = max(dr[i + 1][j], dr[i][j + 1]);
			dr[i][j] = max(dr[i][j], a[i][j] - i - j);
		}
	}

	int ans = INT_MIN;
	for(int i = 1; i <= n; i++) {
		for(int j = 1; j <= m; j++) {
			ans = max(ans, solve(i, j));
		}
	}
	printf("%d\n", ans);
	return 0;
}

Compilation message (stderr)

maxcomp.cpp: In function 'int main(int, const char**)':
maxcomp.cpp:26:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d", &n, &m);
  ~~~~~^~~~~~~~~~~~~~~~~
maxcomp.cpp:29:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    scanf("%d", &a[i][j]);
    ~~~~~^~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...