Submission #44908

#TimeUsernameProblemLanguageResultExecution timeMemory
44908ulnaMaxcomp (info1cup18_maxcomp)C++11
100 / 100
194 ms4816 KiB
#include <bits/stdc++.h>
using namespace std;

// why am I so weak

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

int solve() {
	int res = -INT_MAX;

	for (int j = 0; j < m; j++) {
		dp[j] = -(int)1e9;
	}

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			dp[j]--;
		}

		{
			int roll = -(int)1e9;

			for (int j = 0; j < m; j++) {
				roll--;
				roll = max(roll, -a[i][j] - 1);

				dp[j] = max(dp[j], roll);
			}
		}

		{
			int roll = -(int)1e9;

			for (int j = m - 1; j >= 0; j--) {
				roll--;
				roll = max(roll, -a[i][j] - 1);

				dp[j] = max(dp[j], roll);
			}
		}

		for (int j = 0; j < m; j++) {
			res = max(res, a[i][j] + dp[j]);
		}
	}

	return res;
}
int main() {
	scanf("%d %d", &n, &m);

	for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) {
		scanf("%d", &a[i][j]);
	}

	int res = -1;

	res = max(res, solve());

	for (int i = 0; i < n / 2; i++) {
		swap(a[i], a[n - i - 1]);
	}

	res = max(res, solve());

	cout << res << endl;

	return 0;
}

Compilation message (stderr)

maxcomp.cpp: In function 'int main()':
maxcomp.cpp:52: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:55:8: 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...