Submission #67037

# Submission time Handle Problem Language Result Execution time Memory
67037 2018-08-13T08:53:31 Z cdemirer Maxcomp (info1cup18_maxcomp) C++17
100 / 100
235 ms 39644 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vii> vvii;
typedef vector<vi> vvi;
typedef pair<double, double> dodo;
#define pb(x) push_back(x)
#define mp(x, y) make_pair(x, y)

int N, M;
int input[3000][3000];
int mat[3000][3000];
int solve() {
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < M; j++) {
			mat[i][j] = input[i][j] - (i+j);
		}
	}
	for (int i = N-2; i >= 0; i--) mat[i][M-1] = max(mat[i][M-1], mat[i+1][M-1]);
	for (int j = M-2; j >= 0; j--) mat[N-1][j] = max(mat[N-1][j], mat[N-1][j+1]);
	for (int i = N-2; i >= 0; i--) {
		for (int j = M-2; j >= 0; j--) {
			mat[i][j] = max( mat[i][j], max(mat[i+1][j], mat[i][j+1]) );
		}
	}
	int ret = -1;
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < M; j++) {
			ret = max(ret, mat[i][j] - input[i][j] + (i+j) - 1);
		}
	}
	return ret;
}

int main(int argc, char **argv) {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> N >> M;
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < M; j++) {
			cin >> input[i][j];
		}
	}
	
	int ans = solve();
	for (int i = 0; i < N/2; i++) {
		for (int j = 0; j < M; j++) {
			swap(input[i][j], input[N-1-i][j]);
		}
	}
	ans = max(ans, solve());
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < M; j++) {
			input[i][j] = -input[i][j];
		}
	}
	ans = max(ans, solve());
	for (int i = 0; i < N/2; i++) {
		for (int j = 0; j < M; j++) {
			swap(input[i][j], input[N-1-i][j]);
		}
	}
	ans = max(ans, solve());
	cout << ans << endl;
	
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 528 KB Output is correct
4 Correct 2 ms 528 KB Output is correct
5 Correct 3 ms 560 KB Output is correct
6 Correct 2 ms 564 KB Output is correct
7 Correct 2 ms 568 KB Output is correct
8 Correct 3 ms 648 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 648 KB Output is correct
2 Correct 2 ms 648 KB Output is correct
3 Correct 3 ms 660 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 528 KB Output is correct
4 Correct 2 ms 528 KB Output is correct
5 Correct 3 ms 560 KB Output is correct
6 Correct 2 ms 564 KB Output is correct
7 Correct 2 ms 568 KB Output is correct
8 Correct 3 ms 648 KB Output is correct
9 Correct 3 ms 1052 KB Output is correct
10 Correct 3 ms 1072 KB Output is correct
11 Correct 3 ms 1148 KB Output is correct
12 Correct 4 ms 1148 KB Output is correct
13 Correct 4 ms 1148 KB Output is correct
14 Correct 3 ms 1160 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 528 KB Output is correct
4 Correct 2 ms 528 KB Output is correct
5 Correct 3 ms 560 KB Output is correct
6 Correct 2 ms 564 KB Output is correct
7 Correct 2 ms 568 KB Output is correct
8 Correct 3 ms 648 KB Output is correct
9 Correct 2 ms 648 KB Output is correct
10 Correct 2 ms 648 KB Output is correct
11 Correct 3 ms 660 KB Output is correct
12 Correct 3 ms 1052 KB Output is correct
13 Correct 3 ms 1072 KB Output is correct
14 Correct 3 ms 1148 KB Output is correct
15 Correct 4 ms 1148 KB Output is correct
16 Correct 4 ms 1148 KB Output is correct
17 Correct 3 ms 1160 KB Output is correct
18 Correct 183 ms 25004 KB Output is correct
19 Correct 168 ms 33616 KB Output is correct
20 Correct 187 ms 39216 KB Output is correct
21 Correct 184 ms 39516 KB Output is correct
22 Correct 192 ms 39644 KB Output is correct
23 Correct 235 ms 39644 KB Output is correct
24 Correct 198 ms 39644 KB Output is correct