Submission #45195

# Submission time Handle Problem Language Result Execution time Memory
45195 2018-04-11T19:01:19 Z Bruteforceman Maxcomp (info1cup18_maxcomp) C++11
100 / 100
228 ms 80640 KB
#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

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 time Memory Grader output
1 Correct 13 ms 16120 KB Output is correct
2 Correct 13 ms 16176 KB Output is correct
3 Correct 12 ms 16340 KB Output is correct
4 Correct 12 ms 16340 KB Output is correct
5 Correct 13 ms 16448 KB Output is correct
6 Correct 16 ms 16448 KB Output is correct
7 Correct 13 ms 16448 KB Output is correct
8 Correct 12 ms 16448 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 16448 KB Output is correct
2 Correct 13 ms 16504 KB Output is correct
3 Correct 14 ms 16528 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 16120 KB Output is correct
2 Correct 13 ms 16176 KB Output is correct
3 Correct 12 ms 16340 KB Output is correct
4 Correct 12 ms 16340 KB Output is correct
5 Correct 13 ms 16448 KB Output is correct
6 Correct 16 ms 16448 KB Output is correct
7 Correct 13 ms 16448 KB Output is correct
8 Correct 12 ms 16448 KB Output is correct
9 Correct 13 ms 16788 KB Output is correct
10 Correct 14 ms 16828 KB Output is correct
11 Correct 14 ms 16868 KB Output is correct
12 Correct 17 ms 16892 KB Output is correct
13 Correct 15 ms 16892 KB Output is correct
14 Correct 15 ms 16940 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 16120 KB Output is correct
2 Correct 13 ms 16176 KB Output is correct
3 Correct 12 ms 16340 KB Output is correct
4 Correct 12 ms 16340 KB Output is correct
5 Correct 13 ms 16448 KB Output is correct
6 Correct 16 ms 16448 KB Output is correct
7 Correct 13 ms 16448 KB Output is correct
8 Correct 12 ms 16448 KB Output is correct
9 Correct 13 ms 16448 KB Output is correct
10 Correct 13 ms 16504 KB Output is correct
11 Correct 14 ms 16528 KB Output is correct
12 Correct 13 ms 16788 KB Output is correct
13 Correct 14 ms 16828 KB Output is correct
14 Correct 14 ms 16868 KB Output is correct
15 Correct 17 ms 16892 KB Output is correct
16 Correct 15 ms 16892 KB Output is correct
17 Correct 15 ms 16940 KB Output is correct
18 Correct 228 ms 29188 KB Output is correct
19 Correct 220 ms 37856 KB Output is correct
20 Correct 215 ms 46024 KB Output is correct
21 Correct 219 ms 54408 KB Output is correct
22 Correct 218 ms 63128 KB Output is correct
23 Correct 215 ms 71460 KB Output is correct
24 Correct 184 ms 80640 KB Output is correct